Lab 4
Lab 4
Lab: 4
Familiarization with branching and stack operations
805A 33
805B 44
Run this program in single step mode and examine the reg. pair HL before and after the execution of the instruction
XTHL. Also note the data at 805A and 805B after the program execution.
The flags contents can be changed if the value to be made in the flags register is first stored in the lower part of reg.
pair and pushed to the stack. And if the stack content is popped in the PSW, the content in the reg. pair is transferred in
the accumulator and flags.
Assignment
1. Write a program to set zero and parity flags and reset other flags.
2 Write a program to set auxiliary flag and reset parity flag without affecting other flags.
Jump instructions are used to transfer the control of the program to some other location instead of the next instruction.
These instructions are used as follows
JMP 16-bit Unconditional Jump JM 16-bit Jump on minus
JNZ 16-bit Jump on no zero MP 16-bit Jump on plus
JZ 16-bit Jump on zero JPE 16-bit Jump on parity even
JNC 16-bit Jump on no carry JPO 16-bit Jump on parity odd
JC 16-bit Jump on carry
JMP instruction is the unconditional jump and Jx instruction is the conditional jump. Conditional jumps use the flag
conditions for the branching.
PCHL instruction copies the content of the HL reg. pair into PC, i.e., this command branches the control to the
location specified by HL reg. pair.
Looping is done with the conditional jump instruction. When we have to insert delay we can use the loops for the
delay.
Example 3: Load and run the following program
8000 MVI A, 80H
8002 OUT 43H
8004 MVI A, 01
8006 OUT 40
8008 RLC
8009 JMP 8006
800C RST 5
Run this program in single step mode and note the output in port A and note the sequence of the execution of the
instructions. Does the program terminate? Now insert a delay loop and run the program in full speed.
Example 4: Load the following program
8000 MVI A, 80H 800A INR A
8002 OUT 43H 800B DCR B
8004 MVI A, 01 800C JNZ 8008
8006 MVI B, FF 800F RST 5
8008 OUT 40
Run this program in single step mode and view the content of the program. Does the program terminate now? Explain
how this loop works. Now insert a delay loop and run the program in full speed. Can you see the output?
Example 5: Load the following program
8050 MVI A, 80
8052 OUT 43
8054 MVI A, FF
8056 LXI H, 8080
8059 PCHL
805A RST 5
Also enter
8080 DCR A
8081 OUT 42
8083 JMP 8080
Run this program in single step mode and see what happens when PCHL and JMP instructions are executed.
Assignment
3 Write a program to count the no of bits that are 1 in register A.
4 Write a program to add nos. from one to fifty and display the 16 bit result at port A & B.
5 Write a program that will count up from 00 to FF at port A. Be sure to use PCHL command.
2
Lab Sheet for Microprocessor for BEX/BCT/BEL @ IOE, Pulchowk Campus
Conditional calls are useful if the call is to be occurred if some condition is satisfied. The conditional calls occur
depending upon the flag conditions.
Example 7: Load the following program
8000 MVI A, 80 8020 MVI A, FF 8030 MVI A, 01
8002 OUT 43 8022 OUT 42 8032 OUT 41
8004 LDA 8050 8024 RET 8034 RET
8007 CPI 01
8009 CZ 8020
800C CNZ 8030
800F RST 5
8050 DATA FF
Run this program and examine where the jump occurs (at 8020 or at 8030). Change the data at 8050 with 01 and see
where the jump occurs. In the above two cases what output do you see in the port.
Conditional return instructions are used in returning from the subroutines when some condition occurs.
Example 8: Load the following program
8000 MVI A, 80 8020 LXI B, FFFF
8002 OUT 43 8023 DCR B
8004 MVI A, 01 8024 JNZ 8023
8006 OUT 40 8027 DCR C
8008 CALL 8020 8028 RZ
800B RLC 8029 JMP 8023
800C JMP 8002
Run this program in full speed and explaining what is happening.
Assignments
6 Write a program to transfer the data at 8020 to 8030 if the data is greater than 127. You can assume data yourself.
7 Write a program to rotate the data 3C in port A. Call a delay subroutine for the delaying.
8 Write a program that will check whether the bit D6 of a number stored at 8123 is 0 and its bit D3 is 1. If the
condition satisfies display the number.
9 Write a program that will check whether the number in reg. B is even or not. If the number is even display it in
port A.