Hi! I've done a program that interacts an asm subprogram with a c program. The objective is to make the integer division of two numbers and give the result and the remainder. But i'm having problems to obtain the remainder. Anyone could help me with the possible error detection? The code is presented next:
#include <stdio.h>

int division(int, int, int *);

int main(){
int dividend, divider, remainder;
int quocient = 0;

printf("Dividend = ");
scanf("%d", &dividend);


printf("\n\nDivider = ");
scanf("%d", &divider);


quocient = division(dividend, divider, &remainder);

printf("\n\nQuocient = %d", quocient);


printf("\n\nRemainder = %d\n\n", remainder);


return 0;

}
segment .data
;
; initialized data is put in the data segment here
;


segment .bss
;
; uninitialized data is put in the bss segment
;

segment .text
        global  _division
       
_division: 

        push ebp
        mov ebp, esp
       
       
        cdq
       
        mov  ecx, dword
               
        mov  eax, dword       
           
        idiv ecx                     
       
               
        mov  , edx  ;!!! -> Here is the remainder, but how is passed to the c program?
       
        mov esp, ebp
        pop ebp 
        ret


Thanks!
Posted on 2006-11-29 17:43:35 by ammfj
the relevant part should be
idiv ecx                      
mov ecx, ; ecx = pointer
mov , edx ; store edx at 'ecx'
mov esp, ebp

or something like this

and the function's declaration should be
int __stdcall division(int, int, int *);
Posted on 2006-11-29 18:33:29 by ti_mo_n
Thanks ti_mo_n :D I already correct my code and it works.
Posted on 2006-11-29 18:51:24 by ammfj