Assignment 1
Assignment 1
IN: Input from port Read a data byte from an input device
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.
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
Arithmatic Operations
This is a 1-byte instruction. It subtracts the contents of register R from the content of accumulator
6. DCR R
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
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
MVI B,30H
MVI c,39H
MOV a,b
SUB c
OUT 01H
HLT
Answer: F7H
Logic Operation
1. ANA R
Logically AND the contents of the register R with the contents of the accumulator.
3. ORA R
4. XRA R
5. XRI: 8 bit
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:
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
MVI A,15H
CMA
OUT 01h
Hlt
Answer: EAH
Jump Instructions
1. Unconditional Jump
JMP 16 bit
Prog1.
START: IN 00H
OUT 01H
JMP START
Conditional Jumps
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.