### Lab9

```CS 206D Computer Organization
Lab9
CS 111
Question 2
Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h
Give the content of AX, BX, CX and SP after executing the
following instructions: PUSH AX
PUSH BX
XCHG AX ,CX
POP CX
PUSH AX
POP BX
CS 111
Solution
Initial: AX=1234h BX=5678h CX=9ABCh SP=0100h
PUSH AX 1234 5678
9ABC 00FE 1234 is pushed
PUSH BX 1234 5678
9ABC 00FC 5678 is pushed
XCHG AX,CX 9ABC 5678 1234 00FC
POP CX 9ABC
5678 5678 00FE 5678 is popped
PUSH AX 9ABC 5678 5678 00FC 9ABC is pushed
POP BX 9ABC 9ABC 5678 00FE 9ABC is popped
CS 111
Question 2
Write some code to do the following:
1) Place the top of the stack into AX without changing the
stack contents
2) Place the word that is below the stack top into CX,
without changing the stack contents. You may use AX.
3) Exchange the top two words on the stack. You may use AX
and BX.
CS 111
Solution
1) Place the top of the stack into AX without changing the
stack contents
POP AX ;place top of stack into AX
PUSH AX ;restore stack contents
CS 111
Solution
2) Place the word that is below the stack top into CX,
without changing the stack contents. You may use AX.
POP AX ;place original stack top into AX
POP CX ;place word that is below original stack top into
CX
PUSH CX ;restore word that is below original stack top
PUSH AX ;restore original stack top
CS 111
Solution
3) Exchange the top two words on the stack. You may use AX and BX.
POP AX ;place original stack top into AX
POP BX ;place word that is below original stack top into BX
PUSH AX ;place original stack top back on stack
PUSH BX ;place word that was originally below stack top onto stack top
CS 111
```