Question: 2. Coding by using the Stack [10+10+10pt] 2.1 Early computers use a stack organization: heres how x = a - b is done: push a
2. Coding by using the Stack [10+10+10pt]
2.1 Early computers use a stack organization: heres how x = a - b is done:
push a # a is pushed onto stack
push b # b is pushed onto stack
Sub # pop out the top two number, performing # subtraction, and push the result back
Pop x # x = item pop from stack
Show how x = ( (a - b) * (c + d) ) / (e f ) can be done.
Suppose the available instructions are: push, pop, sub, add, mul, div.
2.2 A user defined stack with partially available information are shown below. Based on the provided clues, fill in its other operations.
a) .data
my_stack: .word 0, 0, 0, 0, 0, 0 ...
.text
#----- initialize stack pointer---
___________ ___________ ...
#----- pop from stack into $t1 ---
lw $t1, -4($t2) subi $t2, $t2, 4 ...
#----- push $t6s value onto stack
__________________ __________________
b) .data
my_stack: .byte -1, -1, -1, -1 ...
.text
# ---- initialize stack pointer---
_____________ _____________ ...
# ---- push $t2s value onto stack ---
addi $s1, $s1, 1 sb $t2, ($s1) ...
#----- pop from stack into $t5 --------
__________________ __________________
c) .data
my_stack: .word 1, 2, 3, 4, 5, 6, 7 ...
.text ... #----- pop from stack into $t1 ---
addi $s2, $s2, 4 lw $t1, -4($s2) ...
#----- push $t0s value onto stack
__________________ __________________
MUST BE IN MIPS ASSEMBLY
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
