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

2. 8051 Assembly Programming_Practice

The document provides examples of 8051 assembly programming, covering operations such as addition, subtraction, multiplication, division, and logical operations. It includes code snippets demonstrating how to manipulate data in registers and the accumulator, along with expected outcomes for each operation. Additionally, it discusses the Program Status Word (PSW) and memory operations, illustrating how to store and retrieve data in the 8051 architecture.

Uploaded by

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

2. 8051 Assembly Programming_Practice

The document provides examples of 8051 assembly programming, covering operations such as addition, subtraction, multiplication, division, and logical operations. It includes code snippets demonstrating how to manipulate data in registers and the accumulator, along with expected outcomes for each operation. Additionally, it discusses the Program Status Word (PSW) and memory operations, illustrating how to store and retrieve data in the 8051 architecture.

Uploaded by

alvin john
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

8051 Assembly Programming

Practice
Addition
ORG 0000h
MOV R0, #03H // move the value 3 to the egister R0//
MOV A, #05H // move the value 5 to accumulator A//
Add A, R0H // add A value with R0 value and stores the
result in A//
END
What will be the content in A?
A= 03+05 = 08H
ORG 0000h
MOV R0, #03H // move the value 3 to the egister R0//
MOV A, #05H // move the value 5 to accumulator A//
Add A, 00H // add A value with R0 value and stores the
result in A//
END
What will be the content in A?
MOV 07h,#01h
MOV A, #08h
ADD A,07h

What will be the content in A?


MOV 07h,#01h
MOV A, #08h
INC C carry=1
ADDC A,07h

What will be the content in A?


A=08+01+01=10=0AH
Subtraction
ORG 0000h
MOV 30H, #03H 30H = 03H
MOV R0, #30H // R0 = 30h//
MOV A, #05H // move the value 5 to accumulator A//
SETB C
SUBB A, @R0H // Result value is stored in the Accumulator A //
END

What will be the content in A ?


@R0 =@30H =03H
A = A-03H-C =05H-03H -01H=01H
Multiplication
ORG 0000h
MOV B, #03H // move the value 3 to the register R0//
MOV A, #05H // move the value 5 to accumulator A//
MUL AB // Multiplied result is stored in the
Accumulator A //
END
What will be the content in A and B?
MUL AB = 16 bit = Higher Byte
Lower Byte
B A
03*05 =(15)d = (0F)H = (00 0F) H

A= 0F H and B 00 H
Division
ORG 0000h
MOV B, #03H // move the value 3 to register R0//
MOV A, #15H // move the value 5 to accumulator A//
DIV AB // final value is stored in the Accumulator A //
END

What will be the content in A?


A/B = 15H/3H = (21/3)D = 07H
A=Q; B=R =00H
Logical: OR, XOR, AND, Swap
MOV A, #20H //0010 0000//
MOV R0, #03H //0000 0011//
XRL A, R0 // 0010 0011//

What will be the content in A ?

MOV A, #20H //0010 0000//


MOV R0, #03H //0000 0011//
SWAP A // A= 02H //
23H
MOV A, #25h
RR A
What will be the content in A?
A= 92H
PSW
Which bank is selected?
ORG 00H
MOV R0, #33H
MOV A, R0
SETB PSW.3
SETB PSW.4
MOV R0, A
END

ANS: Bank 3
MOV A,#0 ;
MOV R2,#04;
Loop
A = 0,clean ACC
the multiplier is replaced in R2
AGAIN:ADD A,#02h ; add the multiplicand to the ACC
DJNZ R2, AGAIN ; repeat until R2 = 0
MOV R5 , A ; save A in R5 ;
A=0
R2=04
A=A+02=02
R2=3!=0
A=A+02=02+02=04
R2=2!=0
A=04+02=06
R2=1!=0
A=06+02=08
R2=0; R5=A=08
MOV A, #00H //00H is stored in the A register//
MOV DPTR, #0500H //DPTR points 0500h address in the
memory//
MOVC A, @A+DPTR //send the value to the A register//
MOV R0, A //date of A send to the PO registrar//
ORG:500H
DB:0AH
END
What will be the content in R0?

You might also like