0% found this document useful (0 votes)
168 views7 pages

Activity No 7 Procedure

The document describes several assembly language programs that demonstrate procedures and the stack. It includes programs that: 1) Push and pop values to demonstrate how the stack works 2) Interchange procedures to output values differently 3) Change an instruction to alter the output 4) Take user input for addition and output the sum in decimal The document provides instructions for students to create, run, and analyze the assembly language programs.

Uploaded by

alex sanders
Copyright
© © All Rights Reserved
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)
168 views7 pages

Activity No 7 Procedure

The document describes several assembly language programs that demonstrate procedures and the stack. It includes programs that: 1) Push and pop values to demonstrate how the stack works 2) Interchange procedures to output values differently 3) Change an instruction to alter the output 4) Take user input for addition and output the sum in decimal The document provides instructions for students to create, run, and analyze the assembly language programs.

Uploaded by

alex sanders
Copyright
© © All Rights Reserved
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/ 7

Activity No.

7
PROCEDURE
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate how stack works in Assembly Language

2. Intended Learning Outcomes (ILOs):

After completion of the activity the students should be able to:

1.1 Create a procedure in Assembly


1.2 Demonstrate push and pop operations
3. Discussion :
Stack
The stack is part of the memory that is used as a temporary storage of return addresses and data.
There are two most common types of stack: the FIFO (First-In, First-Out), also called queue and LIFO
(Last-In, Last-Out). The names of which are implied by the way data are stored and retrieved from them.
The two operations on the stack are the PUSH and POP. The PUSH instruction is used to place
values on the stack and the POP instruction is used to remove values from the stack.
The Stack Pointer (SP) register points to the top of the stack at any given time as the Instruction
Pointer (IP) holds the address of the next instruction to be fetched and executed. The POP instruction
decrements the value of the SP by two and the POP instruction increments the SP by 2.
Since the stack is part of the memory we should specify the size of the stack. We specify the size
of the stack in our program as follows:
.stack 100h
Procedure
Procedure or subroutine is a special part of the program that can be called for execution from any
point in the program. The procedure is written to provide a function that must be performed frequently at
various points in the main program. Whenever the function must be performed, a single instruction is
inserted into the main body of the program to CALL the procedure. The RET instruction must be included at
the end of the procedure to return to the main program.
Whenever there is a CALL to the procedure the value of the IP is automatically push to the stack,
and the RET instruction later will pop the value from the stack to the IP.
In Assembly, a procedure is in the form:
<procedure name> PROC
<instruction 1>
<instruction 2>
<procedure name> ENDP
Calling a Procedure has the form:
CALL <procedure name>
Returning from a Procedure has the form:
BODY proc
call <procedure1>
call <procedure2>
BODY endp
PROCEDURE1 proc
:
ret
PROCEDURE1endp
PROCEDURE2 proc
:
ret
PROCEDURE2endp

4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Program A.
1. Type the following in Notepad.
TITLE proc1.asm
.model small
.stack 100h
.data
.code
main proc
movax,@data
movds,ax
xoral,al
mov cx,16
lp1: push ax
call out1hex
call pcrlf
pop ax
inc al
loop lp1
Mov ax, 4c00h
Int 21h
Main endp

Out1hex proc
And al,0fh
Cmp al,9
Ja ischar
Add al,30h
Jmpprintit
Ischar: add al,37h
Printit: Movdl,al
Mov ah,2
Int 21h
Ret
Out1hex endp

Pcrlfproc
Mov dl,0ah
Mov ah,2
Int 21h
Mov dl,0dh
Mov ah,2
Int 21h
Ret
Pcrlfendp
End main
2. Save the program as proc1.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.1.
What does the procedure Pcrlfdo?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Sample Program B.
1. Modify proc1.asm, interchange the placement of procedure Out1hex with Pcrlf.
2. Save the program as proc2.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.2.
How is your output different from before? Why?
___________________________________________________________________________
___________________________________________________________________________
______________________________________________________________________________

Sample Program C.
1. Modify proc1.asm, change line number 15 with “inc al”.
2. Save the program as proc3.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.3.
How is your output different from before? Why?
___________________________________________________________________________
___________________________________________________________________________
Sample Program B.
1. Type the following in a Notepad.
dosseg
.model small
.stack
.data
msg1 db 13,10,"Enter first number:$"
msg2 db 13,10,"Enter second number:$"
msg3 db 13,10,"Sum in decimal number:$"
num1 db ?
sum db ?
res db 20 DUP('$')
.code
main proc
movax,@data
movds,ax

lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,'0'
mov num1,al

lea dx,msg2
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,'0'
add al,num1
movsum,al

lea dx,msg3
mov ah,09h
int 21h

movsi,offset res
mov ax,00
moval,sum
call addition

lea dx,res
mov ah,09h
int 21h
mov ax,4c00h
int 21h

main endp
addition proc near
push ax
push bx
push cx
push dx
push si
mov cx,00h
mov bx,0Ah

rpt1: mov dx,00


div bx

add dl,'0'
push dx

inc cx
cmp ax,0Ah
jge rpt1

add al,'0'
mov [si],al
rpt2: pop ax
incsi
mov [si],al
loop rpt2

incsi
mov al,'$'
mov [si],al

pop si
pop dx
pop cx
pop bx
pop ax
ret
addition endp
end
2. Save the program as proc4.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.4.

6. DATA ANALYSIS:

Table 7.1 – Output of proc1.asm Table 7.3- Output of proc3.asm

Table 7.2– Output of proc2.asm Table 7.4- Output of proc4.asm

7. PROBLEMS:

1. Create an assembly language program asks the user to enter a password formed from 10
characters. The program prints the password as stars on the screen. If the password is correct, the
program should print “Password is CORRECT!” otherwise, “Password is INCORRECT!”

Create a program that will accept number in decimal and convert it to hexadecimal, binary and octal.

8. CONCLUSIONS:

9. Assessment (Rubric for Laboratory Performance):

You might also like