mca is a microcontroller and accmulator is a third year couse

gauravsharma4365 13 views 29 slides Aug 10, 2024
Slide 1
Slide 1 of 29
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29

About This Presentation

Mca


Slide Content

C
HAPTER
2
8051 A
SSEMBLY
L
ANGUAGE
P
ROGRAMMING
.

S
YLLABUS
Topic Fine Detailing No of Hours
8051Assembly
Language
Programming.
2.1Instructionset 3
2.2Addressingmode
2.3Assemblerdirectives
2.4Programsrelatedto:arithmetic,logical,
delay,input,outputport,serial
communicationandinterrupts

O
BJECTIVE

To give students an understanding of various
functions of the registers in 8051 programming
model.

It defines and explains the various addressing
modes of 8051.

it classify the instructions in terms of their word
size and categories the instruction set into 5
groups.

It helps the students to perform various
arithmetic and logical operations

D
EFINITIONS

Op-code (Operation code):Op-code is the part of an
instruction / directive that identifies a specific operation.

Operand:Operand is a part of an instruction / directive
that represents a value on which the instruction acts.

MNEMONIC: refers to the operation an instruction
performs (copy, addition, logic operation etc.).
Mnemonics are abbreviations of the name of operation
being executed

Assembly language: The language in which the
mnemonics (short -hand form of instructions) are used
to write a program is called assembly language. The
manufacturers of microprocessor give the mnemonics.

A
DDRESSINGMODESOF
8051

Addressing modes of 8051

An "addressing mode" refers to how you are
addressing a given memory location. Each of these
addressing modes provides important flexibilityThe
8051 instruction set supports 6 addressing
modes

Immediate addressing mode

Direct addressing

Register Indirect addressing

Indexed addressing mode

Relative addressing mode

ADDRESSINGMODE

Direct addressing: In this mode, the operands
are (addressed) specified using the 8 bit address
field in the instruction format. Only internal data
RAM and SFRS can be directly addressed.

Example: MOV R0, 89H; 89 H is an address of
special function Register TMOD.

ADDRESSINGMODE

Register Indirect addressing: In this mode the 8
bit address of a operand is stored in a register.
The register R0 and R1 of the selected bank of
register or SP can be used as address register for
storing the 8 bit addresses.

Example: ADD A, @ R0.

ADDRESSINGMODE

Register Instructions: In this mode the operands are
stored in the register R0_R7 of the selected register
Bank. One of these register is (R0_R7) is specified in
the instruction using the 3-bit register specification
field of the opcodeformat.

Example: ADD A, R7.

Register Specific instruction: In this case the operand
is implicitly stated as a part of register. Some of the
instruction always operate only on a specific register.

Example: RLA Rotates accumulator left.

ADDRESSINGMODE

Immediate Mode: In this mode an immediate
data i.e., a constant is specified in the instruction
after the opcodebyte.

Example: MOV A, #10.

ADDRESSINGMODE

Indexed addressing:

Only program memory can be accessed using this addressing mode.

Used in 8051 for look up table operation.

PC and data pointers are allowed 16 bit address register is this mode of
addressing.

These 16 bit register points the base of the lookup table and accumulator
register contains code to be converted using the looking table.

The lookup table data address is found by adding the contents of accumulator
register with that of PC or data pointer.

In the case of jump instruction the contents of accumulator are added with one
of the specified 16 bit register to form a jump destination address.

Example: MOVC A, @A+DPTR

I
NSTRUCTION
S
ET

The process of writing program for the
microcontroller mainly consists of giving instructions
(commands) in the specific order in which they
should be executed in order to carry out a specific
task. All commands are known as INSTRUCTION SET.

All microcontrollers compatible with the 8051 have
in total of 255 instructions, i.e. 255 different words
available for program writing.

I
NSTRUCTION
S
ET

Depending on operation they perform, all
instructions are divided in several groups:

Arithmetic Instructions

Branch Instructions

Data Transfer Instructions

Logic Instructions

Bit-oriented Instructions

D
ATA
T
RANSFER
I
NSTRUCTIONS

Data transfer instructions move the content of
one register to another. The register the content
of which is moved remains unchanged. If they
have the suffix “X” (MOVX), the data is
exchanged with external memory.

D
ATA
T
RANSFER
I
NSTRUCTIONS
TRANSFERINSTRUCTIONS
MnemonicDescription ByteCycle
MOVA,RnMovestheregistertotheaccumulator 11
MOVA,directMovesthedirectbytetotheaccumulator 22
MOVA,@RiMovestheindirecttotheaccumulator 12
MOVA,#dataMovestheimmediatedatatotheaccumulator22
MOVRn,AMovestheaccumulatortotheregister 12
MOVRn,directMovesthedirectbytetotheregister 24
MOVRn,#dataMovestheimmediatedatatotheregister 22
MOVdirect,AMovestheaccumulatortothedirectbyte 23
MOVdirect,RnMovestheregistertothedirectbyte 23
MOVdirect,directMovesthedirectbytetothedirectbyte 34
MOVdirect,@RiMovestheindirecttothedirectbyte 24

D
ATA
T
RANSFER
I
NSTRUCTIONS
Mnemonic Description ByteCycle
MOV@Ri,A Movestheaccumulatortotheindirect 13
MOV@Ri,directMovesthedirectbytetotheindirect 25
MOV@Ri,#dataMovestheimmediatedatatotheindirect 23
MOV,#data Movesa16-bitdatatothedatapointer 33
MOVCA,@A+ Movesthecodebyterelativetothetotheaccumulator(address=A+)13
MOVCA,@A+PCMovesthecodebyterelativetothePCtotheaccumulator(address=A+PC)13
MOVXA,@Ri Movestheexternal(8-bitaddress)totheaccumulator 13-10
MOVXA,@ Movestheexternal(16-bitaddress)totheaccumulator 13-10
MOVX@Ri,A Movestheaccumulatortotheexternal(8-bitaddress) 14-11
MOVX@,A Movestheaccumulatortotheexternal(16-bitaddress) 14-11
PUSHdirect Pushesthedirectbyteontothestack 24
direct Popsthedirectbytefromthestack/td> 23
XCHA,Rn Exchangestheregisterwiththeaccumulator 12
XCHA,direct Exchangesthedirectbytewiththeaccumulator 23
XCHA,@Ri Exchangestheindirectwiththeaccumulator 13
XCHDA,@Ri Exchangesthelow-ordernibbleindirectwiththeaccumulator 13

A
RITHMETIC
I
NSTRUCTIONS
Mnemonic Description ByteCycle
ADD A,Rn Adds the register to the accumulator 11
ADD A,direct Adds the direct byte to the accumulator 22
ADD A,@Ri Adds the indirect RAM to the accumulator 12
ADD A,#data Adds the immediate data to the accumulator 22
ADDC A,Rn Adds the register to the accumulator with a carry flag 11
ADDC A,directAdds the direct byte to the accumulator with a carry flag 22
ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag12
ADDC A,#dataAdds the immediate data to the accumulator with a carry flag22
SUBB A,Rn Subtracts the register from the accumulator with a borrow11
SUBB A,direct Subtracts the direct byte from the accumulator with a borrow22
SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow12
SUBB A,#data Subtracts the immediate data from the accumulator with a borrow22

A
RITHMETIC
I
NSTRUCTIONS
INC A Increments the accumulator by 1 11
INC Rn Increments the register by 1 12
INC Rx Increments the direct byte by 1 23
INC @Ri Increments the indirect RAM by 1 13
DEC A Decrements the accumulator by 1 11
DEC Rn Decrements the register by 1 11
DEC Rx Decrements the direct byte by 1 12
DEC @Ri Decrements the indirect RAM by 1 23
INC DPTR Increments the Data Pointer by 1 13
MUL AB Multiplies A and B 15
DIV AB Divides A by B 15
DA A Decimal adjustment of the accumulator according to BCD code11

B
RANCH
I
NSTRUCTIONS
Mnemonic Description ByteCycle
ACALL addr11Absolute subroutine call 26
LCALL addr16Long subroutine call 36
RET Returns from subroutine 14
RETI Returns from interrupt subroutine 14
AJMP addr11Absolute jump 23
LJMP addr16Long jump 34
SJMP rel Short jump (from –128 to +127 locations relative to
the following instruction)
23
JC rel Jump if carry flag is set. Short jump. 23
JNC rel Jump if carry flag is not set. Short jump. 23
JB bit,rel Jump if direct bit is set. Short jump. 34
JBC bit,rel Jump if direct bit is set and clears bit. Short jump.34
JMP @A+DPTRJump indirect relative to the DPTR 12
JZ rel Jump if the accumulator is zero. Short jump. 23
JNZ rel Jump if the accumulator is not zero. Short jump.23

B
RANCH
I
NSTRUCTIONS
CJNE A,direct,rel
Compares direct byte to the accumulator and jumps if not
equal. Short jump.
34
CJNE A,#data,rel
Compares immediate data to the accumulator and jumps if
not equal. Short jump.
34
CJNE Rn,#data,rel
Compares immediate data to the register and jumps if not
equal. Short jump.
34
CJNE @Ri,#data,rel
Compares immediate data to indirect register and jumps if
not equal. Short jump.
34
DJNZ Rn,relDecrements register and jumps if not 0. Short jump.23
DJNZ Rx,relDecrements direct byte and jump if not 0. Short jump.34
NOP No operation 11

L
OGICINSTRUCTION
Mnemonic Description ByteCycle
ANLA,Rn ANDregistertoaccumulator 11
ANLA,direct ANDdirectbytetoaccumulator 22
ANLA,@Ri ANDindirectRAMtoaccumulator 12
ANLA,#data ANDimmediatedatatoaccumulator 22
ANLdirect,A ANDaccumulatortodirectbyte 23
ANLdirect,#dataANDimmediaedatatodirectregister 34
ORLA,Rn ORregistertoaccumulator 11
ORLA,direct ORdirectbytetoaccumulator 22
ORLA,@Ri ORindirectRAMtoaccumulator 12
ORLdirect,A ORaccumulatortodirectbyte 23
ORLdirect,#dataORimmediatedatatodirectbyte 34

L
OGICINSTRUCTION
XRLA,RnExclusiveORregistertoaccumulator 1 1
XRLA,directExclusiveORdirectbytetoaccumulator 2 2
XRLA,@RiExclusiveORindirectRAMtoaccumulator 1 2
XRLA,#dataExclusiveORimmediatedatatoaccumulator 2 2
XRLdirect,AExclusiveORaccumulatortodirectbyte 2 3
XORLdirect,#dataExclusiveORimmediatedatatodirectbyte 3 4
CLRA Clearstheaccumulator 1 1
CPLA Complementstheaccumulator(1=0,0=1) 1 1
SWAPA Swapsnibbleswithintheaccumulator 1 1
RLA Rotatesbitsintheaccumulatorleft 1 1
RLCA Rotatesbitsintheaccumulatorleftthroughcarry 1 1
RRA Rotatesbitsintheaccumulatorright 1 1
RRCA Rotatesbitsintheaccumulatorrightthroughcarry 1 1

B
IT
-
ORIENTED
I
NSTRUCTIONS
MnemonicDescription ByteCycle
CLRCClearsthecarryflag 11
CLRbitClearsthedirectbit 23
SETBCSetsthecarryflag 11
SETBbitSetsthedirectbit 23
CPLCComplementsthecarryflag 11
CPLbitComplementsthedirectbit 23
ANLC,bitANDdirectbittothecarryflag 22
ANLC,/bitANDcomplementsofdirectbittothecarryflag 22
ORLC,bitORdirectbittothecarryflag 22
ORLC,/bitORcomplementsofdirectbittothecarryflag 22
MOVC,bitMovesthedirectbittothecarryflag 22
MOVbit,CMovesthecarryflagtothedirectbit 23

P
RGRAMINGWITH
8051

Write a program to copy a block of 10 bytes from RAM location
starting at 37h to RAM location Starting at 59h.

PROGRAM:

MOV R0,#37h

MOV R1,#59h

MOV R2,#10

L1: MOV A,@R0

MOV @R1,A

INC R0

INC R1

DJNZ R2, L1

P
RGRAMINGWITH
8051

Write a program to Exchange the content of FFhand
FF00h, where one is internal memory location and
other is memory external location.
MOV DPTR, #0FF00h; take the address in dptr
MOVX A, @DPTR; get the content of 0050h in a
MOV R0, 0FFh ; save the content of 50h in r0
MOV 0FFh, A ; move a to 50h
MOV A, R0 ; get content of 50h in a
MOVX @dptr, A ; move it to 0050h

P
ROGRAMINGWITH
8051

Write a program in 8051 to unpack the BCD number stored in
register A

MOV A, #92H; load the number in accumulator.

MOV B, A ; Store the number in register B

ANL A, #0F0h ; mask lower nibble

SWAP A ; MSB digit= LSB digit

MOV R1, A ; Store the result in register R1

MOV A, B ; Load the number back in accumulator

ANL A, #0Fh ; Store the result in register R0

HERE: SJMP HERE

P
ROGRAMINGWITH
8051

Write a program to generate square wave of 50% duty
cycle (with equal portions high and low) on the P1.5 bit.
Timer 0 is used to generate the time delay.

Write a Program to generate a rectangular wave of
1KHz having 25% duty cycle from TXD pin of 8051 using
timer1. Assume XTAL of 12MHz.

Write a program for the 8051 to transfer letter “A”
serially at 4800baud, continuously.

Write a program to transfer the message “YES” serially
at 9600 baud, 8-bit data, 1 stop bit. Do this
continuously.

P
ROGRAMINGWITH
8051

Program the 8051 to receive bytes of data serially,
and put them in P1. Set the baud rate at 4800, 8-bit
data, and 1 stop bit.

Write a program to perform the following:

Keep monitoring the P1.2 bit until it becomes high

When P1.2 becomes high, write value 45H to port 0

Send a high-to-low (H-to-L) pulse to P2.3

Write a program to get the status of the switch and
send it to the LED. Assume switch is connected to pin
P1.7 and an LED to pin P2.0

P
RGRAMINGWITH
8051

Write a program to get the x value from P1 and send x
2
to P2,
continuously

After the execution of the following program what will be the
contents of R3.

MOV R3, #00H

MOV R1, #02H

MOV R2, #04H

UP: INC 03H

DJN2 R2, UP

DJN2 R1, UP

HERE: SJMP HERE

P
RGRAMINGWITH
8051

Explain the following instructions in 8051

MOV C, P0.7

XCHDA, TL0

CJNE A, 24H, Repeat

RETI

Explain the addressing modes of 8051 Also compare
MOV, MOVX and MOVC Instructions.