Lab # 6 Stack: A. To Learn Use of Runtime Stack in MASM. B. To Learn How To Use Push/pop Commands and Its Variants
Lab # 6 Stack: A. To Learn Use of Runtime Stack in MASM. B. To Learn How To Use Push/pop Commands and Its Variants
1. Objective a. To learn use of Runtime Stack in MASM. b. To learn how to use push/pop commands and its variants 2. Hardware/Software required a. Hardware: PC b. Software Tool/Application: MASM615 3. Tasks, Coding and Screenshots a. Task 1: To retrieve value of SI stored on the stack by pusha instruction. You can increment SP for changing the top of stack. include irvine16.inc .data num1=8 .code main proc mov ax,@data mov ds,ax mov ax,5 mov cx,6 mov dx,5 mov bx,10 mov di,num1 mov si,14 mov bp,5 mov sp,num1 pusha inc sp inc sp pop ax call writeint call crlf .exit
main endp end main b. Stack essentially being a LIFO structure could be used to reverse the sequence of stored values. Write a program using stack to reverse an array by first pushing and then popping its value from stack. include irvine16.inc .data array1 word 1,2,3,4,5 .code main proc mov ax,@data mov ds,ax mov si,offset array1 mov cx,5 r: push [si] add si,2 loop r mov cx,5 n: pop ax call crlf call writeint call crlf loop n .exit main endp end main
c.
Write a procedure to convert all lower case alphabets to upper case. Hint: You can use ADD or AND instruction
include irvine16.inc .data lower db "abcdefghijklmnopqrstuvwxyz" .code upper proc mov cx,26 r: push [si] inc si
loop r mov cx,26 mov ax,0 n: pop ax sub ax,32 call writechar mov right[si][26],ax loop n ret upper endp main proc mov ax,@data mov ds,ax mov si,offset lower call upper call crlf .exit main endp end main 4. Questions/Assignments a. What is the effect of push and pop command on Stack Pointer? Ans: When Push statement is used the stack pointer is decremented while the pop statement causes the stack pointer (SP) to be incremented. b. How can you push/pop a 32-bit value from memory to the stack? Ans: