I'm trying to write a program that creates a sum of all inclusive integers between x and y, with the sum, y, and x being global variables. I'm running into problems when I try to assign the x and y to local registers (my simulator assigns the values of 0x60 and 0x64 to the local registers as opposed to 1 and 4) as well as taking the summed value and transferring that to the global variable of sum. Usually I try to find helpful guides online, but Y86 is such a sparingly used language that there is next to nothing.
My code:
.pos 0
init: irmovl Stack, %esp //Set up stack pointer
irmovl Stack, %ebp //Set up base pointer
call main //call main program
halt //Terminate program
main: pushl %ebp //setup
rrmovl %esp, %ebp
pushl %ebx //declaring x local register
irmovl x, %ebx
pushl %esi //declaring y local register
irmovl y, %esi
pushl %eax //declaring sum
irmovl sum, %eax
pushl %edi //constant of 1
irmovl $1, %edi
L2:
subl %ebx, %esi // %esi = y-x
jl L3 // ends function if x > y
irmovl y, %esi // %esi = y
addl %ebx, %eax // sum += x
addl %edi, %ebx // x++
jmp L2 // go to beginning of loop
rmmovl %eax, (%eax) //value assigned to sum global variable
L3:
rrmovl %ebp, %esp //finish
popl %ebx
popl %esi
popl %edi
popl %eax
popl %ebp
ret
.align 4
x: .long 1
y: .long 4
sum: .long 0
.pos 0x200
Stack: .long 0
I figured out why the registers were getting the wrong values (I was sending them the memory locations with irmovl instead of the values with mrmovl) and in a similar vein, how to assign the value to the global variable sum (rmmovl %eax, sum).
It was a matter of addressing the content as opposed to location