0% found this document useful (0 votes)
21 views

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. The document discusses using the runtime stack in MASM assembly language. It provides examples of using push/pop commands to: - Retrieve a value stored on the stack using pusha - Reverse an array by pushing and popping values from the stack - Convert lowercase letters to uppercase by pushing characters and popping with an offset 2. Key effects of push and pop are that push decrements the stack pointer and pop increments the stack pointer. A 32-bit value can be pushed/popped from memory to the stack using multiple push/pop commands for the value's bytes.

Uploaded by

Daniyal Arshad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

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. The document discusses using the runtime stack in MASM assembly language. It provides examples of using push/pop commands to: - Retrieve a value stored on the stack using pusha - Reverse an array by pushing and popping values from the stack - Convert lowercase letters to uppercase by pushing characters and popping with an offset 2. Key effects of push and pop are that push decrements the stack pointer and pop increments the stack pointer. A 32-bit value can be pushed/popped from memory to the stack using multiple push/pop commands for the value's bytes.

Uploaded by

Daniyal Arshad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB # 6 Stack

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:

You might also like