Subject Code: 3140707 EnrollmentNo:230430116142
Experiment No: 5
Date:
Write following 8085 assembly language programs with output.
a. To add two arrays of five 8-bit values and store result in third array.
b. To store sum of unpacked BCD numbers from packed BCD numbers.
c. To store an ASCII value of each Hex digits.
d. To set an MSB of an 8-bit values if it has even no. of 1’s.
e. To reverse an array of ten 8-bit values using subroutine.
f. Find factorial of given 8-bit value.
g. To perform division of 16-bit number by 8-bit number.
Competency and Practical Skills: understanding of working of registers, instruction set
Relevant CO: CO2 Objectives:
a) To understand working of the 8085 instruction set.
b) To understand the behavior of the flags and how to use flag .
Equipment/Instruments: Personal Computer, GNUsim8085
Explanation:
a. To add two arrays of five 8-bit values and store result in third array.
JMP START ; Jump on start
DATA1: DB 01, 02, 03, 04, 05 ; First Array
DATA2: DB 06, 07, 08, 09, 10 ; Second Array
SUM: DS 5 ; Third array to store sum
COUNT: DB 05 ; Counter value
START: LXI B, DATA1 ; Load address of DATA1 in BC reg. pair
LXI H, DATA2 ; Load address of DATA2 in HL reg. pair
LXI D, SUM ; Load address of SUM in DE reg. pair
LOOP: LDAX B ; Start of LOOP; Read values from DATA1
ADD M ; Add values from DATA2
STAX D ; Store sum in SUM
INX B ; Increment location of DATA1
INX H ; Increment location of DATA2
INX D ; Increment location of SUM
LDA COUNT ; Load count in A register
DCR A ; Decrement count value in A register
STA COUNT ; Store count from A register
JNZ LOOP ; Check Zero flag, if it is not set go back to LOOP ;
HLT Stop the execution
Output:
IT Department, SSEC , Bhavnagar 30 Batch: B7
Subject Code: 3140707 EnrollmentNo:230430116142
b. To store sum of unpacked BCD numbers from packed BCD numbers.
JMP START ; Jump on start
PACKBCD: DB 26H ; Packed BCD number
SUM: DB 00H ; To store sum of digits of Packed BCD number
START: LDA PACKBCD ; Load Packed BCD number to A register
MOV B, A ; Copy number to B register
ANI 0FH ; Perform AND operation with 0Fh to clear first four bits
MOV C, A ; Move last hex digit from A to C register
MOV A, B ; Move Packed BCD number to A register
ANI 0F0H ; Perform AND operation with 0F0h to clear last four bits
RLC ; Rotate A register value 1-bit left
RLC ; Rotate A register value 1-bit left
RLC ; Rotate A register value 1-bit left
RLC ; Rotate A register value 1-bit left (First hex digit is in last
position)
ADD C ; Add another digit from C register
STA SUM ; Store the sum on SUM
HLT ; Stop the execution
IT Department, SSEC , Bhavnagar 31 Batch: B7
Subject Code: 3140707 EnrollmentNo:230430116142
; If carry flag is set take jump on next
; Add 30H to the value in A register
IT Department, SSEC , Bhavnagar 32 Batch: B7
Subject Code: 3140707 EnrollmentNo:230430116142
d. To set an MSB of an 8-bit values if it has even no. of 1’s.
JMP START ; Jump on start
NUM: DB 06H ; Store 8-bit number in NUM
RESULT: DB 00H ; To store result
START: LDA NUM ; Load NUM in A register
MOV D, A ; Copy NUM from A register to D
MVI B, 00H ; Clear B register value to store count of 1’s
MVI C, 07H ; Store 07 in C register to rotate value 7 times right
LOOP: RRC JNC ; Rotate A register value right
NEXT ; If carry flag is not set, take a jump on NEXT
INR B ; If carry flag is set, increment value of B register
NEXT: DCR C ; Decrement counter value in C register
JNZ LOOP ; If Zero flag is not set, take a jump on LOOP
MOV A, B RRC ; Move count of 1’s to A register
JC NEXT1 ; Rotate right to check LSB of count of 1’s
MOV A, D ; if Carry flag is set, take jump on NEXT1 (no. of 1’s are odd)
ORI 80H ; Restore NUM in A register
; Perform OR operation with 80H(10000000) to set MSB in
NEXT1: STA RESULT NUM
HLT ; Store the result
; Stop the execution
Output:
IT Department, SSEC , Bhavnagar 33 Batch: B7
Subject Code: 3140707 EnrollmentNo:230430116142
; Subroutine Load values from the location in DE
Output:
IT Department, SSEC , Bhavnagar 34 Batch: B7
SubjectCode: 3140707 EnrollmentNo:230430116142
f. Find factorial of given 8-bit value.
JMP START ; Jump on start
NUM: DB 05H ; Store 8-bit number in NUM
ANS: DB 00H ; To store the
START: LDA factorial ; Load
NUM NUM to A register
MOV B, A ; Move value to B from A reg.
MVI D, 01H ; Set value of D reg. to 01
FACT: CALL ; Call subroutine
MUL ; Decrement B register value
DCR B ; If Zero flag is not jump on FACT
JNZ FACT ; Copy value of D reg. to A
MOV A, D ; Store the result in ANS
STA ANS
HLT ; Stop the execution
MUL: MOV E, ; Subroutine Move value of B reg to A
B ; Clear value of A reg
XRA A ; Add value of D reg
ML: ADD D ; Decrement value of E reg.
DCR E ; If Zero flag is not set, take jump
JNZ ML on ML ; Store sum in D reg.
MOV D, A ; Return from Subroutine
RET
Output:
g. To perform division of 16-bit number by 8-bit number.
IT Department, SSEC , Bhavnagar 35 Batch: B7
EnrollmentNo: 230430116142
SubjectCode: 3140707
LXI H, 8000H ; Point 8000H address
MOV A, M ; Store the lower order byte
INX H ; Increase the HL pair to point
MOV B, M ; Store the higher order byte
INX H ; Increase the HL pair to point next loc
MOV C, M ; Load the denominator
INR B ; Increase B register
LXI H, 0000H ; Store 0000Hinto HL pair
LOOP: SUB C ; Subtract C from acc
JC SKIP ; Jump to SKIP when CY = 1
INCR: INX H ; Increase quotient part
JMP LOOP ; Jump to LOOP
SKIP: DCR B ; Decrease B
JZ STORE ; Jump to STORE when Z = 1
JMP INCR ; Jump to INCR
STORE: ADD C ; Add C with Acc
XCHG ; swap DE and HL pair contents
LXI H, 8050H ; Load the destination address
MOV M, E ; Store the lower order quotient
INX H ; Increase HL pair
MOV M, D ; Store the higher order quotient
INX H ; Increase HL pair
MOV M, A ; Store the remainder
HLT ; Stop the execution
Output
IT Department, SSEC , Bhavnagar 36 Batch: B7
Subject Code: 3140707 EnrollmentNo:230430116142
Conclusion:
Quiz:
1) Explain XCHG instruction.
2) What is the purpose of the DAA instruction?
IT Department, SSEC , Bhavnagar 37 Batch: B7
Subject Code: 3140707 EnrollmentNo:230430116142
3) Explain JNC and JNZ instruction.
Suggested Reference:
1. [Link], “Microprocessor Architecture, Programming and Applications with 8085A”,
Penram International
Rubric wise marks obtained:
Knowledge of Programming Team work (2) Communication Ethics (2)
subject (2) Skill Skill (2)
Good Average Good Average Good Satisfactory Good Satisfactory Good Average
(2) (1) (2) (1) (2) (1) (2) (1) (2) (1)
Rubrics 1 2 3 4 5 Total
Marks
IT Department, SSEC , Bhavnagar 38 Batch: B7