111/06/07 111/06/07 Microcomputers and Microproce Microcomputers and Microproce ssors ssors Suranaree University Suranaree University Of Technology Of Technology มมม มมม 2002 Anant Oonsivilai 2002 Anant Oonsivilai Chapter 2 Chapter 2 8051 Assembly 8051 Assembly Language Language Programming Programming
Chapter 2 8051 Assembly Language Programming. 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 - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
112/04/22112/04/22 Microcomputers and MicroprocessorsMicrocomputers and Microprocessors
Suranaree UniversitySuranaree University
Of TechnologyOf Technologyมทสมทส
2002 Anant Oonsivilai2002 Anant Oonsivilai
Chapter 2Chapter 28051 Assembly 8051 Assembly
Language ProgrammingLanguage Programming
2002 Anant Oonsivilai2002 Anant Oonsivilai
OutlinesOutlines8051 registers8051 registersManipulate data using registers & MOVE Manipulate data using registers & MOVE instructionsinstructionsCode simple assembly language instructionsCode simple assembly language instructionsAssemble and run a programAssemble and run a programSequence events upon power-upSequence events upon power-upExamine programs in ROM codesExamine programs in ROM codesROM memory mapROM memory mapExecution of instructionsExecution of instructionsData typesData typesPSW register (Program Status Word)PSW register (Program Status Word)RAM memory spaceRAM memory spaceStackStackRegister banksRegister banks
2002 Anant Oonsivilai2002 Anant Oonsivilai
8051 Registers8051 Registers
D7D7 D6D6 D5D5 D4D4 D3D3 D2D2 D1D1 D0D0
DPTR
PC PC (Program counter)
DPH DPL
Figure2-1 (a): Some 8 bit Registers of the 8051
Figure2-1 (b): Some 8051 16 bit Registers
8 bit Registers
R6R6
R5R5
R4R4
R3R3
R2R2
R1R1
R0R0
BB
AA
R7R7
2002 Anant Oonsivilai2002 Anant Oonsivilai
MOV InstructionMOV Instruction
MOV destination, source ; copy source to MOV destination, source ; copy source to dest.dest.MOV A,#55HMOV A,#55H ;load value 55H into reg. A ;load value 55H into reg. AMOV R0,AMOV R0,A ;copy contents of A into R0 ;copy contents of A into R0
;(now A=R0=55H) ;(now A=R0=55H)MOV R1,AMOV R1,A ;copy contents of A into R1 ;copy contents of A into R1
;(now A=R0=R1=55H) ;(now A=R0=R1=55H)MOV R2,AMOV R2,A ;copy contents of A into R2 ;copy contents of A into R2
;(now A=R0=R1=R2=55H) ;(now A=R0=R1=R2=55H)MOV R3,#95HMOV R3,#95H ;load value 95H into R3 ;load value 95H into R3
;(now R3=95H) ;(now R3=95H)MOV A,R3MOV A,R3 ;copy contents of R3 into A ;copy contents of R3 into A
;now A=R3=95H ;now A=R3=95H
2002 Anant Oonsivilai2002 Anant Oonsivilai
Notes on ProgrammingNotes on Programming
Value (proceeded with #) can be loaded Value (proceeded with #) can be loaded directly to registers A, B, or R0 – R7directly to registers A, B, or R0 – R7 MOV R5, #0F9HMOV R5, #0F9H
If values 0 to F moved into an 8-bit If values 0 to F moved into an 8-bit register, the rest assumed all zerosregister, the rest assumed all zeros MOV A, #5MOV A, #5
A too large value causes an errorA too large value causes an error MOV A, #7F2HMOV A, #7F2H
2002 Anant Oonsivilai2002 Anant Oonsivilai
ADD InstructionADD Instruction
ADD A, source ADD A, source ;ADD the source operand;ADD the source operand
;to the accumulator;to the accumulator
MOV A, #25H MOV A, #25H ;load 25H into A;load 25H into AMOV R2,#34H MOV R2,#34H ;load 34H into R2;load 34H into R2ADD A,R2 ADD A,R2 ;add R2 to accumulator;add R2 to accumulator
;(A = A + R2) ;(A = A + R2)
2002 Anant Oonsivilai2002 Anant Oonsivilai
Structure of Assembly Structure of Assembly LanguageLanguage
ORG 0HORG 0H ;start (origin) at location 0 ;start (origin) at location 0MOV R5,#25HMOV R5,#25H ;load 25H into R5 ;load 25H into R5MOV R7,#34HMOV R7,#34H ;load 34H into R7 ;load 34H into R7MOV A,#0MOV A,#0 ;load 0 into A ;load 0 into AADD A,R5ADD A,R5 ;add contents of R5 to A ;add contents of R5 to A
;now A = A + R5 ;now A = A + R5ADD A,R7ADD A,R7 ;add contents of R7 to A ;add contents of R7 to A
;now A = A + R7 ;now A = A + R7ADD A,#12HADD A,#12H ;add to A value 12H ;add to A value 12H
;now A = A + 12H ;now A = A + 12HHERE: SJMP HEREHERE: SJMP HERE ;stay in this loop ;stay in this loop
ENDEND ;end of asm source file ;end of asm source file
Program 2-1:Sample of an Assembly Language Program
2002 Anant Oonsivilai2002 Anant Oonsivilai
Steps to Create a ProgramSteps to Create a Program
2002 Anant Oonsivilai2002 Anant Oonsivilai
8051 Program Counter & ROM 8051 Program Counter & ROM SpaceSpace
2002 Anant Oonsivilai2002 Anant Oonsivilai
8051 Program Counter & ROM 8051 Program Counter & ROM SpaceSpace
2002 Anant Oonsivilai2002 Anant Oonsivilai
8051 Program Counter & ROM 8051 Program Counter & ROM SpaceSpace
2002 Anant Oonsivilai2002 Anant Oonsivilai
Execute a Program Byte by Execute a Program Byte by ByteByte