A microprocessor has three 16-bit registers—D1, D2, and D3—with the initial values shown below in hexadecimal: 

D1: 0123
D2: 4567
D3: 89AB 

The registers are pushed onto the stack and immediately popped off in the following sequence:

PUSH D1
PUSH D2
PUSH D3
POP D1
POP D2
POP D3

The value in D1 after the operations are performed is most nearly:

A.  0123
B.  4567
C.  89AB
D.  2301

1 Answer

James Dowd

Updated on December 30th, 2020

To understand a stack, lets think of it as a stack of books. When you're placing books onto a desk, you place the first one, then you place the next on top, and so on until you have a pile in front of you. When you want to take a book from the pile, you may only take it after you have removed all of the books on top of it, starting from the very top and working your way down through the pile. 

This is how stacks work. Pushing a register loads those values into the bottom of the stack. Pushing another register will load it on top of the first. It is analogous to stacking books on the desk. Popping a register takes the value loaded at the very top of the stack. It is analogous to taking books from the stack. 

Based on this, let's visualize the sequence of our instruction set:

  1. PUSH D1         0123
  2. PUSH D2     45670123
  3. PUSH D3 89AB45670123
  4. POP D1     45670123, D1=89AB
  5. POP D2         0123, D2=4567
  6. POP D3             , D3 = 0123

Therefore, the value of D1 after these order of operation will be 89AB, represented by answer C.

Copyright © 2025 Savvy Engineer