In: Computer Science
Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively.
SS |
SP |
TOS |
AX |
BX |
CX |
DX |
||
Initial contents |
0990 |
0100 |
/ |
789A |
0020 |
2000 |
1234 |
|
after |
PUSH AX |
|||||||
after |
PUSH BX |
|||||||
after |
PUSH CX |
|||||||
after |
POP DX |
|||||||
after |
POP CX |
|||||||
after |
PUSH DX |
|||||||
after |
POP AX |
|||||||
after |
POP BX |
Stack Pointer operation:
· PUSH - stores 16 bit value in the stack.
Syntax for PUSH instruction:
PUSH REG
• A push operation decrements the stack pointer by 2 or 4
(depending on operands) and copies a value into the location
pointed to by the stack pointer.
· POP - gets 16 bit value from the stack.
Syntax for POP instruction:
POP REG
· pop — Pop stack
· The pop instruction removes the 4-byte data element from the top of the hardware-supported stack into the specified operand (i.e. register or memory location). It first moves the 4 bytes located at memory location [SP] into the specified register or memory location, and then increments SP by 4.
· In 8086, the main stack register is called stack pointer - SP. The stack segment register (SS) is usually used to store information about the memory segment that stores the call stack of currently executed program. SP points to current stack top.
General purpose registers in 8086 microprocessor
1)AX – This is the accumulator. It is of 16 bits and is divided into two 8-bit registers AH and AL to also perform 8-bit instructions.
It is generally used for arithmetical and logical instructions but in 8086 microprocessor it is not mandatory to have accumulator as the destination operand.
2)BX – This is the base register. It is of 16 bits and is divided into two 8-bit registers BH and BL to also perform 8-bit instructions.
It is used to store the value of the offset.
3)CX – This is the counter register. It is of
16 bits and is divided into two 8-bit registers CH and CL to also
perform 8-bit instructions.
It is used in looping and
rotation.
4)DX – This is the data register. It is of 16
bits and is divided into two 8-bit registers DH and DL to also
perform 8-bit instructions.
It is used in
multiplication an input/output port addressing.
5)SP –
This is the stack pointer. It is of 16 bits.
It points to the topmost item of the stack. If the stack is empty
the stack pointer will be (FFFE)H. It’s offset address relative to
stack segment.
Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved. Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of AX, BX, CX, and DX are 789Ah, 0020h, 2000h, and 1234h respectively.
Assume that before execution begins the SS register contains 0410h, and the SP register 0100h, and that the contents of
AX=789Ah
BX=0020h
CX=2000h
and DX=1234h
Initial contents:
SS=0410h
SP=0100h
TOS=0990h
Answer:
Make a detailed trace of the execution of the following program fragment, giving the contents of all the registers, and memory locations involved.
1) after
PUSH AX
– SP decreases as data is PUSHed
PUSH AX ==> SUB SP, 2 ; MOV [SS:SP], AX
AX =789Ah goes to memory location 0991=78 0990=9A
2) after
PUSH BX
– SP decreases as data is PUSHed
PUSH BX ==> SUB SP, 2 ; MOV [SS:SP], BX
BX =0020h goes to memory location 0993=00, 0992=20
3) after
PUSH CX
– SP decreases as data is PUSHed
PUSH CX ==> SUB SP, 2 ; MOV [SS:SP], CX
CX =2000h goes to memory location 0995=20 ,0994=00
4) POP DX
– SP increases as data is POPed
POP DX ==> MOV DX, [SS:SP] ; ADD SP, 2
DX=1234h after execution of this instruction mov the content from memory to register DX
5) POP CX
– SP increases as data is POPed
POP CX ==> MOV CX, [SS:SP] ; ADD SP, 2
After execution of POP CX
CX =2000h
CH CL
20 00
0995h 0994h
The register CX contain 2000h after execution.
6) after
PUSH DX
– SP decreases as data is PUSHed
PUSH DX ==> SUB SP, 2 ; MOV [SS:SP], DX
DX =1234h goes to memory location 0997=12 ,0996=34
7) after
POP AX
– SP increases as data is POPed
POP AX ==> MOV AX, [SS:SP] ; ADD SP, 2
After execution of POP AX
AX =789Ah
AH AL
78 9A
0991h 0990h
The register AX contain 789Ah after execution.
8) after
POP BX
– SP increases as data is POPed
POP BX ==> MOV BX, [SS:SP] ; ADD SP, 2
After execution of POP AX
BX =0020h
BH BL
00 20
0993h 0992h
Content of BH is stored in 0993h location and Content of BL is stored in 0992h location
The register BX contain 0020h after execution.