CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh...

7
CS 206D Computer Organization Lab9 CS 111

Transcript of CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh...

Page 1: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

CS 111

CS 206D Computer OrganizationLab9

Page 2: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

CS 111

Question 2

Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100hGive the content of AX, BX, CX and SP after executing the following instructions: PUSH AX

PUSH BXXCHG AX ,CXPOP CXPUSH AXPOP BX

Page 3: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

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

Page 4: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

CS 111

Question 2

Write some code to do the following: 1) Place the top of the stack into AX without changing the

stack contents2) 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.

Page 5: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

CS 111

Solution

1) Place the top of the stack into AX without changing the stack contentsPOP AX ;place top of stack into AXPUSH AX ;restore stack contents

Page 6: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

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 AXPOP CX ;place word that is below original stack top into CXPUSH CX ;restore word that is below original stack topPUSH AX ;restore original stack top

Page 7: CS 206D Computer Organization Lab9 CS 111. Question 2 CS 111 Suppose that AX=7800h BX=1234h CX=91ACh and SP=0100h Give the content of AX, BX, CX and SP.

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 AXPOP BX ;place word that is below original stack top into BXPUSH AX ;place original stack top back on stackPUSH BX ;place word that was originally below stack top onto stack top