Lab 2
Lab 2 : PROGRAMMING BASED ON ARITHMETIC AND LOGICAL OPERATIONS
OBJECTIVES
To familiar with the use of arithmetic and logical instruction sets of 8085
PRELAB
Read the instructions related to arithmetic and logical operations in detail.
OVERVIEW OF ARITHMETIC & LOGICAL INSTRUCTIONS
Opcode | Operand | Description |
ADD | R | Adds the content of register R to the content of the accumulator |
ADI | 8-bit | Adds the 8-bit Data to the content of the accumulator |
SUB | R | Subtracts content of register R from the content of the accumulator |
SUI | 8-bit | Subtracts 8-bit Data from the content of the accumulator |
INR | R | Increases the content of register R by 1 |
DCR | R | Decreases the content of register R by 1 |
ADD | M | Adds the content of memory location specified by register pair HL to the content of the accumulator |
SUB | M | Subtracts the content of memory location specified by register pair HL from the content of the accumulator |
INR | M | Increment the content of the memory location specified by register pair HL by 1. |
DCR | M | Decrement the content of the memory location specified by register pair HL by 1. |
ANA | R | Logically ANDs the content of register R with the content of accumulator |
ANI | 8-bit | Logically ANDs the 8-bit data with the content of the accumulator |
ORA | R | Logically ORs the content of register R with content of the accumulator |
ORI | 8-bit | Logically ORs the 8-bit data with the content of the accumulator |
XRA | R | Exclusive-ORs the contents of register R with the content of accumulator |
XRI | 8-bit | Exclusive-ORs the 8-bit data with the content of the accumulator |
CMA | ㅤ | Complements the content of the accumulator |
RLC | ㅤ | Rotate accumulator left |
RAL | ㅤ | Rotate accumulator left through carry |
RRC | ㅤ | Rotate accumulator right |
RAR | ㅤ | Rotate accumulator right through carry |
CMP | R/M | Compare register or memory with accumulator |
CPI | 8-bit | Compare 8-bit data with accumulator |
Programs
1. Write an assembly language program for the adding of two 8-bits numbers stored at memory location 2100H and 2101H respectively. Store the result at memory location 2102H.
LXI H, 2100H
MOV A, M
INX H
ADD M
INX H
MOV M, A
HLT
2. Write an ALP to add two sixteen bit numbers and store 16-bit result.
LXI H, 2100H
MOV A, M
INX H
MOV B, M
INX H
MOV C, M
INX H
MOV D, M
MOV A, B
ADD C
MOV E, A
MOV A, D
ADC B
MOV H, A
LXI H, 2104H
MOV M, E
INX H
MOV M, H
HLT
3. Subtract two 8-bit numbers at 2100H and 2101H. Save the result at location 2102H.
LXI H, 2100H
MOV A, M
INX H
SUB M
INX H
MOV M, A
HLT
4. Write a program to subtract two 16-bit numbers and store the result.
LXI H, 2100H
MOV A, M
INX H
MOV B, M
INX H
MOV C, M
INX H
MOV D, M
MOV A, B
SUB C
MOV E, A
MOV A, D
SBB B
MOV H, A
LXI H, 2104H
MOV M, E
INX H
MOV M, H
HLT
5. Write ALP to find one’s complement of data 0x55 stored at memory location
LXI H, 2100H
MOV A, M
CMA
MOV M, A
HLT
6. Write an ALP to find two’s complement of data 0x45 stored at memory location
LXI H, 2100H
MOV A, M
CMA
INR A
MOV M, A
HLT
7. Write an ALP to unpacked data stored at location 2100H. Save result at memory locations 2101H and 2102H.
LXI H, 2100H
MOV A, M
ANI 0F0H
RRC
RRC
RRC
RRC
MOV B, A
MOV A, M
ANI 0F0H
MOV M, B
INX H
MOV M, A
HLT
- Write a program that takes two nibbles from 2100H, 2101H and combines to form byte. The nibbles from 2100 are to be taken as most significant nibble.
8. Write a program that takes two nibbles from 2100H, 2101H and combines to form byte. The nibbles from 2100 are to be taken as most significant nibble.
ORG 0000H
MVI H, 21H
MVI L, 00H
MOV A, M
ANI 0F0H
MOV B, A
INX H
MOV A, M
ANI 0F H
ORA B
STA 2200H
HLT