[go: up one dir, main page]

0% found this document useful (0 votes)
72 views5 pages

Laboratory Manual: For Computer Organization and Assembly Language

The document is a laboratory manual for a computer organization and assembly language course. It discusses stack operations using PUSH and POP instructions, calling procedures using CALL and RET instructions, and arithmetic and logic instructions. Specifically, it defines a stack, explains how PUSH stores values and POP retrieves values from the stack. It also describes procedure declarations and calling procedures with CALL while returning with RET. Finally, it provides a table explaining common arithmetic and logic instructions like AND, OR, XOR, and TEST in assembly language.

Uploaded by

muhammad umer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views5 pages

Laboratory Manual: For Computer Organization and Assembly Language

The document is a laboratory manual for a computer organization and assembly language course. It discusses stack operations using PUSH and POP instructions, calling procedures using CALL and RET instructions, and arithmetic and logic instructions. Specifically, it defines a stack, explains how PUSH stores values and POP retrieves values from the stack. It also describes procedure declarations and calling procedures with CALL while returning with RET. Finally, it provides a table explaining common arithmetic and logic instructions like AND, OR, XOR, and TEST in assembly language.

Uploaded by

muhammad umer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

National University of Computer and Emerging Sciences

Laboratory Manual
for

Computer Organization and Assembly Language

Lab Instructor(s) Uzair Tahir


Semester Fall 2017

Department of Computer Science


FAST – NU, Fsd Campus

COAL Lab 6 Manual


Objectives:
 Stack & Procedures
 PUSH and POP instructions in assembly language
 CALL and RET instructions in assembly language
 Logic operators

Stack:
A stack is one dimensional data structure. Items are added
and remove from one end of structure i.e. it is processed in a “last-
in, first-out” manner. The most recent addition to the stack is called
top of the stack. A program must set aside a block of memory to
hold the stack. The stack is a special segment in memory used to
facilitate subroutine handling. We have been doing this by declaring
a stack segment; for example.
.STACK 100H
When the program is assembled and loaded in memory, SS will
contain the segment number of the stack segment and SP (stack
pointer) will initialize to 100h. This represents the empty stack
position as shown. When the stack is not empty, SP contains the
offset address of the top of the stack.

The PUSH instruction is used to store the content of a 16-bit register, or memory location, on the
stack. The stack handling instructions are summarized in Table6.1.

Instruction Example Meaning


SP ← SP –2
PUSH PUSH AX [SP] ← AH
[SP-1] ← AL
[NUM1] ← [SP]
POP POP NUM1 [NUM+1] ← [SP-1]
SP ← SP + 2
SP ← SP –2
PUSHF PUSHF [SP] ← MSB(FR)
[SP-1] ← LSB(FR)
LSB(FR) ← [SP]
POPF POPF MSB(FR) ← [SP+1]
SP ← SP + 2
Push AX, CX, DX, BX, original SP,
PUSHA PUSHA BP, SI, and DI

POP AX, CX, DX, BX, original SP,


POPA POPA BP, SI, and DI

EL 213 – Lab 6 Manual Page 2


FAST – NU, Fsd Campus

Table 6.1

Note: FR=Flag Register


Procedure:
A procedure is a set of instructions that compute some value or take some action (such as printing
or reading a character value). Most procedural programming languages implement procedures using the
call/return mechanism. That is, some code calls a procedure, the procedure does its thing, and then the
procedure returns to the caller.
Procedure Declaration:
The syntax of procedure declaration is the following:
procedure name PROC
; Your code for the procedure goes here
RET
procedure name ENDP

The calling code calls a procedure with the CALL instruction, the procedure returns to the caller
with the RET instruction. A simple procedure may consist of nothing more than a sequence of instructions
ending with a ret instruction.
For example the following “procedure” zeros out the 256 bytes starting at the address in the BX register:

ZeroBytes PROC
XOR AX, AX
MOV CX, 128
ZeroLoop:
MOV [BX], AX
ADD BX, 2
LOOP ZeroLoop
RET
ZeroBytes ENDP
The CALL & RET Instruction:
The CALL instruction transfers the flow of the program to the procedure. The CALL instruction
differs from the jump instruction in the sense that a CALL saves a return address on the stack. The RET
instruction return control to the instruction that immediately follows the CALL as shown below.

Passing parameter:
 Two common methods for parameter passing
 Register Method

EL 213 – Lab 6 Manual Page 3


FAST – NU, Fsd Campus

 Stack Method

Arithmetic and Logic Instructions:

INSTRUCTION OPERAND DESCRIPTION


Logical AND between all bits of two
operands. Result is stored in operand1. These
rules apply: 1 AND 1 = 1
REG, memory 1 AND 0 = 0
memory, REG 0 AND 1 = 0
REG, REG 0 AND 0 = 0
AND memory, immediate Example:
REG, immediate MOV AL, 'a' ; AL = 01100001b
AND AL, 11011111b ; AL = 01000001b ('A')

C Z S O P
0 R r 0 r
Invert each bit of the operand. Algorithm:
if bit is 1 turn it to 0.
if bit is 0 turn it to 1.
Example:
REG MOV AL, 00011011b
NOT Memory NOT AL ; AL = 11100100b

C Z S O P
Unchanged
Logical OR between all bits of two operands.
Result is stored in first operand. These rules
apply:
1 OR 1 = 1
1 OR 0 = 1
REG, memory 0 OR 1 = 1
memory, REG
0 OR 0 = 0
REG, REG
OR Example:
memory, immediate MOV AL, 'A' ; AL = 01000001b
REG, immediate OR AL,00100000b

;AL=01100001b('a')

C Z S O P A
0 R r 0 r ?
REG, memory Logical XOR (Exclusive OR) between all bits
memory, REG of two operands. Result is stored in first
XOR REG, REG operand. These rules apply:
memory, immediate 1 XOR 1 = 0
REG, immediate 1 XOR 0 = 1

EL 213 – Lab 6 Manual Page 4


FAST – NU, Fsd Campus

0 XOR 1 = 1
0 XOR 0 = 0
Example:
MOV AL, 00000111b
XOR AL, 00000010b
;AL = 00000101b

C Z S O P A
0 R r 0 r ?
Logical TEST between all bits of two
operands for flags only. These flags are
effected: ZF, SF, PF. Result is not stored
anywhere. These rules apply:
1 TEST 1 = 1
REG, memory 1 TEST 0 = 0
memory, REG 0 TEST 1 = 0
REG, REG 0 TEST 0 = 0
TEST memory, immediate Example:
REG, immediate MOV AL, 00000101b
TEST AL, 1 ;ZF = 0.
TEST AL, 10b ;ZF = 1.

C Z S O P
0 r r 0 r
Table 6.2

Note:
These marks are used to show the state of the flags:
1 - instruction sets this flag to 1.
0 - instruction sets this flag to 0.
r - flag value depends on result of the instruction.
? - flag value is undefined (maybe 1 or 0).

EL 213 – Lab 6 Manual Page 5

You might also like