Im new to programming in assembly and I am trying to convert a function that is written in c in to assembly code Y86. This is what I have but I know that it is wrong. I started off with writing the assembly code for one parameter but then when I try to have 2 parameters I get confused on what to do. I could use some help. Lets say x = 5 and y = 1.
int rec_mult (int x, int y){
if(y==1){
return x;
}
else{
return x + rec_mult(x, y-1);
}
}
esi = x and ecx = y
rec_mult:
pushl %ebp
rrmovl %esp,%ebp
mrmovl 8(%ebp),%ecx
mrmovl 12(%ebp),%esi
irmovl $1,%edx
rrmovl %ecx,%eax
subl %ecx,%edx
je rec_multend
rrmovl %ecx,%edi
irmovl $1,%edx
subl %edx,%edi
pushl %ecx
pushl %edi
call rec_mult
popl %edi
popl %ecx
addl %esi,%eax
rec_multend:
popl %ebp
ret