HLA递归除法和相应的C代码

这是我的错误HLA程序: 它总是不打印任何东西... 它应该提示用户输入两个整数并输出整数商:

program prog1;

#include( "stdlib.hhf" );

static

n : int8 := 0;

d : int8 := 0;

procedure divideRec( numerator: int8; denominator : int8 ); @nodisplay; @noframe;
static

iReturnAddress : dword;

iResult : int8;

temp : int16;

iRegisterValue : dword;



begin divideRec;


mov( EBX, iRegisterValue );


pop( iReturnAddress );

pop( temp);

//junk 

//this is denominator
pop( temp); 
mov(temp,BX); 
mov(BL, denominator); 

//this is numerator

pop(temp); 
mov(temp,BX); 
mov(BL, numerator); 

push(iReturnAddress); 
push(iRegisterValue); 



//subtask 


mov(0,DH); 

mov(numerator,AL); 
cmp(AL,denominator); 
jge recursiveCall; 

recursiveCall: 
mov(numerator,BL); 
sub(denominator,BL); 
mov(BL, numerator);
push(BX); 
push(temp); 
call divideRec; 
inc(DH); 



jmp ExitSequence; 

ExitSequence:
pop(EBX); 
ret(); 
end divideRec; 



begin prog1; 

stdout.put("Provide a numerator: "); 
stdin.get(n); 
stdout.put("Provide a denominator: "); 
stdin.get(d); 


//16-bits
//n
mov(0,BX); 
mov(n,BL);
push(BX); 
//d
mov(0,BX); 
mov(d,BL); 
push(BX); 


mov(0,BX); 
push(BX); 
call divideRec; 
stdout.put("divide( ",n,", ",d, ") = ");
stdout.puti8(DH); 


end prog1;

这是对应的C代码:



int main(){

int n, d;
printf("gimme a numerator:"); 
scanf("%d",&n); 
 printf("gimme a denominator:"); 
scanf("%d",&d); 
int result = divideRec(n,d); 
printf("the quotient is %d", result); 
return(0); 
}

int divideRec(int numerator, int denominator){

int result = 0; 
if(numerator>=denominator){
result = 1+(divideRec(numerator-denominator, denominator)); 

}
return(result); 

}




该程序始终以零或无输出结束。我相信堆栈对齐,推入和弹出都有问题,我无法弄清楚。请提供一些帮助。

评论