LAB 3
INTRODUCTION TO
ASSEMBLY
PROGRAMMING
OBJECTIVE
To develop basic concepts of assembly programming
EQUIPMENT/ SOFTWARE REQUIRED
Keil uVision
GENERAL FORMAT OF ASSEMBLY
PROGRAM
ORG 0 void main (void)
{
END }
TO ACCESS GENERAL PURPOSE REGISTERS (R0-R7)
ORG 0
MOV R0, #30H ; R0 = 30H (H represent
; hexa decimal number)
MOV R3, #20H ; R3 = 20H
END
TO WRITE (OUTPUT) DATA ON I/O PORTS (P0-
P3)
ORG 0
MOV P0, #30H ; P0 = 30H
MOV R3, #20H ; R3 = 20H
MOV P1, R3 ; P1 = R3 = 20H
END
TO READ (INPUT) DATA FROM I/O PORTS (P0-
P3)
ORG 0
MOV R0, P1 ; R0 = P1
MOV R1, P3 ; R1 = P3
MOV P2, P0 ; P2 = P0
END
TO ACCESS INDIVIDUAL BITS OF I/O PORTS
(P0-P3)
ORG 0
SETB P1.0 ; Port 1, bit 0 = 1
CLR P1.6 ; Port 1, bit 6 = 0
SETB P2.3 ; Port 2, bit 3 = 1
SETB P2.7 ; Port 2, bit 7 = 1
CLR P3.6 ; Port 3, bit 6 = 0
END
ADDITION
ADD A, <scr-byte> ; Add scr-byte to ‘A’ and
; saves result in ‘A’
“scr-byte” can be Rn, Direct, Immediate data and @Ri
where n= 0,1….7 and i= 0 or 1
ADD A, #45 ; Add contents of A with 45
ADD A, R0 ; Add contents of A and contents of R0
ADD A, P0 ; Add contents of A and contents of P0
ADD A, 45H ; Add contents of A and contents of
45H, ; where 45H is a memory
location
ADDITION OF TWO NUMBERS
Suppose we want to add 33h and 46h and saves the
result in R7
ORG 0
MOV A, #33H ; One number must be in ‘A’
ADD A, #46H ; Add two numbers (result will be in A)
MOV R7, A ; Save the result in R7
END
EXERCISE I
a. Write a program which read port 1 and 2, add them
and then show the result on port 0.
b. Design proteus simulation for the above program
and test your program on it.
EXERCISE II
a. Write a program which read values from port1,
port2 and port3, add them and display result on port
0.
b. Design a proteus simulation for the above program.