A
Practical File
On
Microprocessor Lab
(LC-ESC-321G)
Submitted
For
Bachelor of Technology
In
Computer Science & Engineering
At
Chaudhary Ranbir Singh State Institute of Engineering
and Technology, Silani Keso, Jhajjar (124103)
Submitted to: Submitted By:
Ms. Anshita Dhankhar Satyam Kumar
Assistant Professor 231901257
(CSE dept.) 5th sem CSE
INDEX
[Link] Practical Date Teacher sign.
1 Sudy the pin diagram of 8085
microprocessor.
2 Sudy the pin diagram of 8086
microprocessor.
3 Write a program to add 2 hexadecimal
and decimal numbers.
4 Write a program to subtract 2
hexadecimal and decimal numbers.
5 Write a program to perform
multiplication of 2 8-bit numbers using
bit addition method.
6 Write a program to perform
multiplication of 2 8-bit numbers using
bit rotation method.
7 Write a program to perform division of
2 8-bit numbers using repeated
subtraction method.
8 Write a program to perform division of
2 8-bit numbers using bit rotation
method.
9 Write a program to find a smallest and a
largest number of an array.
PRACTICAL - 01
Study and learn the pin diagram of 8085 Microprocessor.
Theory:
8085 is pronounced as “eighty-eighty-five” microprocessor. It is an 8-bit microprocessor designed
by Intel in 1977 using NMOS technology.
It has the following configuration -
• 8-bit data bus.
• 16-bit address bus, which can address upto 64KB.
• A 16-bit program counter.
• A 16-bit stack pointer.
• Six 8-bit registers arranged in pairs: BC, DE, HL.
• Requires +5V supply to operate at 3.2MHZ single phase clock.
It is even used in washing machines, microwave ovens, mobile phones, etc.
8085 Microprocessor - Functional Units:
8085 consists of the following functional units :-
Accumulator - It is an 8-bit register used to perform arithmetic, logical, I/O & LOAD/STORE
operations. It is connected to internal data bus & ALU.
Arithmetic and Logic Unit - As the name suggests, it performs arithmetic and logical operations
like Addition, Subtraction, AND, OR, etc. on 8-bit data.
General Purpose Register - There are 6 general purpose registers in 8085 processor, i.e. B, C,
D, E, H, L. Each register can hold 8-bit data. These registers can work in pair to hold 16- bit data
and their pairing combination is like B-C, D-E & H-L.
Program Counter - It is a 16-bit register used to store the memory address location of the next
instruction to be executed. Microprocessor increments the program whenever an instruction is
being executed, so that the program counter points to the memory address of the next instruction
that is going to be executed.
Stack Pointer – It is also a 16-bit register works like stack, which is always
incremented/decremented by 2 during push & pop operations.
Temporary Register - It is an 8-bit register, which holds the temporary data of arithmetic and
logical operations.
Flag Register - It is an 8-bit register having five 1-bit flip-flops, which holds either 0 or 1
depending upon the result stored in the accumulator.
These are the set of 5 flip-flops −
• Sign (S)
• Zero (Z)
• Auxiliary Carry (AC)
• Parity (P)
• Carry ©
Its bit position is shown in the following table :
Instruction register and decoder - It is an 8-bit register. When an instruction is fetched from
memory then it is stored in the Instruction register. Instruction decoder decodes the information
present in the Instruction register.
Timing and Control Unit - It provides timing and control signal to the microprocessor to
perform operations. Following are the timing and control signals, which control external and
internal circuits -
• Control Signals: READY, RD’, WR’, ALE
• Status Signals: S0, S1, IO/M’
• DMA Signals: HOLD, HLDA
• RESET Signals: RESET IN, RESET OUT
Interrupt control - As the name suggests it controls the interrupts during a process. When a
microprocessor is executing a main program and whenever an interrupt occurs.
the microprocessor shifts the control from the main program to process the incoming request. After
the request is completed, the control goes back to the main program.
There are 5 interrupt signals in 8085 microprocessor: INTR, RST 7.5, RST 6.5, RST 5.5, TRAP.
Serial Input/output control - It controls the serial data communication by using these two
instructions: SID (Serial input data) and SOD (Serial output data).
Address buffer and address-data buffer - The content stored in the stack pointer and
program counter is loaded into the address buffer and address-data buffer to communicate
with the CPU. The memory and I/O chips are connected to these buses; the CPU can
exchange the desired data with the memory and I/O chips.
Address bus and data bus - Data bus carries the data to be stored. It is bidirectional, whereas
address bus carries the location to where it should be stored and it is unidirectional. It is used to
transfer the data & Address I/O devices.
8085 Architecture:
PRACTICAL - 02
Study the pin diagram of 8086 Microprocessor.
What is 8086 Microprocessor?
The 8086 microchip, created by Intel in 1978, is a 16-digit processor that noticeable a huge
headway in figuring innovation. It includes a 16-cycle information transport and a 20-bit address
transport, permitting it to address up to 1 MB of memory. The 8086 is known for its portioned
memory engineering, which partitions memory into sections for more proficient access and the
executives. It upholds a rich arrangement of guidelines and methods of activity, making it
flexible for different applications
PIN DIAGRAM :
Intel 8086 is a 16-bit HMOS microprocessor. It is available in 40 pin DIP chip. It uses a 5V DC
supply for its operation. The 8086 uses a 20-line address bus. It has a 16-line data bus. The 20
lines of the address bus operate in multiplexed mode. The 16-low order address bus lines have
been multiplexed with data and 4 high-order address bus lines have been multiplexed with status
signals.
AD0-AD15( Address/Data bus ): These are low order address bus. They are multiplexed with
data. When AD lines are used to transmit memory address the symbol A is used instead of AD,
for example A0-A15. When data are transmitted over AD lines the symbol D is used in place of
AD, for example D0-D7, D8-D15 or D0-D15.
A16-A19:( High order address bus) These are multiplexed with status signals.
S2, S1, S0: (Status pins) These pins are active during T4, T1 and T2 states and is returned to
passive state (1,1,1 during T3 or Tw (when ready is inactive). These are used by the 8288 bus
controller for generating all the memory and I/O operation) access control signals. Any change
in S2, S1, S0 during T4 indicates the beginning of a bus cycle.
A16/S3, A17/S4, A18/S5, A19/S6 : The specified address lines are multiplexed with
corresponding status signals.
HE’/S7: (Bus High Enable/Status) During T1 it is low. It is used to enable data onto the
most significant half of data bus, D8-D15. 8-bit device connected to upper half of the data
bus use BHE (Active Low) signal. It is multiplexed with status signal S7. S7 signal is
available during T2, T3 and T4.
RD’: This is used for read operation. It is an output signal. It is active when low.
READY : This is the acknowledgement from the memory or slow device that they have
completed the data transfer. The signal made available by the devices is synchronized by the
8284A clock generator to provide ready input to the microprocessor. The signal is active
high(1).
INTR : (Interrupt Request)This is triggered input. This is sampled during the last clock
cycles of each instruction for determining the availability of the request. If any interrupt
request is found pending, the processor enters the interrupt acknowledge cycle. This can be
internally masked after resulting the interrupt enable flag. This signal is active high(1) and has
been synchronized internally.
NMI : (Non maskable interrupt) This is an edge triggered input which results in a type II
interrupt. A subroutine is then vectored through an interrupt vector lookup table which is
located in the system memory. NMI is non-maskable internally by software. A transition made
from low(0) to high(1) initiates the interrupt at the end of the current instruction. This input
has been synchronized internally.
INTA : (Interrupt acknowledge) It is active low(0) during T2, T3 and Tw of each interrupt
acknowledge cycle.
MN/MX’ : (Minimum/Maximum)This pin signal indicates what mode the processor will
operate in.
RQ’/GT1′, RQ’/GT0′ : (Request/Grant) These pins are used by local bus masters used to
force the microprocessor to release the local bus at the end of the microprocessor’s current bus
cycle.
LOCK’ : Its an active low pin. It indicates that other system bus masters have not been
allowed to gain control of the system bus while LOCK’ is active low(0). The LOCK signal
will be active until the completion of the next instruction..
TEST’ : This examined by a ‘WAIT’ instruction. If the TEST pin goes low(0), execution
will continue, else the processor remains in an idle state. The input is internally
synchronized during each of the clock cycle on leading edge of the clock.
CLK : (Clock Input) The clock input provides the basic timing for processing operation and
bus control activity. Its an asymmetric square wave with a 33% duty cycle.
RESET : This pin requires the microprocessor to terminate its present activity
immediately. The signal must be active high(1) for at least four clock cycles.
VCC : Power Supply( +5V D.C.)
GND : Ground
QS1,QS0 : (Queue Status)These signals indicate the status of the internal 8086 instruction
queue .
M/IO’: This signal is used to distinguish between memory and I/O operations.
The M Signal is Active high whereas the IO’ Signal is Active Low. When this Pin is High, the
memory operations takes place. On the other hand, when the Pin is low, the Input/Output
operations from the peripheral devices takes place.
DT/R : (Data Transmit/Receive)This pin is required in minimum systems, that want to use an
8286 or 8287 data bus transceiver. The direction of data flow is controlled through the
transceiver.
DEN: (Data enable) This pin is provided as an output enable for the 8286/8287 in a
minimum system which uses transceiver. DEN is active low(0) during each memory and
input-output access and for INTA cycles.
HOLD/HOLDA: HOLD indicates that another master has been requesting a local bus .This is
an active high(1). The microprocessor receiving the HOLD request will issue HLDA (high) as
an acknowledgement in the middle of a T4 or T1 clock cycle.
ALE : (Address Latch Enable)ALE is provided by the microprocessor to latch the address
into the 8282 or 8283 address latch. It is an active high(1) pulse during T1 of any bus cycle.
ALE signal is never floated, is always integer.
The 8086 microprocessor marked a significant advancement in computer architecture, introducing
a 16-bit architecture that paved the way for more powerful computing systems. Its segmented
memory model allowed for efficient data management and execution of larger programs, making it
a foundation for subsequent x86 architecture. With support for a variety of addressing modes and
robust instruction sets, the 8086 became instrumental in the development of early personal
computers and laid the groundwork for future innovations in microprocessor design.
PRACTICAL - 03
Write a program to add two hexadecimal and decimal number.
ASSEMBLY CODE ( to add two hexadecimal numbers)
Program to add two hexadecimal numbers
ORG 2000H ; Starting address
HEX1: DB 3AH ; First hexadecimal number (3AH)
HEX2: DB 25H ; Second hexadecimal number (25H)
RESULT: DB 00H ; Storage for the result
ORG 2003H ; Code starts here
START:
LXI H, 2000H ; Load HL register pair with the address of HEX1 MOV A, M
; Move the first hexadecimal number into accumulator INX H
; Point to HEX2
ADD M ; Add the second hexadecimal number to the accumulator
INX H ; Point to RESULT
MOV M, A ; Store the result in memory
HLT ; Halt the program
1. Data Section:
HEX1: Stores the first hexadecimal number 3AH (58 in decimal). HEX2:
Stores the second hexadecimal number 25H (37 in decimal). RESULT:
Reserved space to store the addition result.
2. Initialization: The program starts executing at address 2003H.
3. Program Execution:
LXI H, 2000H: Loads the HL register pair with the address of HEX1.
MOV A, M: Moves the content of HEX1 (which is 3AH) into the accumulator (A).
INX H: Increments the HL register pair to point to HEX2.
ADD M: Adds the content of HEX2 (which is 25H) to the accumulator. After this operation, A
will hold the sum of 3AH and 25H
INX H: Increments HL again to point to [Link] HL again to point to
RESULT.
MOV M, A: Stores the result of the addition back into the memory location designated for
RESULT.
HLT: Halts the program.
After executing the program, you can check the result at memory location 2004H: Input
Values:
First Hexadecimal No.: 3AH (58 in decimal) Second
Hexadecimal No.: 25H (37 in decimal) Addition:
3AH + 25H = 5FH (95 in decimal)
Memory Location: After execution, you should check the result at memory location 2004H.
OUTPUT:
ASSEMBLY CODE ( to add two decimal numbers)
Program to add two decimal numbers
ORG 2000H ; Starting address
NUM1: DB 15H ; First decimal number (15)
NUM2: DB 25H ; Second decimal number (25)
RESULT: DB 00H ; Storage for the result
ORG 2003H ; Code starts here
START:
LXI H, 2000H ; Load HL register pair with the address of NUM1
MOV A, M ; Move the first decimal number into accumulator INX
H ; Point to NUM2
ADD M ; Add the second decimal number to the accumulator
INX H ; Point to RESULT
MOV M, A ; Store the result in memory
HLT ; Halt the program
1. Data Section:
NUM1: Stores the first decimal number 15 (represented as 0FH in hexadecimal).
NUM2: Stores the second decimal number 25 (represented as 19H in
hexadecimal).
RESULT: Reserved space to store the addition result.
2. Initialization: The program starts executing at address 2003H.
3. Program Execution:
LXI H, 2000H: Loads the HL register pair with the address of NUM1.
MOV A, M: Moves the content of NUM1 (which is 15) into the accumulator (A).
INX H: Increments the HL register pair to point to NUM2.
ADD M: Adds the content of NUM2 (which is 25) to the accumulator. After this operation, A
will hold the sum of 15 and 25.
INX H: Increments HL again to point to RESULT.
MOV M, A: Stores the result of the addition back into the memory location
designated for RESULT.
HLT: Halts the program.
After executing the program, you can check the result at memory location 2004H:
Input Values:
First Decimal Number: 15
Second Decimal Number: 25
Addition: 15 + 25 = 40
Memory Location: After execution, you can check the result at memory location 2004H.
OUTPUT:
PRACTICAL - 04
Write a program to subtract two hexadecimal and decimal numbers.
ASSEMBLY CODE ( to subtract two hexadecimal numbers)
Program to subtract two hexadecimal numbers
ORG 2000H ; Starting address
HEX1: DB 4AH ; First hexadecimal number (4AH)
HEX2: DB 1BH ; Second hexadecimal number (1BH)
RESULT: DB 00H ; Storage for the result
ORG 2003H ; Code starts here
START:
LXI H, 2000H ; Load HL register pair with the address of HEX1 MOV
A, M ; Move the first hexadecimal number into accumulator
INX H ; Point to HEX2
SUB M ; Subtract the second hexadecimal number from the accumulator
INX H ; Point to RESULT
MOV M, A ; Store the result in memory
HLT ; Halt the program
1. Data Section:
HEX1: Stores the first hexadecimal number 4AH (74 in decimal). HEX2:
Stores the second hexadecimal number 1BH (27 in decimal). RESULT:
Reserved space to store the subtraction result.
2. Initialization: The program starts executing at address 2003H.
3. Program Execution:
LXI H, 2000H: Loads the HL register pair with the address of HEX1.
MOV A, M: Moves the content of HEX1 (which is 4AH) into the accumulator (A).
INX H: Increments the HL register pair to point to HEX2.
SUB M: Subtracts the content of HEX2 (which is 1BH) from the accumulator.
After this operation, A will hold the result of 4AH - 1BH.
INX H: Increments HL again to point to RESULT.
MOV M, A: Stores the result of the subtraction back into the memory location
designated for RESULT.
HLT: Halts the program.
After executing ,
Input Values:
First Hexadecimal Number: 4AH (74 in decimal)
Second Hexadecimal Number: 1BH (27 in decimal)
Subtraction: 4AH - 1BH = 29H (41 in decimal)
Memory Location: After execution, you can check the result at
memory location 2004H.
OUTPUT
ASSEMBLY CODE ( to subtract two decimal numbers)
; Program to subtract two decimal numbers
ORG 2000H ; Starting address
NUM1: DB 25H ; First decimal number (25)
NUM2: DB 15H ; Second decimal number (15)
RESULT: DB 00H ; Storage for the result
ORG 2003H ; Code starts here
START:
LXI H, 2000H ; Load HL register pair with the address of NUM1 MOV
A, M ; Move the first decimal number into accumulator INX H ; Point
to NUM2
SUB M ; Subtract the second decimal number from the accumulator
INX H ; Point to RESULT
MOV M, A ; Store the result in memory
HLT ; Halt the program
1. Data Section:
NUM1: Stores the first decimal number 25 (represented as 19H in hexadecimal).
NUM2: Stores the second decimal number 15 (represented as 0FH in hexadecimal).
RESULT: Reserved space to store the subtraction result.
2. Initialization: The program starts executing at address 2003H.
3. Program Execution:
LXI H, 2000H: Loads the HL register pair with the address of NUM1.
MOV A, M: Moves the content of NUM1 (which is 25) into the accumulator (A).
INX H: Increments the HL register pair to point to NUM2.
SUB M: Subtracts the content of NUM2 (which is 15) from the accumulator.
After this operation, A will hold the result of 25 - 15.
INX H: Increments HL again to point to RESULT.
MOV M, A: Stores the result of the subtraction back into the memory location
designated for RESULT.
HLT: Halts the program.
After executing ,
Input Values:
First Decimal Number: 25 Second
Decimal Number: 15 Subtraction:
25 - 15 = 10
Memory Location: After execution, you can check the result at memory location 2004H.
OUTPUT
PRACTICAL - 05
Write a program to perform multiplication of two 8-bit numbers using bit
addition method .
ASSEMBLY CODE
Program to multiply two 8-bit numbers using bit addition method
ORG 2000H ; Starting address
NUM1: DB 05H ; First number (5)
NUM2: DB 03H ; Second number (3)
RESULT_LOW: DB 00H ; Lower byte of result
RESULT_HIGH: DB 00H ; Higher byte of result
ORG 2003H ; Code starts here
START:
MOV A, M ; Load NUM1 into A
INX H ; Point to NUM2
MOV B, M ; Load NUM2 into B
MVI C, 00H ; Clear C (will hold the result low) MVI
D, 00H ; Clear D (will hold the result high)
; Multiplication loop
MUL_LOOP:
JZ END ; If B is zero, end the loop MOV
E, A ; Move A to E (E = NUM1)
RLC ; Rotate A left (shift)
DCR B ; Decrement B
JZ ADD_RESULT ; If B is zero, add to result
JMP MUL_LOOP ; Continue loop
ADD_RESULT:
ADD C ; Add the low result
MOV C, A ; Store low result back to C MOV A,
E ; Restore E (which holds NUM1)
INX H ; Point to RESULT_LOW
MOV M, C ; Store low result in RESULT_LOW
HLT ; Halt the program
END:
HLT ; Halt the program
1. Data Section:
NUM1: Stores the first number (5).
NUM2: Stores the second number (3).
RESULT_LOW: Reserved space for the lower byte of the result.
RESULT_HIGH: Reserved space for the higher byte of the result .
2. Initialization:
The program starts executing at address 2003H.
Load NUM1 into register A and NUM2 into register B.
Clear registers C and D to store results.
3. Multiplication Loop:
The program checks if B (the multiplier) is zero; if yes, it jumps to the end.
The left rotation (RLC) simulates a shift operation.
Decrease B by 1 (DCR B).
If B is not zero, it continues the loop.
4. Adding Result:
When B reaches zero, the program adds the accumulated result to the storage.
5. Program End:
The program halts after storing the result.
After executing ,
Input Values:
First Number: 05H (5 in decimal)
Second Number: 03H (3 in decimal)
Multiplication: 5 * 3 = 15
OUTPUT:
PRACTICAL - 06
Write a program to perform multiplication of two 8-bit numbers using rotation
method .
ASSEMBLY CODE
; Program to multiply two 8-bit numbers using rotation method
ORG 2000H ; Starting address
NUM1: DB 05H ; First number (5) NUM2:
DB 03H ; Second number (3)
RESULT: DB 00H ; Storage for the
result ORG 2003H ; Code starts here START:
; Initialize registers
MVI C, 00H ; Clear C to hold the result
MOV A, M ; Load NUM1 into A INX H
; Point to NUM2
MOV B, M ; Load NUM2 into B
MVI D, 08H ; Set loop counter to 8 (for 8 bits)
MUL_LOOP:
RLC ; Rotate left A (NUM1)
JNC NO_ADD ; If carry is not set, skip
addition ADD C ; Add to the result in C
NO_ADD:
DCR B ; Decrement B (NUM2)
JZ STORE_RESULT ; If B is zero, store the result
DCR D ; Decrement loop counter
JNZ MUL_LOOP ; Repeat the loop until all bits are process
STORE_RESULT:
MOV M, C ; Store the result in memory
HLT ; Halt the program
1. Data Section:
NUM1: Stores the first number (5).
NUM2: Stores the second number (3).
RESULT: Reserved space for the result of the multiplication.
2. Initialization:
The program starts executing at address 2003H. Register
C is cleared to hold the multiplication result. Load NUM1
into register A and NUM2 into register B. Set a loop
counter D to 8 (for 8 bits).
3. Multiplication Loop:
RLC: Rotate the accumulator left. This simulates shifting the bits of NUM1.
JNC NO_ADD: If the carry flag is not set (meaning the most significant bit was0), skip the
addition.
ADD C: If there is a carry, add the value of NUM1 to C.
DCR B: Decrement B (the multiplier).
JZ STORE_RESULT: If B reaches zero, jump to store the result.
DCR D: Decrement the loop counter.
JNZ MUL_LOOP: Repeat the loop until all bits are processed.
4. Store Result:
MOV M, C: Store the final result in memory.
HLT: Halt the program.
After executing ,
Input Values:
First Number: 05H (5 in decimal)
Second Number: 03H (3 in decimal)
Multiplication: 5 * 3 = 15 (in hexadecimal: 0FH)
OUTPUT
PRACTICAL - 07
Write a program to perform division of two 8 bit numbers using repeated
subtraction.
ASSEMBLY CODE
Program to divide two 8-bit numbers using repeated subtraction
ORG 2000H ; Starting address
DIVIDEND: DB 18H ; Dividend (24 in decimal)
DIVISOR: DB 06H ; Divisor (6 in decimal)
QUOTIENT: DB 00H ; Storage for the quotient
REMAINDER: DB 00H ; Storage for the remainder
ORG 2003H ; Code starts here
START:
MOV A, M ; Load DIVIDEND into accumulator
INX H ; Point to DIVISOR
MOV B, M ; Load DIVISOR into B
MVI C, 00H ; Clear C to store QUOTIENT
MVI D, 00H ; Clear D for Remainder
DIV_LOOP:
CMP B ; Compare A (Dividend) with B (Divisor) JC
STORE_RESULT ; If A < B, jump to store result SUB B
; Subtract B from A
INX C ; Increment QUOTIENT
JMP DIV_LOOP ; Repeat the loop
STORE_RESULT:
MOV M, C ; Store QUOTIENT in memory
INX H ; Point to REMAINDER
MOV M, A ; Store REMAINDER in memory
HLT ; Halt the program
1. Data Section:
DIVIDEND: Stores the dividend (24, represented as 18H).
DIVISOR: Stores the divisor (6, represented as 06H).
QUOTIENT: Reserved space for the result of the division.
REMAINDER: Reserved space to store the remainder.
2. Initialization:
The program starts executing at address 2003H.
Load the DIVIDEND into register A.
Load the DIVISOR into register B.
Clear register C to hold the quotient and register D for the remainder.
3. Division Loop:
CMP B: Compare the dividend (A) with the divisor (B). JC
STORE_RESULT: If A < B, jump to store results. SUB B:
Subtract the divisor from the dividend.
INX C: Increment the quotient for each successful subtraction.
JMP DIV_LOOP: Repeat the loop.
4. Store Result:
MOV M, C: Store the quotient in memory.
HLT: Halt the program.
INX H: Point to REMAINDER.
MOV M, A: Store the final value of A as the remainder.
HLT: Halt the program.
After executing ,
Input Values:
Dividend: 18H (24 in decimal)
Divisor: 06H (6 in decimal)
Division Calculation:
Quotient: 24 / 6 = 4 (which is 04H)
Remainder: 24 % 6 = 0 (which is 00H)
OUTPUT:
PRACTICAL - 08
Write a program to perform division of two 8 bit numbers using bit
rotation method .
ASSEMBLY CODE
Program to divide two 8-bit numbers using bit rotation method
ORG 2000H ; Starting address
DIVIDEND: DB 18H ; Dividend (24 in decimal)
DIVISOR: DB 06H; Divisor (6 in decimal)
QUOTIENT: DB 00H ; Storage for the quotient
REMAINDER: DB 00H ; Storage for the remainder
ORG 2003H ; Code starts here
START:
MOV A, M ; Load DIVIDEND into A
INX H ; Point to DIVISOR
MOV B, M ; Load DIVISOR into B MVI
C, 00H ; Clear C for QUOTIENT
MVI D, 00H ; Clear D for Remainder
; Initialize bit counter
MVI E, 08H ; Set bit counter to 8
DIV_LOOP:
RLC ; Rotate left the accumulate or (A)
RLC ; Rotate left again (to bring in next bit of dividend)
CMP B ; Compare with the divisor
JC NO_SUB ; If A < B, skip subtraction
SUB B ; Subtract divisor from A
INX C ; Increment the quotient
NO_SUB:
DCR E ; Decrement bit counter
JNZ DIV_LOOP ; Repeat until all bits processed
STORE_RESULT:
MOV M, C ; Store QUOTIENT in memory
INX H ; Point to REMAINDER
MOV M, A ; Store REMAINDER in memory
HLT ; Halt the program
1. Data Section:
DIVIDEND: Stores the dividend (24, represented as 18H).
DIVISOR: Stores the divisor (6, represented as 06H).
QUOTIENT: Reserved space for the result of the division.
REMAINDER: Reserved space to store the remainder.
2. Initialization:
The program starts executing at address 2003H.
Load the DIVIDEND into register A.
Load the DIVISOR into register B.
Clear register C to hold the quotient and register D for the remainder.
Set up a bit counter in register E for 8 bits.
3. Division Loop:
RLC: Rotate the accumulator left. This shifts the bits of the dividend.
CMP B: Compare the value in the accumulator with the divisor.
JC NO_SUB: If the dividend is less than the divisor, skip subtraction.
SUB B: Subtract the divisor from the dividend.
INX C: Increment the quotient for each successful subtraction.
DCR E: Decrement the bit counter.
JNZ DIV_LOOP: Repeat the loop until all bits are processed
4. Store Result:
MOV M, C: Store the quotient in memory.
HLT: Halt the program.
INX H: Point to REMAINDER.
MOV M, A: Store the final value of A as the remainder.
HLT: Halt the program.
After executing ,
Input Values:
Dividend: 18H (24 in decimal)
Divisor: 06H (6 in decimal)
Division Calculation:
Quotient: 24 / 6 = 4 (which is 04H)
Remainder: 24 % 6 = 0 (which is 00H)
OUTPUT:
PRACTICAL - 09
Write a program to find the smallest and largest number from an array.
ASSEMBLY CODE
Program to find smallest and largest number in an array
ORG 2000H ; Starting address
ARRAY: DB 05H, 10H, 03H, 25H, 08H ; Example array of 5 numbers
SIZE: DB 05H ; Size of the array (5 numbers)
SMALLEST: DB 00H ; Storage for the smallest number
LARGEST: DB 00H ; Storage for the largest number
ORG 2006H ; Code starts here
START:
MVI A, M ; Load the first element into accumulator (A) MOV
B, A ; Initialize largest with the first element MOV C,
A ; Initialize smallest with the first element MVI D,
00H ; Initialize index to 0
INX H ; Point to the first element of the array
LOOP:
DCR SIZE ; Decrement SIZE to check next element JZ
STORE_RESULT ; If SIZE is zero, go to store result MOV A,
M ; Load the current array element into A
CMP B ; Compare with the largest
JG UPDATE_LARGEST ; If A > B, update largest
CMP C ; Compare with the smallest
JL UPDATE_SMALLEST ; If A < C, update smallest
JMP CONTINUE ; Continue to the next element
UPDATE_LARGEST:
MOV B, A ; Update largest
JMP CONTINUE
UPDATE_SMALLEST:
MOV C, A ; Update smallest
JMP CONTINUE
CONTINUE:
INX H ; Move to the next element
JMP LOOP ; Repeat the loop
STORE_RESULT:
MOV M, C ; Store smallest in memory INX
H ; Point to largest location MOV M,
B ; Store largest in memory HLT ;
Halt the program
1. Data Section:
ARRAY: Contains a predefined set of numbers.
SIZE: Indicates the number of elements in the array.
SMALLEST: Reserved space to store the smallest number.
LARGEST: Reserved space to store the largest number.
2. Initialization:
The program starts executing at address 2006H.
The first element of the array is loaded into the accumulator A.
Initialize registers B and C with the first element to keep track of the largest and smallest
numbers.
Set register D to zero for indexing.
3. Loop:
Decrement the SIZE to keep track of how many numbers are processed. If
SIZE is zero, jump to STORE_RESULT.
Load the current element of the array into A.
Compare A with the largest (B) and smallest (C) values. If A
is greater than B, update B (largest).
If A is less than C, update C (smallest).
Increment the index to move to the next element in the array.
Repeat the loop until all elements are processed.
4. Store Result:
Store the smallest and largest values in memory.
Halt the program.
After executing ,
Input Values:
Array: {05H, 10H, 03H, 25H, 08H} (Decimal: 5, 10, 3, 25, 8)
Output Calculation:
Smallest Number: 03H (3 in decimal)
Largest Number: 25H (25 in decimal)
OUTPUT: