Y86 assembly global variables

2019-03-02 13:11发布

问题:

I am struggling to get global variables to work correctly for my Y86 assignment. Unfortunately the only examples we were provided with are in IA-32 assembly. I have searched for the last few hours but to no avail. This is very basic I know but I am a complete novice at Y86.

I am "declaring" my variables as follows

.align 4
x: .long 1
y: .long 4

When I use them in an operation such as irmovl x, %edx I see the value 380 is assigned to the edx register instead of the value 4. I think what is happening is that I am assigned the memory location to the register instead of the value. What would be the correct syntax to set the value of the global variable to the register?

I have tried using mrmovl instead but am unsure of the syntax for mrmovl with a global variable.

mrmovl x, %edx give me the error "x is not a number"

回答1:

irmovl as the name says is immediate to register. You want mrmovl as that is memory to register.

As for the syntax, since y86 does support displacement, I would expect mrmovl x, %edx to work. You say it doesn't, as a workaround you could use 2 instructions:

irmovl x, %edx     # load address
mrmovl (%edx), %edx # fetch value


标签: assembly y86