Preserving a return address across a nested call

A teaching processor has 32-bit registers, byte-addressed memory, and four-byte instructions. Its link register, LR, holds a return address. Its stack pointer, SP, holds the address of the current top of a downward-growing stack.


For this processor, use these exact instruction rules:

  • CALL target writes the address of the instruction immediately following the call into LR, then transfers execution to target.
  • RET transfers execution to the address currently in LR and changes no register.
  • PUSH LR subtracts 4 from SP, then stores the four-byte value of LR at the new address in SP.
  • POP LR loads LR from the four bytes starting at SP, then adds 4 to SP.
  • SUB SP, SP, 12 subtracts 12 from SP; ADD SP, SP, 12 adds 12 to SP.
  • NOP changes no register, and execution continues at the next instruction.

Initially, SP is 12000. Execution begins at address 4096. All displayed addresses and constants are decimal. Assume no interrupts or other changes to the machine state.


Plain text
4096:  CALL 8192
4100:  NOP

8192:  PUSH LR
8196:  CALL 12288
8200:  POP LR
8204:  RET

12288: SUB SP, SP, 12
12292: ADD SP, SP, 12
12296: RET


For the original program, determine the minimum value reached by SP, the return-address value saved by PUSH LR, and the program-counter value immediately after the RET at address 8204. Then consider a separate run from the same initial state in which the instruction at address 8200 is replaced by NOP. Determine the program-counter value immediately after the first execution of the RET at address 8204 in that modified run.


Give all four answers as exact decimal integers in bytes: stack and program-counter answers are byte addresses, and the saved value is a return byte address.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Machine and Assembly Language Programming Questions: