0

I am currently writing functions using an educational assembly language called Y86, AT&T syntax and am trying to accomplish/get around something this doesn't support. I want to add a number to a value stored in memory and for some stupid reason you can only use addl to add to a register. I don't know why this is.

Inside a function I want to do something such as this and don't know how:

addl $1, -4(ebp)

Also, I seem to have a problem of running out of registers. Maybe it's because I don't know how to make room for storing local variables. I have heard thought there is a concept where registers are saved by the caller and callee. I would greatly appreciate any commands that are equal to what's above but in Y86. Also any tips on saving registers would be great! THANK YOU! I know looking over this stuff is a real pain.

nrz
  • 10,435
  • 4
  • 39
  • 71
Tastybrownies
  • 897
  • 3
  • 23
  • 49

1 Answers1

0

In x86 and Y86 too registers are can be pushed to stack by using push and popped from stack by using pop. Like this:

push %ax ; push ax into stack

; some code here that may overwrite ax.

pop %ax  ; pop ax from stack

x86 has a limited number of register, so many times one needs to use memory for some of the variables.

To create space in stack for local variables, you need to create a stack frame. See What is stack frame in assembly? .

Community
  • 1
  • 1
nrz
  • 10,435
  • 4
  • 39
  • 71