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

Lab Manual 3

Uploaded by

rumanasif3
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lab Manual 3

Uploaded by

rumanasif3
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Organization and Assembly Language

Lab Manual (Lab 3)

Course Instructor:
Lab Instructor:

Session: Fall 2024

School of Systems and Technology


UMT Lahore Pakistan
Objectives:
 Byte & Word
 iAPX80 & iAPX88 Registers
 Addressing Modes
 Declaring Data in assembly Program

Byte & Word

In assembly language, data is often manipulated in units called bytes and words. A byte consists of
8 bits, while a word is typically 16 bits (or 2 bytes). These are the fundamental units of data, and in-
structions can operate on either, depending on the size of the data to be processed.

 Byte: 8 bits, typically used for smaller data values.


 Word: 16 bits, used for larger data values or operations involving wider data.
 Operations like MOV, ADD, or SUB can work on either byte or word-sized registers.
 The choice between byte and word depends on the required precision and size of the data.

iAPX80 & iAPX88 Registers

The iAPX80 and iAPX88 processors from Intel feature a set of registers that are used for various
tasks, such as arithmetic, data movement, and memory addressing. These registers can be accessed
as 8-bit (byte) or 16-bit (word) units.

 AX, BX, CX, DX: General-purpose registers, which can be used as 16-bit (AX) or split into
two 8-bit registers (AH and AL).
 SI, DI: Source and destination index registers for memory operations.
 Flags Register: Contains flags that reflect the outcome of arithmetic and logic operations.
 IP (Instruction Pointer): Holds the address of the next instruction.

Addressing Modes

Addressing modes in assembly language define how the operands of instructions are accessed. These
modes allow the processor to interpret whether data is in a register, memory, or an immediate value
embedded in the instruction.

 Immediate Addressing: The operand is a constant value embedded directly in the instruction
(e.g., mov ax, 5).
 Direct Addressing: The operand refers to a specific memory location (e.g., mov ax,
[1000h]).
 Register Addressing: Operands are located in registers (e.g., mov ax, bx).
 Indirect Addressing: Memory addresses are indirectly referenced via a register (e.g., mov
ax, [bx]).
Declaring Data in Assembly

In assembly language, data is declared using directives like db (define byte) for 8-bit data and dw
(define word) for 16-bit data. These directives reserve space in memory and initialize it with a spe-
cific value.

 db: Defines an 8-bit value (byte).


 dw: Defines a 16-bit value (word).
 Labels: Used to give a symbolic name to memory locations for easy reference.
 Data can be accessed by using its memory label in instructions.

Sample Programs
1. Byte Register Example (Data Movement and Addition)

This program demonstrates moving byte-sized data between registers using immediate addressing
and performing addition:

[ORG 0x100]
mov al, 5 ; Move 5 into AL (byte-sized)
mov bl, 10 ; Move 10 into BL (byte-sized)
add al, bl ; Add BL to AL, result in AL
mov ah, 0x4C ; Terminate program
int 0x21 ; DOS interrupt

2. Word Register Example (Data Movement and Subtraction)

This program shows moving word-sized data between registers using immediate addressing and per-
forming subtraction:

[ORG 0x100]
mov ax, 1000 ; Move 1000 into AX (word-sized)
mov bx, 500 ; Move 500 into BX (word-sized)
sub ax, bx ; Subtract BX from AX, result in AX
mov ax, 0x4C00 ; Terminate program
int 0x21 ; DOS interrupt
This program shows moving word-sized data between registers and memory using direct addressing
and performing addition:

[ORG 0x100]
mov ax, [Num1] ; move the first number in ax
mov bx, [Num2] ; move the second number in bx
add ax, bx ; add first and second numbers in ax
mov bx, [Num3] ; move the third number in bx
add ax, bx ; add the third number to ax
mov [Num4], ax ; move the sum to location Num4

mov ax, 0x4c00 ; exit from program


int 0x21
; execution never comes at this line

Num1: dw 5
Num2: dw 10
Num3: dw 15
Num4: dw 0

Practice Questions

Write an Assembly Program to Add Four Byte-Sized Numbers


Create a program that loads four byte-sized numbers into registers, adds them one by one, and stores
the result in a register.

Write an Assembly Program to Subtract Two Word-Sized Numbers


Write a program that moves two word-sized numbers into registers, performs a subtraction, and
stores the result in another word register.

Write an Assembly Program to Transfer Data Between Registers and Memory


Create a program that stores a byte in memory, loads it into a register, and transfers it to another
memory location. Similarly, transfer a word-sized value between memory and registers.

You might also like