Lecture Notes of Microprocessor and Microcontroller-converted 1586837702
Lecture Notes of Microprocessor and Microcontroller-converted 1586837702
POLYTECHNIC
ROURKELA
LECTURE NOTES
MICROCOMPUTER:
• Microcomputers became popular in the 1970s and 80s with the advent of increasingly
powerful microprocessors.
• Examples of Microcomputers are Intel 8051 controller-a single board computer,
• The second purpose of the memory is to store the binary-coded data with which the
computer is going to be working.
INPUT / OUTPUT:
• The input/output or I/O Section allows the computer to take in data from the outside
world or send data to the outside world.
• Peripherals such as keyboards, video display terminals, printers are connected to I/O
Port.
• The CPU also contains an address counter or instruction pointer register, which holds
the address of the next instruction or data item to be fetched from memory.
Architecture of microprocessor-
• The ALU performs operations such as addition, subtraction and logic operations such as
AND, OR and exclusive OR.
Control Unit:
• The Control Unit Provides the necessary timing and control signals to all the operations
in the Microcomputer
• It controls the flow of data between the Microprocessor and Memory and Peripherals.
• The Control unit performs 2 basic tasks
→Sequencing
→Execution
Register:
• If the CPU has N address lines, then it can directly address 2N memory locations i.e. CPU
with 16 address lines can address 216 or 65536 memory locations.
DATA BUS:
• The data bus consists of 8, 16 or 32 parallel signal lines.
• The data bus lines are bi-directional.
• This means that the CPU can read data in from memory or it can send data out to
memory.
CONTROL BUS:
• The control bus consists of 4 to 10 parallel signal lines.
• The CPU sends out signals on the control bus to enable the output of addressed memory
devices or port devices.
• Typical control bus signals are Memory Read, Memory Write, I/O
Read and I/O Write.
ADDRESS BUS:
DATA BUS:
• It is a group of conducting wires, which is used to generate timing and control signals
to control all the associated peripherals, microprocessor uses control bus to process
data i.e. what to do with selected memory location. Some control signals are:
• Memory read
• Memory write
• I/O read
• I/O Write
• Opcode fetch
1.5 ARCHITECTURE OF 8085 MICROPROCESSOR:
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.
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 (C)
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
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.
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,
and TRAP.
Address bus:
A15-A8, it carries the most significant 8-bits of memory/IO address.
Data bus:
AD7-AD0, it carries the least significant 8-bit address and data bus.
ALE:
It is a positive going pulse generated when a new operation is started by the
microprocessor. When the pulse goes high, it indicates address. When the pulse goes down
it indicates data.
S1 & S0:
These signals are used to identify the type of current operation.
Power supply:
There are 2 power supply signals Vcc & Vss. VCC indicates +5v power supply and VSS
indicates ground signal.
Clock signals:
There are 3 clock signals, i.e. X1, X2, CLK OUT.
X1 X2:
A crystal (RC, LC N/W) is connected at these two pins and is used to set frequency of the
internal clock generator. This frequency is internally divided by 2.
CLK OUT:
This signal is used as the system clock for devices connected with the microprocessor.
Interrupts & externally initiated signals:
• Interrupts are the signals generated by external devices to request the microprocessor to
perform a task.
• There are 5 interrupt signals, i.e. TRAP, RST 7.5, RST 6.5, RST 5.5, and INTR. We will discuss
interrupts in detail in interrupts section.
TRAP:
• It is a non-maskable interrupt, having the highest priority among all interrupts. By default,
it is enabled until it gets acknowledged. In case of failure, it executes as ISR and sends the
data to backup memory. This interrupt transfers the control to the location 0024H.
RST7.5:
• It is a maskable interrupt, having the second highest priority among all interrupts. When
this interrupt is executed, the processor saves the content of the PC register into the stack
and branches to 003CH address.
RST 6.5:
• It is a maskable interrupt, having the third highest priority among all interrupts. When this
interrupt is executed, the processor saves the content of the PC register into the stack and
branches to 0034H address.
RST 5.5:
• It is a maskable interrupt. When this interrupt is executed, the processor saves the content
of the PC register into the stack and branches to 002CH address.
INTR:
It is a maskable interrupt, having the lowest priority among all interrupts. It can be
disabled by resetting the microprocessor.
When INTR signal goes high, the following events can occur:
The microprocessor checks the status of INTR signal during the execution of each
instruction.
• When the INTR signal is high, then the microprocessor completes its current instruction
and sends active low interrupt acknowledge signal.
• When instructions are received, then the microprocessor saves the address of the next
instruction on stack and executes the received instruction.
INTA’:
It is an interrupt acknowledgment sent by the microprocessor after INTR is received.
RESET IN:
This signal is used to reset the microprocessor by setting the program counter to zero.
RESET OUT:
This signal is used to reset all the connected devices when the microprocessor is reset.
READY:
This signal indicates that the device is ready to send or receive data. If READY is low, then
the CPU has to wait for READY to go high.
HOLD:
This signal indicates that another master is requesting the use of the address and data
buses.
• It is possible to use these registers as pairs to store 16-bit information. Only B-C, D-E,
and H-L can form register pairs.
• When they are used as register pairs in an instruction, the left register is understood to
have the MSB byte and the right registers the LSB byte.
• For example, in D-E register pair, the content of the D register is treated as the MSB byte,
and the content of E register is treated as the LSB byte.
2. Temporary Registers:
• Z-Zero flag:-The zero flag sets if the result of the operation in ALU is zero and flag resets
if the result is non-zero. The zero flags are also set if a certain register content becomes
zero following an increment or decrement operation of that register.
• AC-auxiliary Carry flag: - This flag is set if there is an overflow out of bit 3 i.e. carry
from lower nibble to higher nibble (D3 bit to D4 bit). This flag is used for BCD operations
and it is not available for the programmer.
• P-Parity flag: - Parity is defined by the number of one’s present in the accumulator.
After arithmetic or logical operation, if the result has an even number of ones, i.e. even
parity, the flag is set. If the parity is odd, the flag is reset.
• CY-Carry flag: - This flag is set if there is an overflow out of bit 7. The carry flag also
serves as a borrow flag for subtraction. In both the examples shown below, the carry
flag is set.
Instruction Register:-
• In a typical processor operation, the processor first fetches the opcode of instruction
from memory (i.e. it places an address on the address bus and memory responds by
placing the data stored at the specified address on the data bus).
• The CPU stores this opcode in a register called the instruction register. This opcode is
further sent to the instruction decoder to select one of the 256 alternatives.
GPR-
• It stands for General purpose registers.
• In these registers data can be accessed directly without requiring any intermediate.
• Examples of GPR are B, C, D, E, H, and L.
• These registers are of 8-bit.
• In order to hold 16 bit data, two 8 bit register can be combined or they can work in
pairs such as B-C, D-E and H-L. These pairs are known as register pairs.
• The H-L pair works as a memory pointer.
• A memory pointer holds the address of a particular memory location.
SPR-
• SPR stands for special purpose register.
• In special purpose register data cannot accessed directly and requires an intermediate.
• Examples of SPR are Accumulator, program counter, stack pointer.
• These registers are used only by microprocessor not by users.
• We use Timing and controlling unit in 8085 for the generation of timing signals and
the signals to control.
• All the operations and functions both interior and exterior of a microprocessor are
controlled by this unit.
• X2 and CLK output pins: To do or rather perform the operations of timing in the
microcomputer system, we have a generator called clock generator in the CU of 8085.
• Other than the quartz crystal the complete circuit of the oscillator is within the chip.
The two pins namely X1 and X2 are taken out from the chip to give the connection to
the crystal externally.
• We connect a capacitor of 20pF between the terminal X2 and ground just to analyze if
the crystal is getting started.
• The frequency of the crystal is divided by 2 which divide the counter of the unit of
control by 2.
• Internally 8085A works with a frequency of 3 MHz internally with clock frequency.
Hence a crystal of frequency of 6-MHz crystal gets connected between X1 and X2.
• Every operation in the entire 8085 system occurs with the given synchronization
process with the clock. There are Peripheral chips like 8251 USART, which does not
operate until a small clock signal is in need.
• “8085” provides the “stack pointer” which gives the address of the “top of stack”. So,
whenever you want to store an item it stacks, you just store it at the address provided
by the stack pointer.
The stack is a reserved area of the memory in RAM where temporary information
may be stored. An 8-bit stack pointer is used to hold the address of the most recent stack
entry. This location which has the most recent entry is called as the top of the stack.
When the information is written on the stack, the operation is called PUSH. When
the information is read from the stack, the operation is called POP. The stack works on
the principle of Last in First Out.
1.11 8085 INTERRUPTS:
• Interrupt is a process where an external device can get the attention of the
microprocessor.
• An interrupt is considered to be an emergency signal that may be serviced.
• The Microprocessor may respond to it as soon as possible.
• The process starts from the I/O device
• The process is asynchronous
Classification of Interrupts:
Interrupts can be classified into two types:
• Maskable Interrupts (Can be delayed or Rejected)
• Non-Maskable Interrupts (Cannot be delayed or Rejected)
SIM Instruction:
The SIM instruction is used to mask or unmask RST hardware interrupts. When executed,
the SIM instruction reads the content of accumulator and accordingly mask or unmask the
interrupts. The format of control word to be stored in the accumulator before executing
SIM instruction is as shown in Fig.
• In addition to masking interrupts, SIM instruction can be used to send serial data on the
SOD line of the processor.
• The data to be send is placed in the MSB bit of the accumulator and the serial data output
is enabled by making D6 bit to 1.
RIM Instruction:
• RIM instruction is used to read the status of the interrupt mask bits.
• When RIM instruction is executed, the accumulator is loaded with the current status of
the interrupt masks and the pending interrupts.
• The format and the meaning of the data stored in the accumulator after execution of RIM
instruction is shown in Fig.
• In addition RIM instruction is also used to read the serial data on the SID pin of the
processor.
• The data on the SID pin is stored in the MSB of the accumulator after the execution of the
RIM instruction.
• E.g. write an assembly language program to enables all the interrupts in 8085 after reset.
EI Enable interrupts MVI A, 08H: Unmask the interrupts SIM: Set the mask and unmask
using SIM instruction.
UNIT-2: INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
1 – Byte Instructions:
• They include opcode and operands in the same byte.
• Operands are internal registers and coded into the instruction.
• Instructions require one memory location to store the single byte in the memory.
Note:
Instructions having the only register or register pair as the operand is 1 – Byte Instructions.
Instructions in the absence of operand are also 1 – Byte Instructions.
Examples:
MOV B, C
LDAX B
NOP
HLT
2 – Byte Instructions:
• 1st byte specifies opcode and 2nd byte specifies operand.
• Instructions require two memory locations to store in the memory.
Note:
Instructions having the 8-bit number either as an address or data as the operand is 2 – Byte
Instructions.
Examples:
MVI B, 26 H
IN 56 H
3 – Byte Instructions:
• In a 3-byte instruction, the first byte specifies the opcode, and the following two bytes
specify the 16-bit address.
• The 2nd byte holds the low order address.
• The 3rd-byte holds the high order address.
• Instructions require three memory locations to store the single byte in the memory.
Note:
Instructions having the 16-bit number either as an address or data as the operand is 3 – Byte
Instructions.
Examples:
LDA 2050 H
JMP 2085 H
Example:
LDA 9525H→ Load the contents of memory location into Accumulator.
Example:
• MOV A, B→Move the contents of B register to A register.
Example:
• LXIH 9570H→Load immediate the H-L pair with the address of the location 9570H
• MOV A, M→ Move the contents of the memory location pointed by the H-L pair
to accumulator
Example:
ADI DATA →Add immediate the data to the contents of the accumulator.
LXIH 8500H→Load immediate the H-L pair with the operand 8500H
MVI 08H → Move the data 08 H immediately to the accumulator
SUI 05H →Subtract immediately the data 05H from the accumulator
• In this addressing mode the instruction don’t require the address of the operand.
or
• The mode of instruction which do not specify the operand in the instruction but it is
implicated, is known as implicit addressing mode. i.e., the operand is supposed to be
present generally in accumulator.
Example:
CMA→complement the contents of Accumulator
STC→Set carry.
• An instruction is a binary bit pattern which performs a specific function in a system. The
entire group of instructions of a system is called the instruction set.
• Instruction set determines what functions the microprocessor can perform with a single
instruction.
• The instruction set in microprocessor 8085 can be classified into five functional
categories:
OR
• These instructions move data between registers, or between memory and registers.
• This group of instructions copies data from a location called as source to another location
called as destination, without modifying the contents of the source
• These instructions are not the data transfer instructions but data copy instruction because
the source is not modified.
Load accumulator
LDAX B/D Reg. pair The contents of the designated register pair point to a
memory location. This instruction copies the contents of
that memory location into the accumulator. The
contents of either the register pair or the memory
location are not altered.
Example: LDAX B
Arithmetic Operations:
They perform arithmetic operations, such as, addition, subtraction, increment, and
decrement.
Addition:
• Addition of any 8-bit number, or the contents of a register or the contents of a memory
location is added to the contents of the accumulator and the sum is stored in the accumulator.
• No two other 8-bit registers can be added directly.
• For example the contents of register B cannot be added directly to the contents of the register
C. 8085 can also perform 16-bit. It can also perform BCD addition.
Subtraction:
• Subtraction of any 8-bit number, or the contents of a register, or the contents of a memory
location can be subtracted from the contents of the accumulator and the results stored in the
accumulator.
• The subtraction is performed in 2’s compliment, and if the results is negative. Then they are
expressed in 2’s complement.
• No two other registers can be subtracted directly. 8085 do not perform 16-bit subtraction.
Increment or Decrement:
• The 8-bit contents of any register or a memory location can be incremented or decrement by
1.
• Similarly, the 16-bit contents of a register pair can be incremented or decrement by 1.
• These increment and decrement operations can be performed directly in the source itself. It
means without using accumulator.
Opcode Operand Meaning Explanation
These type instructions performs various logical operations with the contents of the
accumulator. 8085 can perform six logical operation which are:
• AND
• OR
• Exclusive-OR
• NOT
• Compare
• Rotate
A 8-bit number can be logically ANDed with the contents of the accumulator. It can also be a
content of register or of a memory location. The results are stored in the accumulator. The
content of the accumulator can be complimented.
Rotate:
Each bit of the accumulator can be shifted either left or right to the next position.
Compare:
• Any 8-bit number or the content of a register, or content of a memory location can be
compared for equality, greater than, or less than, with the contents of the accumulator.
• The result is reflected by zero and carry flags.
Logical AND
The contents of the accumulator are
ANI 8-bit data immediate with
logically AND with the 8-bit data and
the accumulator
the result is placed in the
accumulator.
BRANCHING OPERATIONS:
This group of instruction transfers the control of microprocessor from one location to
another location. 8085 can perform four types of branching operations. These are:
Jump:
• Conditional jumps are the important aspect of the decision-making process in the
programming of a microprocessor.
• These instructions tests for a certain conditions and alter the program sequence when the
condition is met.
• For example zero or carry flag, In addition, the instruction set also includes an instruction
called unconditional jump.
• These type of instructions changes the sequence of a program either by calling a sub-routine
or returning from a sub-routine.
• The conditional call and return instructions can also test the condition flags.
1. Jump Instructions: –
The jump instruction transfers the program sequence to the memory address given in the
operand based on the specified flag. Jump instructions are 2 types: Unconditional Jump
Instructions and Conditional Jump Instructions.
2. Call Instructions:–
The call instruction transfers the program sequence to the memory address given in the
operand. Before transferring, the address of the next instruction after CALL is pushed onto
the stack. Call instructions are 2 types: Unconditional Call Instructions and Conditional Call
Instructions.
3. Return Instructions: –
The return instruction transfers the program sequence from the subroutine to the calling
program. Jump instructions are 2 types: Unconditional Jump Instructions and Conditional
Jump Instructions.
(a) Unconditional Return Instruction:
• The program sequence is transferred unconditionally from the subroutine to the calling
program.
OPCODE OPERAND EXPLANATION EXAMPLE
unconditionally
These type of instructions controls the machine functions, such as halt, interrupt, or do
nothing.
• Machine language and Hex code instructions are very difficult for the programmer.
• Hence for programmer, the instructions of microprocessor are made in the form of English
abbreviation (short form). These instructions are name as Assembly Language instructions
or mnemonics.
• The combinations of different mnemonics are known as Assembly Language Program and it
is a low level language.
Examples of assembly language program
Loading Register or Memory with Data
• In this program the instruction MVI A, ON H will place the given data 08 1H in the
register A.
• The Hex code for MVI A, 08 H is 3E, 08 IH where 3E is the Hex code for MVI A.
• The instruction MOV C, A will move the contents of register A to the register C. Its
machine code is 4F.
• With this instruction the data of register A is copies into the register C. It means
the given data, is 08 H which was previously placed in register A is now copied
into the register C.
• The memory locations required for this program are 2000 H to 2003 H. Any other
memory locations can be selected. After the execution of a program, the contents
of register C can be examined.
Example 3. Write a program to load the contents of memory location 2050 H into
accumulator and then move this data into register B
• The instruction LDA 2050 H will load the contents of memory location 2050 H into the
accumulator.
• The machine code for the instruction LDA is 3A.
• The instruction MOV B. A (Machine code 47) will move the contents of Accumulator to the
register B.
• First of all data 07 is fetch in the memory location 2050.
• Then memory locations 2000 H contain 3A, 2001 H contain 50 H, 2002 H contains 20 H, 2003
H contains 47 H and 2004 H contains 76 H.
• After execution of a program, the contents of register B can be examined.
EXPLANATION:
EXPLANATION:
Assumption – 8 bit number is stored at memory location 2050. Final result is stored at
memory location 3050.
EXPLAINATION:
EXPLANATION:
Registers A, B are used for general purpose.
1. LDA 2050: load the content of memory location 2050 in accumulator A.
2. ANI 0F: perform AND operation in A and 0F. Store the result in A.
3. MOV B, A: moves the content of A in register B.
4. LDA 2050: load the content of memory location 2050 in accumulator A.
5. ANI F0: perform AND operation in A and F0. Store the result in A.
6. RLC: rotate the content of A left by one bit without carry. Use this instruction 4 times to
reverse the content of A.
7. ANA B: perform AND operation in A and B. Store the result in A.
8. STA 3050: store the content of A in memory location 3050.
9. HLT: stops executing the program and halts any further execution.
Example 7- Write a program to find 1’s and 2’s complement of 8-bit number where
starting address is 2000 and the number is stored at 3000 memory address and store
result into 3001 and 3002 memory address.
Program –
MEMORY ADDRESS MNEMONICS OPERANDS COMMENT
2000 LDA [3000] [A] [3000]
2003 CMA [A] [A^]
2004 STA [3001] 1’s complement
2007 ADI 01 [A] [A] + 01
2009 STA [3002] 2’s complement
200C HLT Stop
EXPLANATION:
1. A is an 8-bit accumulator which is used to load and store the data directly
2. LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
3. CMA is used to complement content of accumulator (1 Byte instruction)
4. STA is used to store accumulator direct using 16-bit address (3 Byte instruction)
5. ADI is used to add data into accumulator immediately (2 Byte instruction)
6. HLT is used to halt the program
Assumption: - 8 bit number is stored at memory location 2050. After masking of nibbles,
lower order nibble is stored at memory location 3050 and higher order nibble is stored at
memory location 3051.
Program –
MEMORY MNEMONICS COMMENT
ADDRESS
2000 LDA 2050 A M[2050]
2003 MOV B, A B A
2004 ANI 0F A A (AND) 0F
2006 STA 3050 M[3050] A
2009 MOV A, B AB
200A ANI 0F A A (AND) 0F
200C RLC rotate content of A left by 1
bit without carry
200D RLC rotate content of A left by 1
bit without carry
200E RLC rotate content of A left by 1
bit without carry
200F RLC rotate content of A left by 1
bit without carry
2010 STA 3051 M[3051] A
2013 HLT END
EXPLANATION:
COUNTER:
• A counter is designed simply by loading appropriate number into one of the registers
and using INR or DNR instructions.
• Loop is established to update the count.
• Each count is checked to determine whether it has reached final number; if not, the
loop is repeated. C
TIME DELAY:
• Procedure used to design a specific delay.
• A register is loaded with a number, depending on the time delay required and then the
register is decremented until it reaches zero by setting up a loop with conditional jump
instruction.
Using 8-bit register as counter:
• Counter is another approach to generate a time delay. In this case the program size is
smaller. So in this approach we can generate more time delay in less space. The
following program will demonstrate the time delay using 8-bit counter.
• MVI B,FFH 7
• LOOP: DCR B 4
• JNZ LOOP 7/10
• RET 10
• Here the first instruction will be executed once, it will take 7 T-states. DCR C instruction takes
4 T-states. This will be executed 255 (FF) times. The JNZ instruction takes 10 T-states when
it jumps (It jumps 254 times), otherwise it will take 7 T-States. And the RET instruction takes
10 T-States.
• 7 + ((4*255) + (10*254)) + 7 + 10 = 3584. So the time delay will be 3584 * 1/3µs = 1194.66µs.
So when we need some small delay, then we can use this technique with some other values
in the place of FF.
• This technique can also be done using some nested loops to get larger delays. The following
code is showing how we can get some delay with one loop into some other
LXI B,FFFFH 10
LOOP: DCX B 6
MOV A,B 4
ORA C 4
JNZ LOOP 10 (For Jump),
RET 7(Skip)
10
• In the above table we have placed the T-States. From that table, if we calculate the time delay,
it will be like this:
• 10 + (6 + 4 + 4 + 10) * 65535H – 3 + 10 = 17 + 24 * 65535H = 1572857. So the time delay will
be 1572857 * 1/3µs = 0.52428s. Here we are getting nearly 0.5s delay.
• In different program, we need 1s delay. For that case, this program can be executed twice. We
can call the Delay subroutine twice or use another outer loop for two-time execution.
To perform a repetitive task, commonly used techniques are looping, counting, and indexing.
To add data bytes stored in memory, for example, the following steps are necessary.
LOOPING
• The programming technique used to instruct the microprocessor to repeat tasks is called
looping.
• This task is accomplished by using jump instructions.
• Define the task to be repeated is called Looping.
• A loop is set up by using either a conditional Jump or an unconditional Jump as illustrated in
Examples.
COUNTING:
INDEXING:
SETTING FLAGS:
CLASSIFICATION OF LOOPS:
1 Conditional loop
2.Unconditional loop
CONTINUOUS LOOP:
• Repeats a task continuously.
• A continuous loop is set up by using the unconditional jump instruction
• A program with a continuous loop does not stop repeating the tasks until the system is
reset.
CONDITIONAL LOOP:
Example:
• Steps to add ten bytes of data stored in memory locations starting ata given location and
display the sum.
• The microprocessor needs
Direct method:
In the direct method, the stack pointers address is loaded into the stack pointer register
directly.
LXI H, 8000H
SPHL
LXI H, 1234H
PUSH H
POP D
HLT
(2200H) = 67H
(2300H) = 6 x OAH + 7 = 3CH + 7 = 43H
Source Program:
Program
LXI H,5000
MOV A,M ;Initialize memory pointer
ADD A ;MSD X 2
MOV B,A ;Store MSD X 2
ADD A ;MSD X 4
ADD A ;MSD X 8
ADD B ;MSD X 10
INX H ;Point to LSD
ADD M ;Add to form HEX
INX H
MOV M,A ;Store the result
HLT
Result
Input:
Data 0: 02H in memory location 5000
Data 1: 09H in memory location 5001
Output:
Data 0: 1DH in memory location 5002
Program to find larger of two numbers
PROGRAM:
MEMORY MACHINE LABELS MNEMONICS OPERANDS COMMENTS
ADDRESS CODE
2000 21,01,25 LXI H,2501H Address of 1st number
in H-L pair.
2003 7E MOV A,M 1stnumber in
accumulator.
2004 23 INX H Address of 2nd number
in H-L pair.
2005 BE CMP M Compared 2nd number
with 1st number. Is the
2nd number> 1st?
2006 D2,0A,20 JNC AHEAD No, larger number is in
accumulator. Go to
AHEAD
2009 7E MOV A,M Yes, get 2nd number in
accumulator.
200A 32,03,25 AHEAD STA 2503H store larger number in
2503H
200D 76 HLT Stop the program.
Example-1:
Data:
2501→98 H
2502→87 H
Result:
2503→98 H and it is stored in the memory location 2503 H.
Program to find smaller of two numbers
PROGRAM:-
ADDRESS MACHINE LABELS MNEMONICS OPERANDS COMMENTS
CODES
2000 21,01,25 LXI H,2501H Address of the
1st number in H-
L pair
2003 7E MOV A,M 1st number in
accumulator
2004 23 INX H Address of the
2nd number in H-
L pair.
2005 BE CMP M Compare 2nd
number with 1st
.Is 1st number <
2nd number?
2006 DA,0A,20 JNC AHEAD Yes, smaller
number is in
accumulator. Go
to AHEAD.
2009 7E MOV A,M No ,get 2nd
number in
accumulator
200A 32,03,25 AHEAD STA 2503H Store smaller
number in
2503H.
200D 76 HLT stop
EXAMPLE:
DATA:
2501-84H
2502-99H
RESULT:
2503-84H
Program to find the largest number in a data array
PROGRAM:
MEMORY MACHINE LABELS MNEMONICS OPERANDS COMMENTS
ADDRESS CODES
2000 21,00,25 LXI H, 2500H Address for count in
H-L pair.
2003 4E MOV C,M Count in register C.
2004 23 INX H Address of the 1st
number in H-L pair.
2005 7E MOV A,M 1st number in
accumulator.
2006 OD DCR C Decrement count.
2007 23 INX H Address of next
number.
2008 BE CMP M Compare next
number with
previous maximum.
Is next number>
previous maximum.
2009 D2,0D,20 JNC AHEAD NO, Larger number
is in accumulator.
GO to the label
AHEAD.
200C 7E MOV A,M Yes, get larger
number in
accumulator.
200D 0D DCR C Decrement Count.
200E C2, 07, 20 JNZ LOOP
2011 32,04,25 STA 2504H Store result in
2504H.
2014 76 HLT Stop the Program.
Example-1:
Data:
2500→03
2501→98
2502→75
2503→99
Result: 2504→99
Program to find the smallest number in a data array
PROGRAM:
I/O addressing:
• Input/output (I/O) port addresses are used to communicate between devices and software.
• The I/O port address is used to send and receive data for a component.
• As with IRQs, each component will have a unique I/O port assigned.
• There are 65,535 I/O ports in a computer, and they are referenced by a hexadecimal address
in the range of 0000h to FFFF H.