Q.Analyse the following PUSH and POP sequence. Assume the stack pointer SP is first loaded with 30H and that RAM location 00H (register R0) already contains the value ACH. State the value of SP and the affected location after each instruction.
MOV 81H, #30H ; copy the immediate data 30H to the SP
PUSH 00H
PUSH 00H
POP 01H
POP 80H
MOV 81H, #30H ; copy the immediate data 30H to the SP
PUSH 00H
PUSH 00H
POP 01H
POP 80H
[!TLDR]
SP is set to 30H; each PUSH increments SP then writes ACH into internal RAM, and each POP reads a byte back and then decrements SP, ending with SP = 30H after R1 and Port 0 both receive ACH.
Concept - the stack, SP, PUSH and POP. The stack is an area of internal RAM addressed through the Stack Pointer SFR (SP), whose direct address is 81H. PUSH direct first increments SP and then copies the byte at the given direct address into the RAM location now pointed to by SP. POP direct does the reverse: it copies the byte at the RAM location pointed to by SP into the given direct address and then decrements SP.
Given: SP is loaded with 30H and RAM location 00H (register R0 of bank 0) holds ACH.
Trace:
MOV 81H, #30H- 81H is the direct address of SP, so SP = 30H.PUSH 00H- SP is incremented to 31H, then the content of address 00H (ACH) is copied to RAM location 31H. Now RAM[31H] = ACH.PUSH 00H- SP is incremented to 32H, then ACH is copied to RAM location 32H. Now RAM[32H] = ACH.POP 01H- the byte at RAM[32H] (ACH) is copied to address 01H (register R1), then SP is decremented to 31H. Now R1 = ACH.POP 80H- the byte at RAM[31H] (ACH) is copied to address 80H (the Port 0 latch), then SP is decremented to 30H. Now P0 = ACH.
[!ANSWER]
SP: 30H -> 31H -> 32H -> 31H -> 30H. RAM[31H] = RAM[32H] = ACH after the pushes; then R1 = ACH and the Port 0 latch = ACH, with SP restored to 30H.
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.