1.
Writing small data transfer programs
MOV: MOVE copy a data byte
MVI: MOV Immediate Load a data byte directly
OUT: Output to a port send a data byte to an output device
IN: Input from port Read a data byte from an input device
HLT: Halt Stop processing and wait
NOP: No Operation Do not Perform any Operation
MOV RD, RS move 1-byte instruction, copies data from source register to destination register.
MVI R,8-bit move immediate: this is a 2- byte instruction, loads 8 bits of 2nd byte into the register
specified
OUT: 8bit port address output to a port, a 2-byte instruction, sends the contents of the accumulator to
the output port specified in the second byte
IN 8-bit port address Input from port, this is a 2- byte instruction, accepts data from input port
specified in the second byte and loads into the accumulator.
HLT: Halt is a 1- byte instruction, the processor stops executing and enters wait state. The address bus
and data bus are placed in high impedance state. No register contents are affected.
NOP: No operation, this is a 1 -byte instruction. No operation is performed.
Prog1: Load the accumulator A with the data byte 82H and save the data in register B.
MVI A,82H
MOV B, A
Result
Prog2.: Load the hexadecimal number 37H in register B and display the number at the output port
labeled Port1(01H).
MVI B,37H
Mov A,B
OUT 01H
HLT
Result: at I/O Ports address 01 H has data 55H.
Arithmatic Operations
1. ADD R add the contents of a register
add 1 byte instruction , add the contents of register to contents of accumulator.
2. ADI, 8 bit
add immediate. This is a 2 byte instruction, adds the second byte to the contents of the
accumulator
3. SUB R subtract the contents of register
This is a 1-byte instruction. It subtracts the contents of register R from the content of accumulator
4. SUI: subtract immediate subtract 8 bit data
This is a 2- byte instruction. It subtracts the second byte from the contents of accumulator.
5. INR R
Increment: 1 byte instruction.
Increases the contents of register R by 1
6. DCR R
Decrement : 1 byte instruction
Decreases the contents of register R by 1.
Prog3: The contents of accumulator are 93H and the contents of register C are B7H. Add both contents.
MVI A,93H
MVI C,0B7H
ADD C
OUT 01H
HLT
ANSWER: 4AH(74)
Prog4: Add the number 35h directly to the sum in previous program.
MVI A,93H
MVI C,0B7H
ADD C
ADI 35H
OUT 01H
HLT
Prog5. Let accumulator hold the data byte FFH. Add 01H and then increment the content of accumulator
MVI A,0FFH
ADI 01H
INR A
OUT 01H
HLT
Prog 6. Write a program
(i) To load the number 8BH in register D.
(ii) Load the number 6FH in register C
(iii) Increment the contents of register C by one.
(iv) Add the contents of registers C and D and display the sum at the output Port 01H.
MVI D,8BH
MVI C,6FH
MVI A,0H
INR C
ADD C
ADD D
OUT 01H
HLT
Answer: FBH
Prog7. Register B has 65H and the accumulator has 97H. Subtract the contents of register B from the
contents of the accumulator.
MVI B,65H
MVI A,97H
SUB B
OUT 01H
HLT
Answr: 32H
Prog8. Write a program
Load the number 30H in register B and 39H in register C.
Subtract 39H from 30H
Display output at Port address 01H
MVI B,30H
MVI c,39H
MOV a,b
SUB c
OUT 01H
HLT
Answer: F7H
Logic Operation
1. ANA R
Logical AND with accumulator
This is a 1-byte instruction.
Logically AND the contents of the register R with the contents of the accumulator.
CY is reset and AC is set.
2. ANI 8 bit
AND immediate with accumulator
This is a 2 byte instruction
Logically and the 2nd byte with the contents of accumulator
CY is reset and AC is set.
3. ORA R
Logically OR with accumulator
This is a 2 byte instruction
Logically OR the 2nd byte with the contents of accumulator.
4. XRA R
Logically Exclusive OR with Accumulator
This is a 1 byte instruction
Ex-OR the contents of register R with the contents of accumulator.
5. XRI: 8 bit
Exclusive OR the 2nd byte with the contens of accumulator.
6. CMA Complement accumulator
This is a 1 byte instruction that complements the contents of the accumulator
No flags are affected.
Prog1. Input data through input port 03H and mask the data by using AND operation and send the result
to output port 01H
IN 03H
ANI 80H
OUT 01h
HLT
Answer : 80H
Prog2.: Assume register B holds 93H and the accumulator holds 15H. Show the results of the instructions
(i)ORA B
(ii)XRA B
(iii)CMA
Answer:
(i) MVI B,93H
MVI A,15H
ORA B
OUT 01h
Hlt
Answer: 97H
(II) xra b
MVI B,93H
MVI A,15H
XRA B
OUT 01h
Hlt
ANS: 86h
(III) MVI B,93H
MVI A,15H
CMA
OUT 01h
Hlt
Answer: EAH
Jump Instructions
1. Unconditional Jump
JMP 16 bit
JUMP is a 3 byte instruction
The second and third byte specify the 16- bit memory address.
Prog1.
START: IN 00H
OUT 01H
JMP START
Conditional Jumps
JC 16 bit Jump on Carry if result generates carry and CY=1.
JNC 16bit Jump on no carry(CY=0)
JZ 16 bit Jump on zero (if result is zero and Z=1)
JNZ 16 bit Jump on no zero (z=0)
Assignment
1. Specify the contents of the registers and flag status as the following instructions are executed
Registers: A, B, C, D
flags: S, Z, C, Y
MVI A,00H
MVI B,F8H
MOV C,A
MOV D,B
HLT
2. Write instructions to load the hexadecimal number 65H in register C and 92H in the
accumulator A. Display the number 65H at Port 0 and 92H at Port1.
3. Write instructions to read the data at input PORT 07H and at PORT 08H. Display the input data
from PORT 07H at output PORT 00H, and store the input data from PORT 08H in register B.
4. Specify the output at PORt1 if the following program is executed
MVI B,82H
MOV A, B
MOV C, A
MVI D,37H
OUT PORT 1
HLT
5. Specify the register contents and the flag status as the following instructions are executed.
MVI A,F2H
MVI B,7AH
ADD B
OUT PORT0
HLT
6. Specify the register contents and the flag status as the following instructions are executed.
MVI A,5EH
ADI A2H
MOV C,A
HLT
7. Write a program using the ADI instruction to add the two hexadecimal numbers 3AH and 48H
and to display the answer at output port.
8. WAP to
a. Clear the accumulator
b. Add 47H
c. Subtract 92h
d. Add 64h
e. Display the result after subtracting 92H and after adding 64H.
9. What is the output at PORT1(01H) when the following instructions are executed?
MVI A,8FH
ADI 72H
JC DSPLAY
OUT PORT1
HLT
DSPLAY: XRA A
OUT PORT1
HLT
In problem 7. Replace the instruction ADI 72H by instruction SUI 67H and specify the output.
Q8. Write the instructions to clear the CY flag, to load number FFH in register C, and to add 01
to C. If the CY flag is set display 01 at an output port otherwise display the contents of register
C.