Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Department of IT
University Institute of Engineering & Technology
Panjab University, Chandigarh
INTRODUCTION .......................................................................................................................... 4
EXPERIMENT-11: Add two 8-bit numbers along with considering the carry. ........................... 30
EXPERIMENT-13: Subtract two 8-bit numbers along with considering the borrow. ................. 35
EXPERIMENT-16: Add two 8-bit numbers and show the result in decimal number system. .... 43
INTRODUCTION
The first step in writing a program is to think very carefully about the problem that you want the
program to solve. In other words, ask yourself many times, “what do I really want this program
to do ? “ It is good idea to write down exactly what you want the program to do and the order in
which you want the program to do it. At this point
student should not write down program statements, should write the operations in general terms.
3.1 Define your Constant, Variables & Pointers for the program.
This is the standard procedure for all experiments, hence not required to write
separate procedure for all experiments. The list of experiments is attached.
Example: Move a block of 8-bit numbers from one place to other place.
Data(H): 37, A2, F2, 82, 57, 5A, 7F, DA, E5, 8B, A7, C2, B8, 10, 19, 98
DCR B
SAVE: This command is used to save the contents of specified block on to a audio cassette for
permanent storage.
LOAD: This command is opposite to save command. The contents of audio cassette block is
loaded (retrieved back) in the system RAM from a given DS (file name)
CODE: When this command key is pressed the address field remains blank, Data field shows a
dot indicating that it expects a code. User is provided with a table of codes, indicating the
meaning and Prerequisites of each code. User loads the appropriate code and executes it by
pressing EXEC. The monitor branches to the appropriate sub-routines pointed by the code.
STEP: Mere running a program with RUN is done whenever the program development is
complete i.e. to run a final working program. During the program development stage some sort
of aid to execute the part of program at a time and then test its success is required. The STEP
command helps you to do the above.
SINGLE STEPPING: to execute single instruction at a time, using STEP command. The
STEP command requires a start address, break address and the no.of times the br should
occur.
BREAK POINT: set a software breakpoint RST1. This software breakpoint can be done
using the RUN command. It requires RST1 (CFH) to be inserted to a location where you
want to break. The disadvantage of this method is that you have to insert and remove 'CF'
and you have to operate in the RAM area only.
VI: This key causes immediate recognition of RST 7.5 interrupt and control passes to location
003C in the monitor. This location has a jump to location 20CE in user RAM. You can put any
instruction or jump in 20CE to 20D0
- Interrupts must be enabled (EI) instruction.
- RST 7.5 must be unmasked (mask reset by SIM instruction)
RUN: This command is used to execute your programs or subroutines from a Specified address.
EXEC: Pressing EXEC will place the data field contents into the named register and terminate
the command.
REG: This command allows you to display and optionally modify the contents of 8085 CPU
registers. The various registers are A, B, C, D, E, F, I, H, L, SPH, SPL, PCH, PCL. (H – higher
byte, L – lower byte)
RES: On RES, the display shows MP – 85 as a sign on message, indicating that the monitor is
ready to accept a command. Pressing any non-command key generates “Err” message. After “-
Err” user can immediately give a valid command.
SET: It is used to SET the address of a required memory location. A dot in the address field of
display indicated that the entry will be displayed in the address field.
INC: Pressing INC, first time will shift the dot to the data field of display. Data field will show
the contents of the memory location pointed by the address set. One can modify or retain the data
field to any value.
DEC: DEC acts as similar to INC, except the address field is decremented, pointing to previous
memory locations.
0 – F: Hex Keypad
Crystal Frequency:
Study of Interrupts:
- RST 7.5 - VI
- RST 5.5 - 8279
- NMI - Counter 0 output
- RST 6.5 - Used to implement Single Step
- INTR - Used to implement Single Step
. (stop) . (stop)
GO (means run) SI
Enter the beginning address of prog Enter the beginning address of prog
Explanation:
This program finds the 1’s complement of an 8-bit number stored in memory location 3000H.
Let us assume that the operand stored at memory location 3000H is 85H.
The operand is moved to accumulator from memory location 3000H.
Then, its complement is found by using CMA instruction.
The result is stored at memory location 3001H.
Output:
Before Execution:
3000H: 85H
After Execution:
3001H: 7AH
Explanation:
This program finds the 2’s complement of an 8-bit number stored in memory location 3000H.
Let us assume that the operand stored at memory location 3000H is 85H.
The operand is moved to accumulator from memory location 3000H.
Then, its complement is found by using CMA instruction.
One is added to accumulator by incrementing it to find its 2’s complement.
The result is stored at memory location 3001H.
Output:
Before Execution:
3000H: 85H
After Execution:
3001H: 7BH
Explanation:
This program finds the 1’s complement of 16-bit number stored in memory 3000H-3001H.
There is no direct way to find 1’s complement of 16-bit number. Therefore, this can be
accomplished by finding the 1’s complement of two 8-bit numbers.
Let us assume that the operand stored at memory locations 3000H-3001H is 45H-6AH.
The operand is loaded into H-L pair from memory locations 3000H-3001H.
The lower-order is moved from register L to accumulator.
Its complement is found by using CMA instruction.
The result obtained is moved back to register L.
Then, the higher-order is moved from register H to accumulator.
Its complement is found by using CMA instruction.
The result obtained is moved back to register H.
Now, the final result is in H-L pair.
The result is stored from H-L pair to memory locations 3002H-3003H.
Output:
Before Execution: After Execution:
3000H: 45H 3002H: BAH
3001H: 6AH 3003H: 95H
Explanation:
This program finds the 2’s complement of 16-bit number stored in memory locations 3000H-
3001H.
There is no direct way to find 2’s complement of 16-bit number. Therefore, this can be
accomplished by finding the 1’s complement of two 8-bit numbers and then incrementing it
to get 2’s complement.
Let us assume that the operand stored at memory locations 3000H-3001H is 12H-05H.
The operand is loaded into H-L pair from memory locations 3000H-3001H.
The lower-order is moved from register L to accumulator.
Its complement is found by using CMA instruction.
The result obtained is moved back to register L.
Then, the higher-order is moved from register H to accumulator.
Its complement is found by using CMA instruction.
The result obtained is moved back to register H.
H-L pair is incremented to get 2’s complement.
Now, the final result is in H-L pair.
The result is stored from H-L pair to memory locations 3002H-3003H.
Output:
Before Execution: After Execution:
3000H: 12H 3002H: EEH
3001H: 05H 3003H: FAH
Explanation:
This program performs the left shift operation on an 8-bit number by one bit stored in
memory location 3000H.
Let us assume that the operand stored at memory location 3000H is 05H.
The operand is moved to accumulator from memory location 3000H.
Output:
Before Execution:
3000H: 05H
After Execution:
3001H: 0AH
Explanation:
This program performs the right shift operation on an 8-bit number by one bit stored in
memory location 3000H.
Let us assume that the operand stored at memory location 3000H is 04H.
The operand is moved to accumulator from memory location 3000H.
Then, shift right operation is done by using RAR instruction.
The result is stored at memory location 3001H.
Output:
Before Execution:
3000H: 04H
After Execution:
3001H: 02H
Explanation:
This program masks the lower nibble of an 8-bit number stored in memory location 3000H.
Let us assume that the operand stored at memory location 3000H is 45H.
The operand is moved to accumulator from memory location 3000H.
Then, AND operation of F0H is performed with accumulator. This results in the masking of
lower nibble.
The result is stored at memory location 3001H.
Output:
Before Execution:
3000H: 45H
After Execution:
3001H: 40H
Explanation:
This program masks the higher nibble of an 8-bit number stored in memory location 3000H.
Let us assume that the operand stored at memory location 3000H is 45H.
The operand is moved to accumulator from memory location 3000H.
Then, AND operation of 0FH is performed with accumulator. This results in the masking of
higher nibble.
The result is stored at memory location 3001H.
Output:
Before Execution:
3000H: 45H
After Execution:
3001H: 05H
AIM: WAP to add two 8-bit numbers without considering the carry
Explanation:
This program adds two operands stored in memory location 3000H and 3001H, without
considering the carry produced (if any).
Let us assume that the operands stored at memory location 3000H is 04H and 3001H is 02H.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
The two operands are added and the result is stored in accumulator.
H-L pair is again incremented and the result is moved from accumulator to memory location
3002H.
Output:
Before Execution:
3000H: 04H
3001H: 02H
After Execution:
3002H: 06H
Explanation:
This program adds two operands stored in memory location 3000H and 3001H, along with
considering the carry produced (if any).
Let us assume that the operands stored at memory location 3000H is FAH and 3001H is 28H.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
Register C is initialized to 00H. It stores the carry (if any).
The two operands stored in register A and B are added and the result is stored in accumulator.
Then, carry flag is checked for carry. If there is a carry, C register is incremented.
H-L pair is incremented and the result is moved from accumulator to memory 3002H.
H-L pair is again incremented and carry (either 0 or 1) is moved from register C to memory
location 3003H
Output:
Before Execution:
3000H: FAH
3001H: 28H
After Execution:
3002H: 22H
3003H: 01H
Explanation:
This program subtracts two operands stored in memory location 3000H and 3001H, without
considering the borrow taken (if any).
Let us assume that the operands stored at memory location 3000H is 05H and 3001H is 02H.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
The two operands are subtracted and the result is stored in accumulator.
H-L pair is again incremented and the result is moved from accumulator to memory location
3002H.
Output:
Before Execution:
3000H: 05H
3001H: 02H
After Execution:
3002H: 03H
Explanation:
This program subtracts two operands stored in memory location 3000H and 3001H, along
with considering the borrow taken (if any).
Let us assume that the operands stored at memory location 3000H is 05H and 3001H is 02H.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
Register C is initialized to 00H. It stores the borrow (if any).
The two operands stored in register A and B are subtracted and the result is stored in
accumulator.
Then, carry flag is checked for borrow. If there is a borrow, C register is incremented.
H-L pair is incremented and the result is moved from accumulator to memory location
3002H.
H-L pair is again incremented and borrow (either 0 or 1) is moved from register C to memory
location 3003H.
Output:
Before Execution:
3000H: 05H
3001H: 02H
After Execution:
3002H: 03H
3003H: 00H
AIM: WAP to add two 16-bit numbers without considering the carry.
Explanation:
This program adds two 16-bit operands stored in memory locations 3000H-3001H and
3002H-3003H, without considering the carry produced (if any).
Let us assume that the operands stored at memory locations 3000H-3001H is 02H-04H and
3002H-3003H is 04H-03H.
The H-L pair is loaded with the first 16-bit operand 0204H from memory locations 3000H-
3001H.
Then, the first 16-bit operand is moved to D-E pair.
The second 16-bit operand 0403H is loaded to H-L pair from memory locations 3002H-
3003H.
The two operands are added and the result is stored in H-L pair.
The result is stored from H-L pair to memory locations 3004H-3005H.
Output:
Before Execution: After Execution:
3000H: 02H 3004H: 06H
3001H: 04H 3005H: 07H
3002H: 04H
3003H: 03H
Explanation:
This program subtracts two 16-bit operands stored in memory locations 3000H-3001H and
3002H-3003H, without considering the borrow taken (if any).
Let us assume that the operands stored at memory locations 3000H-3001H is 08H-06H and
3002H-3003H is 05H-04H.
The H-L pair is loaded with the first 16-bit operand 0806H from memory locations 3000H-
3001H.
Then, the first 16-bit operand is moved to D-E pair.
The second 16-bit operand 0504H is loaded to H-L pair from memory locations 3002H-
3003H.
AIM: WAP to add two 8-bit numbers and show the result in decimal number system.
Explanation:
This program adds two operands stored in memory location 3000H and 3001H, and shows
the result in decimal number system.
Let us assume that the operands stored at memory location 3000H is 08H and 3001H is 05H.
After addition, instead of showing the result in hexadecimal as 0DH, it shows the result in
decimal as 13.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
Register C is initialized to 00H. It stores the carry (if any).
The two operands stored in register A and B are added and the result is stored in accumulator.
Output:
Before Execution:
3000H: 08H
3001H: 05H
After Execution:
3002H: 13
3003H: 00H
Explanation:
This program multiplies two operands stored in memory location 3000H and 3001H, using
successive addition method.
In successive addition method, the second operand is considered as counter, and the first
number is added with itself until counter decrements to zero.
Let us assume that the operands stored at memory location 3000H is 02H and 3001H is 05H.
Then, by using successive addition method, we get 02H + 02H + 02H + 02H + 02H = 0AH.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to register B from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register C from memory location 3001H to act as counter.
Accumulator is initialized to 00H.
Register B is added with accumulator and the result is stored in accumulator.
Register C (counter) is decremented by 1.
Then, counter is checked for zero. If it hasn’t become zero yet, then register B is again added
with accumulator, and counter is again checked for zero.
If counter becomes zero, then H-L pair is incremented and the result is moved from
accumulator to memory location 3002H.
Output:
Before Execution:
3000H: 02H
3001H: 05H
After Execution:
3002H: 0AH
Explanation:
This program finds the square of an 8-bit number stored in memory location 3000H.
The square of a number is found by multiplying it by itself.
Therefore, the number is added with itself and is also used as counter.
Let us assume that the operands stored at memory location 3000H is 03H.
Then, by using successive addition method, we get 03H + 03H + 03H = 09H.
Initially, H-L pair is loaded with the address of the operand.
The operand is moved to register B from memory location 3000H and then it is copied to
register C.
Accumulator is initialized to 00H.
Register B is added with accumulator and the result is stored in accumulator.
Register C (counter) is decremented by 1.
Then, counter is checked for zero. If it hasn’t become zero yet, then register B is again added
Output:
Before Execution:
3000H: 03H
After Execution:
3001H: 09H
Explanation:
This program compares the two operands to find the largest out of them.
After comparison, the largest of two must be in accumulator. If it is already in accumulator,
then it is moved to memory.
If it is not in accumulator, then first it is moved to accumulator and then from there, it is
moved to memory.
Let us assume that the operands stored at memory location 3000H is 25H and 3001H is 15H.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
The two operands are compared.
After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.
Carry flag is checked for carry. If there is a carry, it means B is greater than A and it is
moved to accumulator.
At last, H-L pair is incremented and the largest number is moved from accumulator to
memory location 3002H.
Output:
Before Execution:
3000H: 25H
3001H: 15H
After Execution:
3002H: 25H
Explanation:
This program compares two operands to find the smallest out of them.
After comparison, the smallest of two must be in accumulator. If it is already in accumulator,
then it is moved to memory.
If it is not in accumulator, then first it is moved to accumulator and then from there, it is
moved to memory.
Let us assume that the operands stored at memory location 3000H is 25H and 3001H is 15H.
Initially, H-L pair is loaded with the address of first memory location.
The first operand is moved to accumulator from memory location 3000H and H-L pair is
incremented to point to next memory location.
The second operand is moved to register B from memory location 3001H.
The two operands are compared.
After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.
Carry flag is checked for carry. If there is no carry, it means B is smaller than A and it is
moved to accumulator.
At last, H-L pair is incremented and the smallest number is moved from accumulator to
memory location 3002H.
Output:
Before Execution:
3000H: 25H
3001H: 15H
After Execution:
3002H: 15H
Based on the format followed for the above programs, perform the rest of the
experiments
Study the above instructions from the book. As per the common procedure specified in
this manual, perform the experiments.
AIM: Write a program to sort given 10 numbers from memory location 2200H in the ascending
order.
Source program :
MOV D, M
MOV M, A
DCX H
MOV M, D
JNZ START
AIM: Write a set of instructions to alter the contents of flag register in 8085.
AIM: Calculate the sum of series of numbers. The length of the series is in memory location
4200H and the series begins from memory location 4201H.
a. Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory location
4300H.
b. Consider the sum to be 16 bit number. Store the sum at memory locations 4300H and 4301H.
Program 1:
LDA 4200H
MOV C, A : Initialize counter
SUB A : sum = 0
LXI H, 420lH : Initialize pointer
BACK: ADD M : SUM = SUM + data
INX H : increment pointer
DCR C : Decrement counter
JNZ BACK : if counter 0 repeat
STA 4300H : Store sum
HLT :Terminate program execution
Output:
Before Execution:
4200H = 04H
4201H = 10H
4202H = 45H
4203H = 33H
4204H = 22H
After Execution:
Result = 10 +41 + 30 + 12 = H
4300H = H
Program 2
LDA 4200H
MOV C, A : Initialize counter
LXI H, 4201H : Initialize pointer
SUB A :Sum low = 0
MOV B, A : Sum high = 0
BACK: ADD M : Sum = sum + data
JNC SKIP
INR B : Add carry to MSB of SUM
SKIP: INX H : Increment pointer
DCR C : Decrement counter
JNZ BACK : Check if counter 0 repeat
STA 4300H : Store lower byte
MOV A, B
STA 4301H : Store higher byte
HLT :Terminate program execution
Output:
Before Execution:
4200H = 04H
420lH = 9AH
4202H = 52H
4203H = 89H
4204H = 3EH
After Execution:
Result = 9AH + 52H + 89H + 3EH = H
4300H = B3H Lower byte
4301H = 0lH Higher byte
AIM: Divide 16 bit number stored in memory locations 2200H and 2201H by the 8 bit number
stored at memory location 2202H. Store the quotient in memory locations 2300H and 2301H and
remainder in memory locations 2302H and 2303H.
Flowchart
Program:
LHLD 2200H : Get the dividend
LDA 2202H : Get the divisor
MOV C, A
LXI D, 0000H : Quotient = 0
BACK: MOV A, L
SUB C : Subtract divisor
MOV L, A : Save partial result
JNC SKIP : if CY 1 jump
DCR H : Subtract borrow of previous subtraction
SKIP: INX D : Increment quotient
MOV A, H
CPI, 00 : Check if dividend < divisor
JNZ BACK : if no repeat
MOV A, L
CMP C
JNC BACK
SHLD 2302H : Store the remainder
XCHG
SHLD 2300H : Store the quotient
HLT : Terminate program execution
Output:
Before Execution:
(2200H) = 60H
(2201H) = A0H
(2202H) = l2H
After Execution:
Result = A060H/12H = 8E8H Quotient and 10H remainder
(2300H) = E8H
(2301H) = 08H
(2302H= 10H
(2303H) 00H
AIM: Find the number of negative elements (most significant bit 1) in a block of data. The
length of the block is in memory location 2200H and the block itself begins in memory location
2201H. Store the number of negative elements in memory location 2300H
Flowchart
Program:
LDA 2200H
JZ SKIP : If MSB = 1
MOV A, B
Output:
Before Execution:
(2200H) = 04H
(2201H) = 56H
(2202H) = A9H
(2203H) = 73H
(2204H) = 82H
After Execution:
Source program :
LDA 2200H
MOV A, M
SKIP: INX H
DCR C
JNZ BACK
Output:
Before Execution:
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
After Execution:
Result = (2202H) = A9H
AIM: WAP to count number of l's in the contents of D register and store the count in the B
register.
Flowchart
Source program :
MVI B, 00H
MVI C, 08H
MOV A, D
BACK: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ BACK
HLT
Output:
Before Execution:
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
After Execution:
AIM: A block of data consisting of 256 bytes is stored in memory starting at 3000H. This block
is to be shifted (relocated) in memory from 3050H onwards. Do not shift the block or part of the
block anywhere else in the memory.
Two blocks (3000 - 30FF and 3050 - 314F) are overlapping. Therefore it is necessary to transfer
last byte first and first byte last.
Source Program:
Reference: www.eazynotes.com