70 likes | 229 Views
CS 206D Computer Organization Lab9. 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 . Solution .
E N D
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=5678hCX=9ABChSP=0100h • PUSH AX 1234 56789ABC00FE 1234 is pushed • PUSH BX 1234 56789ABC00FC 5678 is pushed • XCHG AX,CX 9ABC 5678123400FC • POP CX 9ABC 5678567800FE 5678 is popped • PUSH AX 9ABC 5678567800FC 9ABC is pushed • POP BX 9ABC 9ABC567800FE 9ABC is popped CS 111
Question 2 • Write some code to do the following: • 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