Lab08SE.docx
Lab08SE.docx
Topic:
1) Irvine setup
2) Procedure
3) Stack operations
Irvine setup:
First download Irvine it from your Google Classroom unzip it into c directory folder
After that copy the file path and includes it into your project path into multiple following steps.
1) Right click you .asm file and go to properties section click new window is pop out from there
you need to go Item Type just select Microsoft Macro Assembler then apply and ok.
Now copy the path of Irvine folder and right click of your project included go to properties
section from that select Linker option select Additional Library Directories includes you need
to paste the path of Irvine folder that is present in your C drive.
Feom Link drop down go to input section and select the Additional Dependencies just write
Irvine32.lib and ok.
Now go to the Microsoft Macro Assembler then select Inculde path paste the path then click
Ok than Apply and ok
Now your Irvine setup is included just paste this code and test it.
Procedure/Functions
Key Elements
Simple Example
This example demonstrates a procedure called DisplayMessage that prints a message to the console
using the Irvine32 library.
Code Example (main.asm)
INCLUDE Irvine32.inc ; Include the Irvine32 library
.data
message BYTE "Hello from the procedure!", 0 ; Define a message string
.code
main PROC
call DisplayMessage ; Call the DisplayMessage procedure
exit ; Exit the program
main ENDP
Stack Applications
There are several important uses of runtime stacks in programs:
a. A stack makes a convenient temporary save area for registers when they are used for
more than one purpose. After they are modified, they can be restored to their original
values.
b. When the CALL instruction executes, the CPU saves the current subroutine’s return
address on the stack.
c. When calling a subroutine, you pass input values called arguments by pushing them on
the stack.
d. The stack provides temporary storage for local variables inside subroutines.
PUSH Instruction:
The PUSH instruction first decrements ESP and then copies a source operand into the stack.
A 16-bit operand causes ESP to be decremented by 2. A 32-bit operand causes ESP to be decremented by
4. There are three instruction formats:
PUSH reg/mem16
PUSH reg/mem32
PUSH imm32
POP Instruction:
The POP instruction first copies the contents of the stack element pointed to by ESP into a 16- or
32-bit destination operand and then increments ESP. If the operand is 16 bits, ESP is incremented by 2; if
the operand is 32 bits, ESP is incremented by 4:
POP reg/mem16
POP reg/mem32
Tasks:
1. Reversing an Array using Stack
● Problem Statement: Write an assembly program to reverse an array of integers using stack
operations. Push each element of the array onto the stack and then pop them in reverse order.
● Input: [3, 5, 7, 9, 11]
● Output: [11, 9, 7, 5, 3]
3. Palindrome Checker
● Problem Statement: Implement a postfix expression evaluator using stack operations. Push
operands onto the stack and pop them when encountering an operator to perform calculations.
● Input: "5 6 + 2 *" (Postfix notation for (5 + 6) * 2)
● Output: 22
● Problem Statement: Use stack operations (PUSH and POP) to simulate swapping in a Bubble Sort
algorithm to sort an array.
● Input: [8, 4, 3, 7, 6]
● Output: [3, 4, 6, 7, 8]
6. Infix to Postfix Conversion
● Problem Statement: Simulate a stack data structure using an array. Implement the basic stack
operations: PUSH, POP, PEEK, and DISPLAY.
● Input: Push: 3, Push: 5, Pop, Push: 9
● Output: [3, 9]
● Problem Statement: Write a program that finds the maximum element in a stack. After pushing
all elements, pop them to check the maximum value.
● Input: [2, 9, 4, 6, 1]
● Output: 9
● Problem Statement: Write a program to reverse a string using stack operations. Push each
character onto the stack and then pop them in reverse order to form the reversed string.
● Input: "hello"
● Output: "olleh"