0% found this document useful (0 votes)
46 views

LAB 3 Introduction To Assembly Programming1

This document provides an introduction to assembly programming, explaining how to access registers and I/O ports, perform arithmetic operations like addition, change register banks, and set or clear individual bits on ports. It also includes examples of assembly code to add two numbers, read from and write to ports, and exercises for students to write programs that read multiple ports, perform additions, and display results on ports.

Uploaded by

Jawaad Asim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

LAB 3 Introduction To Assembly Programming1

This document provides an introduction to assembly programming, explaining how to access registers and I/O ports, perform arithmetic operations like addition, change register banks, and set or clear individual bits on ports. It also includes examples of assembly code to add two numbers, read from and write to ports, and exercises for students to write programs that read multiple ports, perform additions, and display results on ports.

Uploaded by

Jawaad Asim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

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
HOW TO CHANGE REGISTER BANK
We have 2 bits in PSW register RS0 and RS1. To
select any register bank we have following four
combinations

RS1 RS0 Active Bank Number


0 0 0
0 1 1
1 0 2
1 1 3
HOW TO CHANGE REGISTER BANK

ORG 0
; By default bank 0 is active

SETB RS0
CLR RS1 ; Register bank 1 is active now

CLR RS0
SETB RS1 ; Register bank 2 is active now

SETB RS0
SETB RS1 ; Register bank 3 is active now

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. Then saves value of port1 in R0-
bank 0, value of port2 in R1-bank 1 and value of
port3 in R2-bank 2
b. Now add above values and display result on port 0.
c. Design a proteus simulation for the above program.

You might also like