0% found this document useful (0 votes)
59 views29 pages

8051 Assembly Language Programming

This document discusses 8051 assembly language programming. It outlines registers, MOV and ADD instructions, assembling and running programs, and memory organization. Specifically, it describes the 8051's register set, manipulating data with MOV, basic program structure, executing instructions sequentially, data types, the PSW flag register, RAM memory allocation, register banks, using the stack, and conflicts between stack and bank 1 memory.

Uploaded by

arbresha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views29 pages

8051 Assembly Language Programming

This document discusses 8051 assembly language programming. It outlines registers, MOV and ADD instructions, assembling and running programs, and memory organization. Specifically, it describes the 8051's register set, manipulating data with MOV, basic program structure, executing instructions sequentially, data types, the PSW flag register, RAM memory allocation, register banks, using the stack, and conflicts between stack and bank 1 memory.

Uploaded by

arbresha
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 29

NATIONAL TAIWAN

OCEAN UNIVERSITY
國立台灣海洋大學

Chapter 2
8051 Assembly Language
Programming

2002 MuDer Jeng 110/12/08 Microcomputers and Microprocessor


Outlines
 8051 registers
 Manipulate data using registers & MOVE instructions
 Code simple assembly language instructions
 Assemble and run a program
 Sequence events upon power-up
 Examine programs in ROM codes
 ROM memory map
 Execution of instructions
 Data types
 PSW register
 RAM memory space
 Stack
 Register banks
2002 MuDer Jeng
8051 Registers
D7 D6 D5 D4 D3 D2 D1 D0
A
B
R0
8 bit Registers
R1
R2 DPTR DPH DPL
R3
R4 PC PC (Program counter)
R5
R6 Figure2-1 (b): Some 8051 16 bit Registers
R7

Figure2-1 (a): Some 8 bit Registers of the 8051

2002 MuDer Jeng


MOV Instruction
 MOV destination, source ; copy source to dest.
 MOV A,#55H ;load value 55H into reg. A
MOV R0,A ;copy contents of A into R0
;(now A=R0=55H)
MOV R1,A ;copy contents of A into R1
;(now A=R0=R1=55H)
MOV R2,A ;copy contents of A into R2
;(now A=R0=R1=R2=55H)
MOV R3,#95H ;load value 95H into R3
;(now R3=95H)
MOV A,R3 ;copy contents of R3 into A
;now A=R3=95H

2002 MuDer Jeng


Notes on Programming
 Value (proceeded with #) can be loaded
directly to registers A, B, or R0 – R7
– MOV R5, #0F9H
 If values 0 to F moved into an 8-bit register,
the rest assumed all zeros
– MOV A, #5
 A too large value causes an error
– MOV A, #7F2H

2002 MuDer Jeng


ADD Instruction
 ADD A, source ;ADD the source operand
;to the accumulator
 MOV A, #25H ;load 25H into A
MOV R2,#34H ;load 34H into R2
ADD A,R2 ;add R2 to accumulator
;(A = A + R2)

2002 MuDer Jeng


Structure of Assembly Language
ORG 0H ;start (origin) at location 0
MOV R5,#25H ;load 25H into R5
MOV R7,#34H ;load 34H into R7
MOV A,#0 ;load 0 into A
ADD A,R5 ;add contents of R5 to A
;now A = A + R5
ADD A,R7 ;add contents of R7 to A
;now A = A + R7
ADD A,#12H ;add to A value 12H
;now A = A + 12H
HERE: SJMP HERE ;stay in this loop
END ;end of asm source file
Program 2-1:Sample of an Assembly Language Program

2002 MuDer Jeng


Steps to Create a Program

2002 MuDer Jeng


8051 Program Counter & ROM Space

2002 MuDer Jeng


8051 Program Counter & ROM Space

2002 MuDer Jeng


8051 Program Counter & ROM Space

2002 MuDer Jeng


Execute a Program Byte by Byte
1. PC=0000: opcode 7D fetched; 25 fetched;
R5←25; PC+2
2. PC=0002: opcode 7F fetched; 34 fetched;
R7←34; PC+2
3. PC=0004; opcode 74 fetched; 0 fetched;
A←0; PC+2
4. PC=0006; opcode 2D fetched; A←A+R5;
PC+1
5. (Similarly…)

2002 MuDer Jeng


8051 On-Chip ROM Address Range

2002 MuDer Jeng


Data Types & Directives
ORG 500H
DATA1: DB 28 ;DECIMAL (1C in Hex)
DATA2: DB 00110101B ;BINARY (35 in Hex)
DATA3: DB 39H ;HEX
ORG 510H
DATA4: DB “2591” ; ASCII NUMBERS

ORG 518H
DATA6: DB “My name is Joe” ;ASCII CHARACTERS

2002 MuDer Jeng


PSW (Flag) Register

2002 MuDer Jeng


Instructions Affecting Flag Bits

2002 MuDer Jeng


ADD Instruction and PSW

2002 MuDer Jeng


ADD Instruction and PSW

2002 MuDer Jeng


ADD Instruction and PSW

2002 MuDer Jeng


8051 RAM Allocation

2002 MuDer Jeng


8051 Register Banks

2002 MuDer Jeng


Access RAM Locations Using Register Names

2002 MuDer Jeng


Access RAM Locations Using Addresses

2002 MuDer Jeng


Switch Register Banks

2002 MuDer Jeng


Switch Register Banks

2002 MuDer Jeng


Pushing onto Stack

2002 MuDer Jeng


Popping from Stack

2002 MuDer Jeng


Stack & Bank 1 Conflict

2002 MuDer Jeng


Stack & Bank 1 Conflict

2002 MuDer Jeng

You might also like