Y86 assembly global variables

别说谁变了你拦得住时间么 提交于 2019-12-31 04:26: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


来源:https://stackoverflow.com/questions/33714298/y86-assembly-global-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!