Question: Build a Stack. This exercise is to understand stack operation in MASM. Build a stack by pushing 5 data elements into stand and popping out
Build a Stack.
This exercise is to understand stack operation in MASM. Build a stack by pushing data elements into stand and popping out the same data elements and display the values to user.
The code template is given below with the comments. Your task is to fill in the dotted lines of code, execute and show the results. You have to submit the running code, screen shot of the results and a brief paragraph description of the working of the program.
Template
; Use the PUSH and POP instructions to display a list of bit
; integers in reverse order on the console.
; Uses indirect addressing with a loop.
model small
stack h
data
aList dw hhhhh ; declare array list of data elements
code
main proc
; init data segment
; load cx register with the number of times to loop
; store si register with the offset of the data array
; Push the numbers.
L: ; move the data element into ax register
push ax ; push ax into stack
; increment the si pointer to nect data element in the array
loop L; loop to the next iteration
; Pop and display the numbers.
; load cx register with the number of times to loop
L: pop ax; pop from stack
; display in hexadecimal
loop L ; loop to the next iteration
main endp
end main
Helpful Syntax
How to write loops in MASM?
Load the number to iterate over the loop in CX register. The loop instruction automatically decrements cx and only jumps if cx
Example
mov cx
myloop:
; Your loop content
loop myloop
How to store the offset of the array and mov over the array list for each iteration?
mov sioffset aList ;stores the address of the array into si register
mov axsi ; move the content at the address in the si register
add sitype aList ;increment the address value in the si register to pint to the next element of the array
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
