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

``````program prog1;

#include( "stdlib.hhf" );

static

n : int8 := 0;

d : int8 := 0;

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

iResult : int8;

temp : int16;

iRegisterValue : dword;

begin divideRec;

mov( EBX, iRegisterValue );

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(iRegisterValue);

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;
``````

``````

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);

}

``````