0

Assume address 100 holds the value 7 and address 200 holds the value 3, explain the instruction cycle for the arithmetic instruction sub using Von Neumann Machine definition.

push[100]
push[200]
sub
pop[500]

I know the answer is

  • push[100] so Top of the stack is 7 , as the value in address 100 is 7
  • push[200] so Top of the stack is 3, as the value in address 200 is 3.
  • sub so you subtract 7 minus 3 i.e do (7-3) and 4 will be stored in stack address 500.
  • pop[500] so you pop the value contained in address 500. so 4 will be popped and returned."

I wanted to ask why the 4 would be stored in address 500?

zx485
  • 28,498
  • 28
  • 50
  • 59
  • 1
    I think the sub will operate over the two stack arguments, ie leaving the result at the top of the stack. the `pop [500]` will then read the value from top of the stack, and store it into memory at address 500. The `sub` is not aware of existence of `500`, that's in the opcode of next instruction, but assembly instructions usually don't take a "peek" forward or backward, assembly instruction is usually autonomous and all the "state" affecting it's executing is either encoded in the instruction self (f.e. immediate value), or part of it's arguments (memory value, stack value, flags value, etc). – Ped7g Feb 23 '17 at 15:39
  • Oh, that makes so much more sense. Thanks! – ThisIsntAUserName Feb 23 '17 at 15:45
  • In real world like Z80 or x86 CPU the "top of the stack" is ordinary RAM memory being pointed at with register `sp` (Stack Pointer), `push` instruction then internally works as subtracting size of argument from `sp`, then storing the argument into memory at address `sp`. `pop` works the other way, loading the value from address `sp` into argument, and adding size of argument to `sp`, so "top of stack" is pointing to next value. (You can also manipulate with register `sp` directly, for example common way to "allocate" (reserve) space for C/C++ local variables is to do `sub sp,`) – Ped7g Feb 23 '17 at 15:48

0 Answers0