Y86 assembly global variables

2019-03-02 13:28发布

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"

标签: assembly y86
1条回答
叼着烟拽天下
2楼-- · 2019-03-02 14:08

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
查看更多
登录 后发表回答