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 5 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 1 paragraph description of the working of the program.
Template -
; Use the PUSH and POP instructions to display a list of 16-bit
; integers in reverse order on the console.
; Uses indirect addressing with a loop.
.model small
.stack 100h
.data
aList dw 100h,200h,300h,400h,500h ; 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.
L1: ........... ; 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 L1; loop to the next iteration
; Pop and display the numbers.
..........; load cx register with the number of times to loop
L2: pop ax; pop from stack
......... ; display in hexadecimal
loop L2 ; loop to the next iteration
main endp
end main
Helpful Syntax -
1) 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 !=0.
Example -
mov cx,3
myloop:
; Your loop content
loop myloop
2) How to store the offset of the array and mov over the array list for each iteration?
mov si,offset aList ;stores the address of the array into si register
mov ax,[si] ; move the content at the address in the si register
add si,type 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!