1 What is the function of the stack How does it work Show th


1. What is the function of the stack? How does it work? Show the stack and stack pointer for each line of the following program. ORG 0

MOV R0, #66H

MOV R3, #7FH

MOV R7, #5DH

PUSH 0

PUSH 3

PUSH 7

CLR A

MOV R3, A

MOV R7, A

POP 3

POP 7

POP 0

2. Translate the assembly language program given in problem #1 to machine language and show the contents and address of the ROM where program is stored.

The instructions format are given below:

Instruction         Bytes      Encoding

MOV Rn, #data     2        01111rrr dddddddd

MOV Rn, A          1        11111rrr

PUSH direct         2         11000000 aaaaaaaa

POP direct            2         11010000 aaaaaaaa

CLR A                   1         11100100

Solution

1. What is Stack?
In Assembly Language programming, when a program starts executing, a certain contiguous section of memory is set aside for the program called the stack.The stack pointer is usually a register that contains the top of the stack. The stack pointer contains the smallest address x such that any address smaller than x is considered garbage, and any address greater than or equal to x is considered valid.
How does it work?

Pushing onto the stack

For example, in MIPs a push instruction would be implemented like:

and a Pop instruction would look like:

Ans:

ORG 0
MOV R0, #66H ;SP = 08, Contents of stack are undefined, R0 = 66H
MOV R3, #7FH ;SP = 08, Contents of stack are undefined, R3 = 7FH
MOV R7, #5DH ;SP = 08, Contents of stack are undefined, R7 = 5DH
PUSH 0 ;SP = 09, location 09 contains 66H
PUSH 3 ;SP = 0A, location 0A contains 7FH
PUSH 7 ;SP = 0B, location 0B contains 5DH
CLR A ;clear the accumulator
MOV R3, A ;move accumulator to R3, clears R3
MOV R7, A ;move accumulator to R7, clears R7
POP 3 ;location 0B is moved to R3 (5DH) SP = 0A
POP 7 ;location 0A is moved to R7 (7FH) SP = 09
POP 0 ;location 09 is moved to R0 (66H) SP = 08

so in the end
R0 = 66H
R3 = 5DH
R7 = 7FH

Note: PUSH increments the SP first, then saves the value. POP gets the value first, then decrements the SP.

 1. What is the function of the stack? How does it work? Show the stack and stack pointer for each line of the following program. ORG 0 MOV R0, #66H MOV R3, #7F
 1. What is the function of the stack? How does it work? Show the stack and stack pointer for each line of the following program. ORG 0 MOV R0, #66H MOV R3, #7F

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site