SlideShare a Scribd company logo
NFC institute of Engineering and
Technology
Computer Organization & Assembly Language
Lab manual
Name: ALI ASAD MUMTAZ
Class: BSSE-B
Roll #: BSSE-2K23-220
Session: 2K23 – 2K27
Subject: Computer Organization & Assembly Language
Professor: Ms. Areej
Table of Contents
Lab 2........................................................................................................................3
Types of programming language..............................................................................3
MOV Instructions......................................................................................................5
Arithmetic instructions.............................................................................................5
Lab 3........................................................................................................................7
ADC (Addition with Carry):.......................................................................................9
SBB (Subtract with Borrow):....................................................................................9
Lab 4......................................................................................................................10
Variable Declaration in EMU8086...........................................................................10
Lab 6......................................................................................................................14
Array declaration in EMU8086................................................................................14
Sum of Arrays.........................................................................................................16
Logical Instructions................................................................................................20
Lab 7......................................................................................................................21
Interrupts...............................................................................................................21
Lab 8......................................................................................................................25
Jump Instructions..................................................................................................25
Lab 9......................................................................................................................29
Loop in assembly language....................................................................................29
Lab 11....................................................................................................................32
Procedures and Functions......................................................................................32
Lab 12....................................................................................................................35
Stack Push POP in assembly language...................................................................35
Lab 13....................................................................................................................39
Bitwise Rotation in Assembly..................................................................................39
Lab 14....................................................................................................................42
SHIFT instructions..................................................................................................42
Lab 15....................................................................................................................45
String Handling and Manipulation...........................................................................45
Lab 16....................................................................................................................48
Interfacing with I/O Ports and External Devices......................................................48
Lab 2
Types of programming language
 Low level language
 High level language
High level language:
 No use of 0, 1
 English like words called mnemonics
 e.g. C ,C++ , Java
Low level language:
Binary (0,1) are used that are difficult to understand or code by
humans.
Types of Low level language:
1. Machine language
 Machine can understand it easily
 0,1 is used
 Difficult to write a program
2. Assembly language
 0,1 and some English words are used
 Translator is used to translate the assemble language
 The translator of assemble language is called assembler
 Assembler converts assembly language to machine
language
Registers:
 Increase speed of CPU
 Allocates space in main memory for data
 Present in processor
Types of registers:
 General purpose registers
 Special registers
General purpose register:
1. AX (accumulator)
2. BX (base)
3. CX (count)
4. DX (destination)
Where X=size in memory.
It can be 8,16,32,64,etc.
Special purpose register:
1. IP
2. IR
3. BP
4. SP
5. SI
6. DI
7. CS
8. DS
9. ES
a=10
b=20
AL AH
lower
higher
8- bit
REGISTER
PROCESSING
ELEMENT
PROCESSOR
10
20
2001
3001
a
b
MAIN
MEMORY
Data bus
MOV Instructions
The MOV instruction copies a word or byte of data from a
specified source to a specified destination. The destination can be
a register or a memory location. The source can be a register, a
memory location or an immediate number. The source and
destination cannot both be memory locations.
Arithmetic instructions
ADD:
Add — Integer Addition. The add instruction adds together its two
operands, storing the result in its first operand. Note, whereas
both operands may be registers, at most one operand may be a
memory location.
SUB:
SUB: Subtract: The subtract instruction subtracts the source
operand from the destination operand and the result is left in the
destination operand. Source operand may be a register or a
memory location, but source and destination operands both must
not be memory operands.
INC:
INC: Increment: This instruction increments the contents of the
specified register or memory location by 1.
DEC:
DEC: Decrement: The decrement instruction subtracts 1 from the
contents of the specified register or memory location.
Lab 3
MUL:
The MUL instruction deals with the multiplication of two unsigned
numbers. By default answer of multiplication is stored in
Accumulator register.
There are types of multiplication depending on the number of bits:
8 bits:
MUL D8*al AX
 Here D8 is any 8 bit number.
 The product of this multiplication is stored in AX i.e. is a 16
bits register.
 Product of 8 bits MUL is a 16 bit number.
16 bits:
MUL D16*al DX, AX
 Here D16 is any 16 bit number.
 The product of this multiplication is stored in AX and DX i.e. is
a 32 bits register if combined.
 Product of 16 bits MUL is a 32 bit number, upper 16 bits are
stored in DX and lower 16 bits are stored in AX.
DIV:
The DIV instruction performs the division of two unsigned
operands. The denominator resides in a source operand and it
should not be immediate. However, it can be register or a memory
location.
The division can be:
8 bits:
DIV AX/D8 where Q AL, R AH
 Here AX is a 16 bits register.
 D8 is 8 bits number.
 Quotient of 8 bits division is stored in AL.
 Remainder of 8 bits division is stored in AH.
16 bits:
DIV (AX, DX)/D16 where Q AX, R DX
 Here AX and DX is a 32 bits register when combined.
 D16 is 16 bits number.
 Quotient of 16 bits division is stored in AX.
 Remainder of 16 bits division is stored in DX.
ADC (Addition with Carry):
The ADC (Add with Carry) instruction in the 8086 microprocessor
is used to add two values together along with the carry flag. This is
particularly useful in multi-byte or multi-word arithmetic
operations, where previous additions may have resulted in a carry
that needs to be accounted for in subsequent calculations.
SBB (Subtract with Borrow):
The SBB (Subtract with Borrow) instruction in the 8086
microprocessor is used to subtract one operand from another,
taking into account the current state of the Carry Flag (CF). This
instruction is particularly useful for multi-byte or multi-word
arithmetic operations where previous subtractions may have
resulted in a borrow that needs to be included in the current
subtraction.
Lab 4
Variable Declaration in EMU8086
What is a Variable?
A variable is a storage location in a program that holds data. It
allows programmers to store, modify, and retrieve values during
program execution.
Types of Variables in EMU8086
Data types:
1. BYTE
2. WORD
3. DWORD
BYTE:
 DB (define byte)
 8 bits
 used to store single byte value
WORD:
 DW (define word)
 16 bits
 used to store 16bit value
Double WORD:
 DD (define double)
 32 bits
 used to store 32 bit (4 bytes) value
Declaring variable
Syntax :
VARIABLE_NAME DATA_TYPE INITIAL_VALUE
Example:
myByte DB 10
myWord DW 1234h
myDword DD 1234567h
model small
 Define memory model
 Program uses single code and data segment , program that
fits in 64kb segment
stack 100h
 Define stack size
data
 Start of data segment
code
 Start of code segment
MOV AX, 4C00h
 4C Terminates the process
 00 Return code/ exit code
 DOS function to exit program (disk operting system)
INT 21h
 int instruction to generate interrupt
 21h DOS interrupt 21h is used to interrupt the program
 Call DOS interrupt
$ is used to indicate the end of the string
MOV AH, 09h
 Sets up the DOS function for displaying/ printing a string
 By placing 09h into the AH register, you're telling DOS that
you want to call the "print string" function.
LEA DX, message
LEA: This stands for "Load Effective Address." It is used to
load the address of a variable (or the offset of a string) into a
register.
DX: This is another register, used for data storage
message: This is the label for the string you declared in
the .DATA segment (e.g., message DB 'Hello, World!', 0).
Basic program of variable declaration:
Add to Variables Program:
Adding two variables:
Variables of same data type can be added only.
Hello World Program:
Lab 6
Array declaration in EMU8086
Definition:
An array is a collection of elements, all of the same type, stored in
contiguous memory locations.
Purpose:
Arrays allow you to manage multiple values efficiently, facilitating
tasks like sorting, searching, and data manipulation.
Types of Arrays in EMU8086:
Byte Array:
 DB (define byte)
 8 bits
WORD Array:
 DW (define word)
 16 bits
 used to store 2 byte/16bit value
Double WORD array:
 DD (define double)
 32 bits
 used to store 32 bit (4 bytes) value
String Array (Characters):
Declaration:
Strings are typically declared as byte arrays with a null
terminator.
e. g. myString DB 'Hello', 0
Declaring Array:
Syntax:
Array_NAME DATA_TYPE value1, value2, value3
Example:
 myBytes DB 10, 20, 30, 40
 myWords DW 1000, 2000, 3000
 myDWords DD 100000, 200000, 300000
Program for array declaration:
Sum of Arrays
MOV CX, 5:
Loads the number of elements in the array (5) into the CX register.
CX is used as a loop counter.
LEA SI, myBytes:
Loads the effective address of the myBytes array into the SI
(Source Index) register. SI will be used to point to the current
element of the array as we iterate through it.
sum_loop:
This is the label marking the beginning of the summing loop.
INC SI:
Increments the SI register to point to the next byte in the array.
Since each element is 1 byte, this moves SI to the next element.
LOOP sum_loop:
Decrements CX and repeats the loop if CX is not zero. This means
the loop will continue until we have summed all five elements of
the array.
CALL PrintNumber:
Calls the PrintNumber procedure to print the sum.
PrintNumber PROC:
Marks the beginning of the PrintNumber procedure.
ADD AL, '0':
Converts the numeric value in AL to its ASCII equivalent. Since we
are dealing with single-digit sums (0-9), this conversion works
correctly.
RET:
Returns from the PrintNumber procedure.
Sum of Byte type array:
Sum of WORD type array:
Sum of Double WORD type array:
Logical Instructions
Logical instructions perform bitwise operations on binary
data.
Common logical instructions:
AND instruction
OR instruction
XOR instruction
NOT instruction:
Lab 7
Interrupts
What are Interrupts?
Interrupts are signals to the processor emitted by hardware or
software indicating an event that needs immediate attention.
When the CPU receives an interrupt, it temporarily halts its
current execution and jumps to a specific routine (the interrupt
handler) to address the event. After handling the interrupt, the
CPU resumes its previous task.
Types of Interrupts
Hardware Interrupts:
Triggered by hardware devices (like keyboards, mice, timers).
They usually indicate an event like a key press or a completed I/O
operation.
Software Interrupts:
Triggered by software instructions (like the INT instruction).
Commonly used to request services from the operating system.
Interrupts in EMU8086
Here are some common interrupts and their functions
INT 21h:
DOS services (like file operations, keyboard input).
INT 10h:
Video services (like screen output, mode setting).
INT 16h:
Keyboard services (like reading key input).
Program for int 21h:
Program for int 10h:
INT 10h:
 Calls the BIOS interrupt 10h, which handles video services.
This sets the specified video mode.
 Calls the BIOS interrupt 10h to execute the printing function.
The character in AL is displayed on the screen.
MOV AX, 0003h:
Prepares to set the video mode. The value 0003h specifies the
80x25 text mode, which is the standard text display.
MOV AH, 0Eh:
Sets AH to 0Eh, which indicates the function to print a character in
teletype mode (meaning it will display the character and move the
cursor).
computer organization and assembly language.docx
Program for int 16h:
INT 16h:
Set Video Mode:
MOV AX, 0003h: Sets the video mode to 80x25 text.
INT 10h: Calls the BIOS interrupt to apply the video mode.
Read Key Press:
MOV AH, 01h: Prepares to read a character from the
keyboard.
INT 16h: Waits for a key press and stores the character in AL.
Display Character:
MOV AH, 0Eh: Sets up to print a character.
INT 10h: Displays the character stored in AL.
Lab 8
Jump Instructions
Purpose:
The JUMP instruction allows you to move to a different part of the
code. This is essential for implementing loops, conditionals, and
other control flow structures
Types:
1. Unconditional Jumps:
Syntax:
JMP label
Description:
Transfers control to the specified label, regardless of any
conditions.
Example:
JMP start (Jump to the label 'start')
2. Conditional Jumps:
These jumps occur based on the status of flags set by comparison
instructions.
Common Conditional Jump Instructions:
• JE / JZ: Jump if Equal / Zero
• JNE / JNZ: Jump if Not Equal / Not Zero
• JG / JNBE: Jump if Greater / Not Below or Equal
• JL / JNGE: Jump if Less / Not Greater or Equal
• JGE / JNL: Jump if Greater or Equal / Not Less
• JLE / JNG: Jump if Less or Equal / Not Greater
• JA / JBE: Jump if Above / Below or Equal
• JB / JAE: Jump if Below / Above or Equal
Unconditional jumps:
Conditional Jumps:
computer organization and assembly language.docx
Looping:
• LOOP:
Decreases CX and jumps if CX is not zero.
• LOOPZ/LOOPE:
Loops while ZF is set (zero flag).
• LOOPNZ/LOOPNE:
Loops while ZF is not set (not zero).
computer organization and assembly language.docx
Lab 9
Loop in assembly language
What is Loop?
A statement or set of statement that is executed repeatedly is
known loop
Set of instruction that is repeated until a terminating condition is
reached is called loop
The structure that repeats a statement is known as iterative or
looping construct
Syntax
Label Name:
Statement
Loop Label Name Where Call Loop
Example
test:
mov ah,2
int 21h
loop test
Label is placed at the beginning of a loop statement
Label name must not be a reserved word like mov, add, AX,DB
Test is label name in this example
CX register
CX register is used for loop value.
CX register acts as a counter for repetition or loops.
CX register used in looping.
Factorial loop:
String reversal:
Even sum
computer organization and assembly language.docx
Lab 11
Procedures and Functions
What is a Procedure?
A block of code that performs a specific task.
Does not return a value.
Example use case: Code reuse for common tasks.
What is a Function?
Similar to a procedure, but it returns a value.
Can be used for calculations or to perform tasks that require a
return value.
Why we use Procedure?
.Easy to write program
.Reusability
.Reduce complicity
.Eliminate duplicate code
Syntax
Procedure_name proc
----------
----------
Ret
Procedure_name proc
CALL Instruction
Used to invoke a procedure or function.
Control is transferred to the procedure/function.
RET Instruction
Used to return control to the caller.
Can return a value if it's a function.
Using Local Variables in Procedures
What are Local Variables?
Variables defined within a procedure or function.
Scope is limited to that procedure/function.
How to Use Local Variables:
Typically stored on the stack.
Recursive Functions
What is Recursion?
A function that calls itself.
Requires a base case to prevent infinite loops.
Addition Procedure:
Printing Procedure:
New line Procedure:
Lab 12
Stack Push POP in assembly language
Stack:
Stack is an area of memory for keeping temporary data.
Stack is used by CALL instruction to keep return address for
procedure, RET instruction gets this value from the stack and
returns to that offset.
There are two instructions that work with the stack:
PUSH - stores 16 bit value in the stack.
POP - gets 16 bit value from the stack.
Push Instruction Syntax
Syntax for PUSH instruction:
PUSH REG
PUSH SREG
PUSH memory
PUSH immediate
REG: AX, BX, CX, DX, DI, SI, BP, SP.
SREG: DS, ES, SS, CS.
memory: [BX], [BX+SI+7], 16 bit variable, etc...
immediate: 5, -24, 3Fh, 10001101b, etc...
Pop Instruction Syntax
Syntax for POP instruction:
POP REG
POP SREG
POP memory
REG: AX, BX, CX, DX, DI, SI, BP, SP.
SREG: DS, ES, SS, (except CS).
memory: [BX], [BX+SI+7], 16 bit variable, etc...
PUSH and POP work with 16 bit values only!
The stack uses LIFO (Last In First Out) algorithm,
this means that if we push these values one by one into the stack:
1, 2, 3, 4, 5
the first value that we will get on pop will be 5, then 4, 3, 2, and
only then 1.
Operation of Stack
Program#1
Program#2
Program#3
Program#4
computer organization and assembly language.docx
Lab 13
Bitwise Rotation in Assembly
What is Bitwise Rotation?
Bitwise rotation involves shifting the bits of a binary number
around in a circular manner. That is, when a bit is shifted out of
one end, it is placed back on the other end (opposite side).
In a rotation, the bit that "falls off" the end of the operand is not
discarded. Instead, it gets placed back into the opposite end,
potentially affecting the Carry Flag (CF) in the process.
ROL - Rotate Left
In the ROL (Rotate Left) operation:
Each bit is shifted one position to the left.
The most significant bit (MSB), which falls off the left side, is
moved into the least significant bit (LSB) position.
The Carry Flag (CF) is updated with the bit that was shifted out of
the MSB.
ROR - Rotate Right
In the ROR (Rotate Right) operation:
Each bit is shifted one position to the right.
The least significant bit (LSB), which falls off the right side, is
moved into the most significant bit (MSB) position.
The Carry Flag (CF) is updated with the bit that was shifted out of
the LSB.
What is RCL?
The RCL (Rotate through Carry Left):
Instruction rotates the bits of a register or memory operand left
while also shifting the Carry Flag (CF) into the least significant bit
(LSB) of the operand.
What is RCR?
The RCR (Rotate through Carry Right)
Instruction rotates the bits of a register or memory operand right,
while also rotating the Carry Flag (CF) into the most significant bit
(MSB) of the operand, and the least significant bit (LSB) of the
operand is shifted into CF.
ROL instruction:
ROR instruction:
RCR instruction:
RCL instruction:
Lab 14
SHIFT instructions
Shift Instructions in EMU8086 Assembly
The 8086 processor provides several shift instructions for
manipulating the bits in registers and memory.
These instructions are primarily used for multiplying or dividing
values by powers of two and for bit-level manipulations.
SHL (Shift Left)
The SHL instruction shifts the bits of a register or memory
operand to the left. A left shift operation essentially multiplies the
operand by a power of 2.
Syntax:
SHL destination, count
The SHL instruction works by shifting all bits to the left, inserting
zeros in the vacated positions on the right. The bits that are
shifted out of the leftmost position are stored in the Carry Flag
(CF).
SHR (Shift Right)
The SHR instruction shifts the bits of a register or memory
operand to the right. A right shift operation divides the operand by
a power of 2. This instruction is typically used for unsigned values.
Syntax:
SHR destination, count
The SHR instruction works by shifting all bits to the right, inserting
zeros in the vacated positions on the left. The bits shifted out from
the rightmost side are stored in the Carry Flag (CF).
SAL (Shift Arithmetic Left)
The SAL instruction is functionally identical to SHL. It performs a
left shift, and the result is the same as multiplying the operand by
powers of two.
Syntax:
SAL destination, count
SAR (Shift Arithmetic Right)
The SAR instruction is used for an arithmetic right shift. This
instruction works similarly to SHR, but it preserves the sign bit
(most significant bit) when shifting. It is used to divide signed
numbers by powers of 2.
Syntax:
SAR destination, count
In an arithmetic right shift, the leftmost bit (sign bit) is preserved,
so it works correctly for signed numbers in two's complement.
Lab 15
String Handling and Manipulation
Key String Instructions:
MOVS - Move a Byte/Word from Source to
Destination
The MOVS instruction is used to move a byte or word from the
source (pointed by SI or ES:DI) to the destination (pointed by DI or
SI).
Syntax: MOVS destination, source
Usage: It can transfer data in blocks (byte or word), and it works
in conjunction with the SI (source index) and DI (destination index)
registers.
Example: Copying a String
LODS: Load a Byte/Word from Source into the
Accumulator
The LODS instruction loads a byte or word from the source
address (pointed by SI) into the accumulator (AL or AX).
Syntax: LODS AL | AX, [SI]
Usage: LODS is useful for reading or loading characters from a
string.
Example: Reading a Character from a String
STOS: Store the Accumulator Content into Memory
The STOS instruction stores the contents of the accumulator into
a memory location (pointed by DI), then increments DI.
Syntax: STOS AL | AX, [DI]
Usage: It’s used to store a byte or word (in AL or AX) to memory.
Example: Storing a Character to Memory
CMPS: Compare Two Strings
The CMPS instruction compares two strings byte by byte.
Syntax: CMPS destination, source
Usage: This is typically used to compare the byte or word at the
memory locations pointed by SI and DI.
Example: Comparing Two Strings
SCAS: Scan a String for a Byte or Word
The SCAS instruction compares a byte or word in the accumulator
to the string pointed by DI.
Syntax: SCAS AL | AX, [DI]
Usage: It’s used to scan a string for a specific byte or word. If a
match is found, ZF will be set.
Example: Searching for a Character in a String
Lab 16
Interfacing with I/O Ports and External Devices
Introduction to I/O Ports
What are I/O Ports?
8086 I/O ports are used to communicate with external devices
such as keyboards, printers, display screens, and other hardware.
These ports are locations in the computer's memory-mapped I/O
space or an address range where the CPU can send or receive
data from hardware components.
Ports are usually addressed by a 16-bit value (0x0000 to 0xFFFF in
the x86 architecture), and the CPU can either write data to a port
or read data from it.The 8086 processor uses IN and OUT
instructions for reading from and writing to I/O ports.
Common I/O port addresses:
0x60: Keyboard data register (used for input from the keyboard).
0x378: LPT1 (parallel port), used for printers.
0x3F8: COM1 (serial port).
Port range:
Ports range from 0 to 65535, and can be configured to interface
with devices like keyboards, displays, sensors, and more.
I/O Communication:
OUT sends data from the CPU to an I/O port.
IN reads data from an I/O port into the CPU.
How to Access I/O Ports in Assembly:
In assembly language, you access I/O ports using the IN and OUT
instructions, specifying the port address in the dx register and the
data in the al, ax, or dx register depending on the size of data
(byte, word, etc.)
Example of Outputting Data to an External
Device
Sending Data to a Printer.
0x378:
0x60:
computer organization and assembly language.docx
Ad

More Related Content

Similar to computer organization and assembly language.docx (20)

Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
Urvashi Singh
 
Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Introduction of 8086 micro processor .
Introduction of 8086 micro processor .
Siraj Ahmed
 
Highridge ISA
Highridge ISAHighridge ISA
Highridge ISA
Alec Selfridge
 
Module 3 Computer Organization Data Hazards.pptx
Module 3 Computer Organization Data Hazards.pptxModule 3 Computer Organization Data Hazards.pptx
Module 3 Computer Organization Data Hazards.pptx
earningmoney9595
 
Alp 05
Alp 05Alp 05
Alp 05
gswapnil86
 
Alp 05
Alp 05Alp 05
Alp 05
Murali Krishna
 
15CS44 MP & MC Module 2
15CS44 MP & MC Module  215CS44 MP & MC Module  2
15CS44 MP & MC Module 2
RLJIT
 
BISWAJIT ADHIKARI_28101623024_PC EE 602.pdf
BISWAJIT ADHIKARI_28101623024_PC EE 602.pdfBISWAJIT ADHIKARI_28101623024_PC EE 602.pdf
BISWAJIT ADHIKARI_28101623024_PC EE 602.pdf
BiswajitAdhikari6
 
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENTUNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
KavithaNagendran1
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
Ahmed M. Abed
 
Different addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessorDifferent addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessor
Daffodil International University
 
report-MICRO-P (2).pptx
report-MICRO-P (2).pptxreport-MICRO-P (2).pptx
report-MICRO-P (2).pptx
JohnbenetteTarrobago
 
Lect05 Prog Model
Lect05 Prog ModelLect05 Prog Model
Lect05 Prog Model
anoosdomain
 
other-architectures.ppt
other-architectures.pptother-architectures.ppt
other-architectures.ppt
Jaya Chavan
 
Chapter 5 notes
Chapter 5 notesChapter 5 notes
Chapter 5 notes
HarshitParkar6677
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
The reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memoryThe reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memory
PVS-Studio
 
Lecture9
Lecture9Lecture9
Lecture9
misgina Mengesha
 
outline : basicc elements of assembly language
outline : basicc elements of assembly languageoutline : basicc elements of assembly language
outline : basicc elements of assembly language
rivadiab30663
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
Tirumalesh Nizampatnam
 
Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086Assembler directives and basic steps ALP of 8086
Assembler directives and basic steps ALP of 8086
Urvashi Singh
 
Introduction of 8086 micro processor .
Introduction of 8086 micro processor .Introduction of 8086 micro processor .
Introduction of 8086 micro processor .
Siraj Ahmed
 
Module 3 Computer Organization Data Hazards.pptx
Module 3 Computer Organization Data Hazards.pptxModule 3 Computer Organization Data Hazards.pptx
Module 3 Computer Organization Data Hazards.pptx
earningmoney9595
 
15CS44 MP & MC Module 2
15CS44 MP & MC Module  215CS44 MP & MC Module  2
15CS44 MP & MC Module 2
RLJIT
 
BISWAJIT ADHIKARI_28101623024_PC EE 602.pdf
BISWAJIT ADHIKARI_28101623024_PC EE 602.pdfBISWAJIT ADHIKARI_28101623024_PC EE 602.pdf
BISWAJIT ADHIKARI_28101623024_PC EE 602.pdf
BiswajitAdhikari6
 
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENTUNIT IV Compiler.pptx RUNTIMEENVIRONMENT
UNIT IV Compiler.pptx RUNTIMEENVIRONMENT
KavithaNagendran1
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
Ahmed M. Abed
 
Lect05 Prog Model
Lect05 Prog ModelLect05 Prog Model
Lect05 Prog Model
anoosdomain
 
other-architectures.ppt
other-architectures.pptother-architectures.ppt
other-architectures.ppt
Jaya Chavan
 
Chapter 2 programming concepts - I
Chapter 2  programming concepts - IChapter 2  programming concepts - I
Chapter 2 programming concepts - I
SHREEHARI WADAWADAGI
 
The reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memoryThe reasons why 64-bit programs require more stack memory
The reasons why 64-bit programs require more stack memory
PVS-Studio
 
outline : basicc elements of assembly language
outline : basicc elements of assembly languageoutline : basicc elements of assembly language
outline : basicc elements of assembly language
rivadiab30663
 

Recently uploaded (20)

Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
How iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost FundsHow iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost Funds
ireneschmid345
 
03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia03 Daniel 2-notes.ppt seminario escatologia
03 Daniel 2-notes.ppt seminario escatologia
Alexander Romero Arosquipa
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
Defense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptxDefense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptx
Greg Makowski
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
Simple_AI_Explanation_English somplr.pptx
Simple_AI_Explanation_English somplr.pptxSimple_AI_Explanation_English somplr.pptx
Simple_AI_Explanation_English somplr.pptx
ssuser2aa19f
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Classification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptxClassification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptx
wencyjorda88
 
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
James Francis Paradigm Asset Management
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.pptJust-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
ssuser5f8f49
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
DPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdfDPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdf
inmishra17121973
 
IAS-slides2-ia-aaaaaaaaaaain-business.pdf
IAS-slides2-ia-aaaaaaaaaaain-business.pdfIAS-slides2-ia-aaaaaaaaaaain-business.pdf
IAS-slides2-ia-aaaaaaaaaaain-business.pdf
mcgardenlevi9
 
AI Competitor Analysis: How to Monitor and Outperform Your Competitors
AI Competitor Analysis: How to Monitor and Outperform Your CompetitorsAI Competitor Analysis: How to Monitor and Outperform Your Competitors
AI Competitor Analysis: How to Monitor and Outperform Your Competitors
Contify
 
Medical Dataset including visualizations
Medical Dataset including visualizationsMedical Dataset including visualizations
Medical Dataset including visualizations
vishrut8750588758
 
Data Science Courses in India iim skills
Data Science Courses in India iim skillsData Science Courses in India iim skills
Data Science Courses in India iim skills
dharnathakur29
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
How iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost FundsHow iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost Funds
ireneschmid345
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
Defense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptxDefense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptx
Greg Makowski
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
Simple_AI_Explanation_English somplr.pptx
Simple_AI_Explanation_English somplr.pptxSimple_AI_Explanation_English somplr.pptx
Simple_AI_Explanation_English somplr.pptx
ssuser2aa19f
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Classification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptxClassification_in_Machinee_Learning.pptx
Classification_in_Machinee_Learning.pptx
wencyjorda88
 
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
James Francis Paradigm Asset Management
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.pptJust-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
Just-In-Timeasdfffffffghhhhhhhhhhj Systems.ppt
ssuser5f8f49
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
Deloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit contextDeloitte Analytics - Applying Process Mining in an audit context
Deloitte Analytics - Applying Process Mining in an audit context
Process mining Evangelist
 
DPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdfDPR_Expert_Recruitment_notice_Revised.pdf
DPR_Expert_Recruitment_notice_Revised.pdf
inmishra17121973
 
IAS-slides2-ia-aaaaaaaaaaain-business.pdf
IAS-slides2-ia-aaaaaaaaaaain-business.pdfIAS-slides2-ia-aaaaaaaaaaain-business.pdf
IAS-slides2-ia-aaaaaaaaaaain-business.pdf
mcgardenlevi9
 
AI Competitor Analysis: How to Monitor and Outperform Your Competitors
AI Competitor Analysis: How to Monitor and Outperform Your CompetitorsAI Competitor Analysis: How to Monitor and Outperform Your Competitors
AI Competitor Analysis: How to Monitor and Outperform Your Competitors
Contify
 
Medical Dataset including visualizations
Medical Dataset including visualizationsMedical Dataset including visualizations
Medical Dataset including visualizations
vishrut8750588758
 
Data Science Courses in India iim skills
Data Science Courses in India iim skillsData Science Courses in India iim skills
Data Science Courses in India iim skills
dharnathakur29
 
Ad

computer organization and assembly language.docx

  • 1. NFC institute of Engineering and Technology Computer Organization & Assembly Language Lab manual Name: ALI ASAD MUMTAZ Class: BSSE-B Roll #: BSSE-2K23-220 Session: 2K23 – 2K27 Subject: Computer Organization & Assembly Language Professor: Ms. Areej
  • 2. Table of Contents Lab 2........................................................................................................................3 Types of programming language..............................................................................3 MOV Instructions......................................................................................................5 Arithmetic instructions.............................................................................................5 Lab 3........................................................................................................................7 ADC (Addition with Carry):.......................................................................................9 SBB (Subtract with Borrow):....................................................................................9 Lab 4......................................................................................................................10 Variable Declaration in EMU8086...........................................................................10 Lab 6......................................................................................................................14 Array declaration in EMU8086................................................................................14 Sum of Arrays.........................................................................................................16 Logical Instructions................................................................................................20 Lab 7......................................................................................................................21 Interrupts...............................................................................................................21 Lab 8......................................................................................................................25 Jump Instructions..................................................................................................25 Lab 9......................................................................................................................29 Loop in assembly language....................................................................................29 Lab 11....................................................................................................................32 Procedures and Functions......................................................................................32 Lab 12....................................................................................................................35 Stack Push POP in assembly language...................................................................35 Lab 13....................................................................................................................39 Bitwise Rotation in Assembly..................................................................................39 Lab 14....................................................................................................................42 SHIFT instructions..................................................................................................42 Lab 15....................................................................................................................45 String Handling and Manipulation...........................................................................45 Lab 16....................................................................................................................48 Interfacing with I/O Ports and External Devices......................................................48
  • 3. Lab 2 Types of programming language  Low level language  High level language High level language:  No use of 0, 1  English like words called mnemonics  e.g. C ,C++ , Java Low level language: Binary (0,1) are used that are difficult to understand or code by humans. Types of Low level language: 1. Machine language  Machine can understand it easily  0,1 is used  Difficult to write a program 2. Assembly language  0,1 and some English words are used  Translator is used to translate the assemble language  The translator of assemble language is called assembler  Assembler converts assembly language to machine language Registers:  Increase speed of CPU  Allocates space in main memory for data  Present in processor Types of registers:  General purpose registers  Special registers
  • 4. General purpose register: 1. AX (accumulator) 2. BX (base) 3. CX (count) 4. DX (destination) Where X=size in memory. It can be 8,16,32,64,etc. Special purpose register: 1. IP 2. IR 3. BP 4. SP 5. SI 6. DI 7. CS 8. DS 9. ES a=10 b=20 AL AH lower higher 8- bit REGISTER PROCESSING ELEMENT PROCESSOR 10 20 2001 3001 a b MAIN MEMORY Data bus
  • 5. MOV Instructions The MOV instruction copies a word or byte of data from a specified source to a specified destination. The destination can be a register or a memory location. The source can be a register, a memory location or an immediate number. The source and destination cannot both be memory locations. Arithmetic instructions ADD: Add — Integer Addition. The add instruction adds together its two operands, storing the result in its first operand. Note, whereas both operands may be registers, at most one operand may be a memory location.
  • 6. SUB: SUB: Subtract: The subtract instruction subtracts the source operand from the destination operand and the result is left in the destination operand. Source operand may be a register or a memory location, but source and destination operands both must not be memory operands. INC: INC: Increment: This instruction increments the contents of the specified register or memory location by 1. DEC: DEC: Decrement: The decrement instruction subtracts 1 from the contents of the specified register or memory location.
  • 7. Lab 3 MUL: The MUL instruction deals with the multiplication of two unsigned numbers. By default answer of multiplication is stored in Accumulator register. There are types of multiplication depending on the number of bits: 8 bits: MUL D8*al AX  Here D8 is any 8 bit number.  The product of this multiplication is stored in AX i.e. is a 16 bits register.  Product of 8 bits MUL is a 16 bit number. 16 bits: MUL D16*al DX, AX  Here D16 is any 16 bit number.  The product of this multiplication is stored in AX and DX i.e. is a 32 bits register if combined.
  • 8.  Product of 16 bits MUL is a 32 bit number, upper 16 bits are stored in DX and lower 16 bits are stored in AX. DIV: The DIV instruction performs the division of two unsigned operands. The denominator resides in a source operand and it should not be immediate. However, it can be register or a memory location. The division can be: 8 bits: DIV AX/D8 where Q AL, R AH  Here AX is a 16 bits register.  D8 is 8 bits number.  Quotient of 8 bits division is stored in AL.  Remainder of 8 bits division is stored in AH. 16 bits: DIV (AX, DX)/D16 where Q AX, R DX  Here AX and DX is a 32 bits register when combined.  D16 is 16 bits number.
  • 9.  Quotient of 16 bits division is stored in AX.  Remainder of 16 bits division is stored in DX. ADC (Addition with Carry): The ADC (Add with Carry) instruction in the 8086 microprocessor is used to add two values together along with the carry flag. This is particularly useful in multi-byte or multi-word arithmetic operations, where previous additions may have resulted in a carry that needs to be accounted for in subsequent calculations. SBB (Subtract with Borrow): The SBB (Subtract with Borrow) instruction in the 8086 microprocessor is used to subtract one operand from another, taking into account the current state of the Carry Flag (CF). This instruction is particularly useful for multi-byte or multi-word arithmetic operations where previous subtractions may have
  • 10. resulted in a borrow that needs to be included in the current subtraction. Lab 4 Variable Declaration in EMU8086 What is a Variable? A variable is a storage location in a program that holds data. It allows programmers to store, modify, and retrieve values during program execution. Types of Variables in EMU8086 Data types: 1. BYTE 2. WORD 3. DWORD BYTE:  DB (define byte)  8 bits  used to store single byte value WORD:  DW (define word)  16 bits
  • 11.  used to store 16bit value Double WORD:  DD (define double)  32 bits  used to store 32 bit (4 bytes) value Declaring variable Syntax : VARIABLE_NAME DATA_TYPE INITIAL_VALUE Example: myByte DB 10 myWord DW 1234h myDword DD 1234567h model small  Define memory model  Program uses single code and data segment , program that fits in 64kb segment stack 100h  Define stack size data  Start of data segment code  Start of code segment MOV AX, 4C00h  4C Terminates the process  00 Return code/ exit code  DOS function to exit program (disk operting system) INT 21h  int instruction to generate interrupt  21h DOS interrupt 21h is used to interrupt the program
  • 12.  Call DOS interrupt $ is used to indicate the end of the string MOV AH, 09h  Sets up the DOS function for displaying/ printing a string  By placing 09h into the AH register, you're telling DOS that you want to call the "print string" function. LEA DX, message LEA: This stands for "Load Effective Address." It is used to load the address of a variable (or the offset of a string) into a register. DX: This is another register, used for data storage message: This is the label for the string you declared in the .DATA segment (e.g., message DB 'Hello, World!', 0). Basic program of variable declaration: Add to Variables Program:
  • 13. Adding two variables: Variables of same data type can be added only. Hello World Program:
  • 14. Lab 6 Array declaration in EMU8086 Definition: An array is a collection of elements, all of the same type, stored in contiguous memory locations. Purpose: Arrays allow you to manage multiple values efficiently, facilitating tasks like sorting, searching, and data manipulation. Types of Arrays in EMU8086: Byte Array:  DB (define byte)  8 bits WORD Array:  DW (define word)  16 bits  used to store 2 byte/16bit value Double WORD array:  DD (define double)  32 bits  used to store 32 bit (4 bytes) value
  • 15. String Array (Characters): Declaration: Strings are typically declared as byte arrays with a null terminator. e. g. myString DB 'Hello', 0 Declaring Array: Syntax: Array_NAME DATA_TYPE value1, value2, value3 Example:  myBytes DB 10, 20, 30, 40  myWords DW 1000, 2000, 3000  myDWords DD 100000, 200000, 300000 Program for array declaration:
  • 16. Sum of Arrays MOV CX, 5: Loads the number of elements in the array (5) into the CX register. CX is used as a loop counter. LEA SI, myBytes: Loads the effective address of the myBytes array into the SI (Source Index) register. SI will be used to point to the current element of the array as we iterate through it.
  • 17. sum_loop: This is the label marking the beginning of the summing loop. INC SI: Increments the SI register to point to the next byte in the array. Since each element is 1 byte, this moves SI to the next element. LOOP sum_loop: Decrements CX and repeats the loop if CX is not zero. This means the loop will continue until we have summed all five elements of the array. CALL PrintNumber: Calls the PrintNumber procedure to print the sum. PrintNumber PROC: Marks the beginning of the PrintNumber procedure. ADD AL, '0': Converts the numeric value in AL to its ASCII equivalent. Since we are dealing with single-digit sums (0-9), this conversion works correctly. RET: Returns from the PrintNumber procedure. Sum of Byte type array:
  • 18. Sum of WORD type array:
  • 19. Sum of Double WORD type array:
  • 20. Logical Instructions Logical instructions perform bitwise operations on binary data.
  • 21. Common logical instructions: AND instruction OR instruction XOR instruction NOT instruction:
  • 22. Lab 7 Interrupts What are Interrupts? Interrupts are signals to the processor emitted by hardware or software indicating an event that needs immediate attention. When the CPU receives an interrupt, it temporarily halts its current execution and jumps to a specific routine (the interrupt handler) to address the event. After handling the interrupt, the CPU resumes its previous task. Types of Interrupts Hardware Interrupts: Triggered by hardware devices (like keyboards, mice, timers). They usually indicate an event like a key press or a completed I/O operation. Software Interrupts: Triggered by software instructions (like the INT instruction). Commonly used to request services from the operating system. Interrupts in EMU8086 Here are some common interrupts and their functions INT 21h: DOS services (like file operations, keyboard input). INT 10h: Video services (like screen output, mode setting). INT 16h: Keyboard services (like reading key input).
  • 23. Program for int 21h: Program for int 10h: INT 10h:  Calls the BIOS interrupt 10h, which handles video services. This sets the specified video mode.  Calls the BIOS interrupt 10h to execute the printing function. The character in AL is displayed on the screen. MOV AX, 0003h: Prepares to set the video mode. The value 0003h specifies the 80x25 text mode, which is the standard text display. MOV AH, 0Eh: Sets AH to 0Eh, which indicates the function to print a character in teletype mode (meaning it will display the character and move the cursor).
  • 25. Program for int 16h: INT 16h: Set Video Mode: MOV AX, 0003h: Sets the video mode to 80x25 text. INT 10h: Calls the BIOS interrupt to apply the video mode. Read Key Press: MOV AH, 01h: Prepares to read a character from the keyboard. INT 16h: Waits for a key press and stores the character in AL. Display Character: MOV AH, 0Eh: Sets up to print a character. INT 10h: Displays the character stored in AL.
  • 26. Lab 8 Jump Instructions Purpose: The JUMP instruction allows you to move to a different part of the code. This is essential for implementing loops, conditionals, and other control flow structures Types: 1. Unconditional Jumps: Syntax: JMP label Description: Transfers control to the specified label, regardless of any conditions. Example: JMP start (Jump to the label 'start') 2. Conditional Jumps: These jumps occur based on the status of flags set by comparison instructions. Common Conditional Jump Instructions: • JE / JZ: Jump if Equal / Zero • JNE / JNZ: Jump if Not Equal / Not Zero • JG / JNBE: Jump if Greater / Not Below or Equal • JL / JNGE: Jump if Less / Not Greater or Equal • JGE / JNL: Jump if Greater or Equal / Not Less • JLE / JNG: Jump if Less or Equal / Not Greater • JA / JBE: Jump if Above / Below or Equal
  • 27. • JB / JAE: Jump if Below / Above or Equal Unconditional jumps: Conditional Jumps:
  • 29. Looping: • LOOP: Decreases CX and jumps if CX is not zero. • LOOPZ/LOOPE: Loops while ZF is set (zero flag). • LOOPNZ/LOOPNE: Loops while ZF is not set (not zero).
  • 31. Lab 9 Loop in assembly language What is Loop? A statement or set of statement that is executed repeatedly is known loop Set of instruction that is repeated until a terminating condition is reached is called loop The structure that repeats a statement is known as iterative or looping construct Syntax Label Name: Statement Loop Label Name Where Call Loop Example test: mov ah,2 int 21h loop test Label is placed at the beginning of a loop statement Label name must not be a reserved word like mov, add, AX,DB Test is label name in this example CX register
  • 32. CX register is used for loop value. CX register acts as a counter for repetition or loops. CX register used in looping. Factorial loop: String reversal:
  • 35. Lab 11 Procedures and Functions What is a Procedure? A block of code that performs a specific task. Does not return a value. Example use case: Code reuse for common tasks. What is a Function? Similar to a procedure, but it returns a value. Can be used for calculations or to perform tasks that require a return value. Why we use Procedure? .Easy to write program .Reusability .Reduce complicity .Eliminate duplicate code Syntax Procedure_name proc ---------- ---------- Ret Procedure_name proc CALL Instruction Used to invoke a procedure or function. Control is transferred to the procedure/function. RET Instruction Used to return control to the caller. Can return a value if it's a function.
  • 36. Using Local Variables in Procedures What are Local Variables? Variables defined within a procedure or function. Scope is limited to that procedure/function. How to Use Local Variables: Typically stored on the stack. Recursive Functions What is Recursion? A function that calls itself. Requires a base case to prevent infinite loops. Addition Procedure:
  • 38. Lab 12 Stack Push POP in assembly language Stack: Stack is an area of memory for keeping temporary data. Stack is used by CALL instruction to keep return address for procedure, RET instruction gets this value from the stack and returns to that offset. There are two instructions that work with the stack: PUSH - stores 16 bit value in the stack. POP - gets 16 bit value from the stack. Push Instruction Syntax Syntax for PUSH instruction: PUSH REG PUSH SREG PUSH memory PUSH immediate REG: AX, BX, CX, DX, DI, SI, BP, SP. SREG: DS, ES, SS, CS. memory: [BX], [BX+SI+7], 16 bit variable, etc... immediate: 5, -24, 3Fh, 10001101b, etc... Pop Instruction Syntax Syntax for POP instruction: POP REG POP SREG POP memory REG: AX, BX, CX, DX, DI, SI, BP, SP. SREG: DS, ES, SS, (except CS). memory: [BX], [BX+SI+7], 16 bit variable, etc...
  • 39. PUSH and POP work with 16 bit values only! The stack uses LIFO (Last In First Out) algorithm, this means that if we push these values one by one into the stack: 1, 2, 3, 4, 5 the first value that we will get on pop will be 5, then 4, 3, 2, and only then 1. Operation of Stack Program#1
  • 43. Lab 13 Bitwise Rotation in Assembly What is Bitwise Rotation? Bitwise rotation involves shifting the bits of a binary number around in a circular manner. That is, when a bit is shifted out of one end, it is placed back on the other end (opposite side). In a rotation, the bit that "falls off" the end of the operand is not discarded. Instead, it gets placed back into the opposite end, potentially affecting the Carry Flag (CF) in the process. ROL - Rotate Left In the ROL (Rotate Left) operation: Each bit is shifted one position to the left. The most significant bit (MSB), which falls off the left side, is moved into the least significant bit (LSB) position. The Carry Flag (CF) is updated with the bit that was shifted out of the MSB. ROR - Rotate Right In the ROR (Rotate Right) operation: Each bit is shifted one position to the right. The least significant bit (LSB), which falls off the right side, is moved into the most significant bit (MSB) position. The Carry Flag (CF) is updated with the bit that was shifted out of the LSB. What is RCL? The RCL (Rotate through Carry Left): Instruction rotates the bits of a register or memory operand left while also shifting the Carry Flag (CF) into the least significant bit (LSB) of the operand. What is RCR? The RCR (Rotate through Carry Right)
  • 44. Instruction rotates the bits of a register or memory operand right, while also rotating the Carry Flag (CF) into the most significant bit (MSB) of the operand, and the least significant bit (LSB) of the operand is shifted into CF. ROL instruction: ROR instruction:
  • 46. RCL instruction: Lab 14 SHIFT instructions Shift Instructions in EMU8086 Assembly The 8086 processor provides several shift instructions for manipulating the bits in registers and memory. These instructions are primarily used for multiplying or dividing values by powers of two and for bit-level manipulations. SHL (Shift Left) The SHL instruction shifts the bits of a register or memory operand to the left. A left shift operation essentially multiplies the operand by a power of 2. Syntax:
  • 47. SHL destination, count The SHL instruction works by shifting all bits to the left, inserting zeros in the vacated positions on the right. The bits that are shifted out of the leftmost position are stored in the Carry Flag (CF). SHR (Shift Right) The SHR instruction shifts the bits of a register or memory operand to the right. A right shift operation divides the operand by a power of 2. This instruction is typically used for unsigned values. Syntax: SHR destination, count The SHR instruction works by shifting all bits to the right, inserting zeros in the vacated positions on the left. The bits shifted out from the rightmost side are stored in the Carry Flag (CF).
  • 48. SAL (Shift Arithmetic Left) The SAL instruction is functionally identical to SHL. It performs a left shift, and the result is the same as multiplying the operand by powers of two. Syntax: SAL destination, count SAR (Shift Arithmetic Right) The SAR instruction is used for an arithmetic right shift. This instruction works similarly to SHR, but it preserves the sign bit (most significant bit) when shifting. It is used to divide signed numbers by powers of 2. Syntax: SAR destination, count
  • 49. In an arithmetic right shift, the leftmost bit (sign bit) is preserved, so it works correctly for signed numbers in two's complement. Lab 15 String Handling and Manipulation Key String Instructions:
  • 50. MOVS - Move a Byte/Word from Source to Destination The MOVS instruction is used to move a byte or word from the source (pointed by SI or ES:DI) to the destination (pointed by DI or SI). Syntax: MOVS destination, source Usage: It can transfer data in blocks (byte or word), and it works in conjunction with the SI (source index) and DI (destination index) registers. Example: Copying a String LODS: Load a Byte/Word from Source into the Accumulator The LODS instruction loads a byte or word from the source address (pointed by SI) into the accumulator (AL or AX). Syntax: LODS AL | AX, [SI] Usage: LODS is useful for reading or loading characters from a string. Example: Reading a Character from a String
  • 51. STOS: Store the Accumulator Content into Memory The STOS instruction stores the contents of the accumulator into a memory location (pointed by DI), then increments DI. Syntax: STOS AL | AX, [DI] Usage: It’s used to store a byte or word (in AL or AX) to memory. Example: Storing a Character to Memory
  • 52. CMPS: Compare Two Strings The CMPS instruction compares two strings byte by byte. Syntax: CMPS destination, source Usage: This is typically used to compare the byte or word at the memory locations pointed by SI and DI. Example: Comparing Two Strings SCAS: Scan a String for a Byte or Word The SCAS instruction compares a byte or word in the accumulator to the string pointed by DI. Syntax: SCAS AL | AX, [DI] Usage: It’s used to scan a string for a specific byte or word. If a match is found, ZF will be set. Example: Searching for a Character in a String
  • 53. Lab 16 Interfacing with I/O Ports and External Devices Introduction to I/O Ports What are I/O Ports? 8086 I/O ports are used to communicate with external devices such as keyboards, printers, display screens, and other hardware. These ports are locations in the computer's memory-mapped I/O space or an address range where the CPU can send or receive data from hardware components. Ports are usually addressed by a 16-bit value (0x0000 to 0xFFFF in the x86 architecture), and the CPU can either write data to a port or read data from it.The 8086 processor uses IN and OUT instructions for reading from and writing to I/O ports. Common I/O port addresses: 0x60: Keyboard data register (used for input from the keyboard). 0x378: LPT1 (parallel port), used for printers. 0x3F8: COM1 (serial port). Port range: Ports range from 0 to 65535, and can be configured to interface with devices like keyboards, displays, sensors, and more. I/O Communication: OUT sends data from the CPU to an I/O port. IN reads data from an I/O port into the CPU. How to Access I/O Ports in Assembly: In assembly language, you access I/O ports using the IN and OUT instructions, specifying the port address in the dx register and the data in the al, ax, or dx register depending on the size of data (byte, word, etc.)
  • 54. Example of Outputting Data to an External Device Sending Data to a Printer. 0x378: 0x60: