M.
Harini 19BEC1459
LAB 2
ASSEMBLY PROGRAMMING WITH ARITHMETIC INSTRUCTION OF 8051
AIM: To write assembly programs to perform basic arithmetic operations using kiel
software.
SOFTWARE USED:
Kiel 5
SAMPLE PROGRAMS:
Program-1:
Write an 8051 ASM program to perform addition of two 8-bit numbers 97H and 76H
and store the result at address location 55H.
ASSEMBLY CODE FOR PROGRAM-1:
ORG 0000H
MOV A, #97H ; A = 97H
ADD A, #76H ; A = A+76H = 97H + 76H
MOV 55H, A
END
Program-2:
Write an 8051 ASM program to perform subtraction of two 8-bit numbers 76h and 79H
and store the result at address location 55H.
ASSEMBLY CODE FOR PROGRAM-2:
ORG 0000H
MOV A, #97H ; A = 97H
SUBB A, #76H ; A = A-76H = 97H - 76H = 21H
MOV 55H, A
END
Program-3:
Write an 8051 ASM program to perform addition of two 16-bit numbers. The numbers
are 3CE7H and 388DH. Place the sum in R7 and R6; R7 holds higher byte and R6 should
have the lower byte.
ASSEMBLY CODE FOR PROGRAM-3:
ORG 0000H
MOV A, #0E7H ; A = E7H
ADD A, #8DH ; A = A + 8DH = E7H+8D = 74H AND SET CARRY AS 1
MOV R6, A ; R6 = 74H
MOV A, #3CH ; A = 3CH
ADDC A, #3BH ; A = A+3B+C=78H AND THERE IS BNO CARRY THEREFORE C=0
MOV R7, A ; R7 = 78H
END
Program-4:
Write an 8051 ASM program to perform subtraction of two 16-bit numbers. The
numbers are 2762H and 1276H. Place the sum in R7 and R6; R6 should have the lower
byte.
ASSEMBLY CODE FOR PROGRAM-4:
ORG 0000H
MOV A, #62H ; A = 62H
SUBB A, #76H ; A = A - 76H = 62H=76H = ECH AND BORROW IS GENERATED
THEREFORE C = 1
MOV R6, A ; R6 = ECH
MOV A, #27H ; A = 27H
SUBB A, #12H ; A = A- 12H - C = 27H-12H-1 = 14H
MOV R7, A ; R7 = 14H
END
Program-5:
Write an 8051 ASM program to perform multiplication of two 8-bit numbers present in
data memory address location 33H and 34H and store the result in 36H(higher byte)
and 35H(lower byte).
ASSEMBLY CODE FOR PROGRAM-5:
ORG 0000H
MOV A, 33H ; A = [33H] = 05H and FF; FETCH THE CONTENT OF MEMORY
LOCATION 33H
MOV B, 34H ; B = [34H] = 15H and FF; FETCH THE CONTENT OF MEMORY
LOCATION 34H
MUL AB ; A = A*B = 05H*15H=69H
MOV 36H, B
MOV 35H, A
END
Program-6:
Write an 8051 ASM program to perform division of two 8-bit numbers present in data
memory address location 33H and 34H and store the result in 36H(higher byte) and
35H(lower byte).
ASSEMBLY CODE FOR PROGRAM-6:
ORG 0000H
MOV A, 33H ; A = [33H] = FFH; FETCH THE CONTENT OF MEMORY LOCATION 33H
MOV B, 34H ; B = [34H] = FFH; FETCH THE CONTENT OF MEMORY LOCATION 34H
DIV AB ; A=A/B=FFH/FFH=1H
MOV 36H, B
MOV 35H, A
END
SNAPSHOT OF PROGRAM -1:
SNAPSHOT OF PROGRAM -2:
SNAPSHOT OF PROGRAM -3:
SNAPSHOT OF PROGRAM -4:
SNAPSHOT OF PROGRAM -5:
SNAPSHOT OF PROGRAM -6:
CHALLENGING TASK 1:
Problem: Write an 8051 ASM program to solve the following mathematical equation:
(a-b)^2 = a^2 + b^2 - 2ab
Where “a” and “b” are values at memory location 60H and 61H and store the result in
60H(high byte) and 61H(low byte).
PROGRAM IN ASSEMBLY LANGUAGE:
ORG 0000H
MOV A, 60H ; A=[60H]= 12H; FETCH THE CONTENT OF MEMORY LOCATION
60H
MOV B, 61H ; B=[61H]= 08H; FETCH THE CONTENT OF MEMORY LOCATION
61H
SUBB A, B ; A = A - B = 12H - 08H = AH
MOV B, A ; B = 04H
MUL AB ; A = A*B = AH*AH = 64H
MOV 61H, B
MOV 60H, A
END
SNAPSHOT OF PROGRAM:
Challenging Task 2:
Program in assembly language:
ORG 0000H
MOV A, #25H
ADD A, #36H
SUBB A, #12H
MOV B, #18H
DIV AB
END
Snapshot: