I'm new to Y86 and am trying to write a recursive multiplication function, but the wrong parameter keeps being passed.
The code that calls the multiplication function:
square:
irmovl $4, %ebx
pushl %ebx # push argument
rrmovl %ebx, %edx #set it equal to the number being squared
pushl %edx
call rmult
popl %edx
popl %ebx
ret
And the actual multiplication code:
rmult:
pushl %ebp
rrmovl %esp,%ebp
mrmovl 8(%ebp),%ebx #ebx = y
irmovl $0,%eax
rrmovl %ebx,%edi
subl %ebx,%eax
je rec_multend
rrmovl %ebx,%esi
irmovl $1,%eax
subl %eax,%esi
pushl %ebx
pushl %esi
call rmult
mrmovl 12(%ebp),%edx #edx = x
popl %esi
popl %ebx
addl %edx,%edi
rec_multend:
popl %ebp
ret
I pass in 4 for both x and y as the function calling them is squaring a number and so they should be the same, but at the line:
mrmovl 12(%ebp),%edx #edx = x
It passes in 2 instead of the 4 that I initially put in there, which ends up returning a value of 13 rather than 16.
From my limited understanding of Y86, "mrmovl 8(%ebp),%ebx" should return the second parameter which I set equal to Y and "mrmovl 12(%ebp),%edx" should return the first parameter equal to X, with both of them being passed in as 4.