【问题标题】:Using Global Variables in Y86 Assembly在 Y86 汇编中使用全局变量
【发布时间】:2014-11-19 02:18:45
【问题描述】:

我正在尝试编写一个程序来创建 x 和 y 之间所有包含整数的和,其中 sum、y 和 x 是全局变量。当我尝试将 x 和 y 分配给本地寄存器时遇到问题(我的模拟器将 0x60 和 0x64 的值分配给本地寄存器,而不是 1 和 4)以及获取总和并将其传输到sum 的全局变量。通常我会尝试在网上找到有用的指南,但 Y86 是一种很少使用的语言,几乎没有。

我的代码:

.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

【问题讨论】:

    标签: assembly global-variables cpu-registers y86


    【解决方案1】:

    我弄清楚了为什么寄存器会得到错误的值(我用 irmovl 向它们发送内存位置,而不是用 mrmovl 的值),并且类似地,如何将值分配给全局变量 sum (rmmovl % eax,总和)。

    这是解决内容而不是位置的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 2023-02-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多