8051 Chap7 Assembly Programming
-
Upload
trieu-do-minh -
Category
Documents
-
view
256 -
download
1
Transcript of 8051 Chap7 Assembly Programming
-
7/30/2019 8051 Chap7 Assembly Programming
1/12
17-May-
Chapter 7
Assembly Language Programming
Chap 7 Assembly LanguageProgramming
Assembler
Change mnemonic code into machine code
Label can be used to represent symbolic address/data
Directives : like pre-processing operator (#) in Clanguage.
Linkage Editor
Link objective code into executable file
(*.obj *.exe)
-
7/30/2019 8051 Chap7 Assembly Programming
2/12
17-May-
FIGURE 71 Assembling a source program
Assembler
FIGURE 72 Pseudo code sketch of a two-pass operator
PASS 1
Establish symbol table
- Computing
address/symbol
PASS 2
Convert mnemonic codeinto machine code
-
7/30/2019 8051 Chap7 Assembly Programming
3/12
17-May-
FIGURE 73 Use of the generic JMP mnemonic
Symbol Table :
SymbolAddress/Data
Assembly program
Machine instructions
MOV A, #0
Assembler Directives
Like Variable declaration in high-level language
Assembler controls
Conditional compiling
Comments
After ; to EOL
. ; this is a comment
-
7/30/2019 8051 Chap7 Assembly Programming
4/12
17-May-
Formant of Assembly language
case insensitive
[label:] mnemonic [operation] [,operand].. ; comment
Example :
PAR EQU 500 ; #define symbol
JNB TI, $ ; HERE: JNB TI, HERE
Constant expression Implement by assembler
Examples:
MOV A, 9-0 ; means char constant
Operators in constant expressions
Arithmetic : + - * / MOD
Logic : AND OR NOT XOR
Relational : EQ NE LT LE GT GE= < >=
Special : SHR SHL HIGH LOW ()
-
7/30/2019 8051 Chap7 Assembly Programming
5/12
17-May-
Precedence of constant()
HIGH LOW
/MOD SHR SHL
+ -
EQ NE LT LE GT GE = < >=
NOT
AND
OR
XOR
Directives(1) Assembler state control
ORG define the location of the code
END directive to tell assembler the end of source file
USING set the register bank
Examples :
ORG 100H
ORG $+100H
USING 3
PUSH AR7 ; now AR7 means $23H.
END
-
7/30/2019 8051 Chap7 Assembly Programming
6/12
17-May-
(2) Symbol define
Segment EQU
Storage initialization/reservation
Program link
Segment selection
(A) Segment defineIn low-level language, the programmer need to manage the
location of program/data in memory
symbol SEGMENT segment_type
.. ; the following program was form a segment
; called symbol,; The content is segment_type (code or data)
segment_type can be one of
CODE (program)
XDATA (the extended data segment)
DATA (direct address space, 00-7fH)
IDATA (indirect address space, 00-7FH 80-FFH for 8052)
BIT (bit address space)
CSEG AT (equivalent to SEGMENT CODE)
DSEG AT
XSEG AT
ISEG AT
BSEG AT
-
7/30/2019 8051 Chap7 Assembly Programming
7/12
17-May-
(B) EQU
like the named constant define in C (#define)
Example:
BASE EQU 10
other constants :
#10H, $(current location)
(C) Storage initialization/reservation
DS (define space, like unintialized array)
DBIT (define bit data)
DB (define byte data) DW (define word data, low-byte in lower address)
Example 1:
DSEG AT 30H
LENGTH: EQU 40
BUFFER: DS LENGTH
PROG SEGMENT CODE
MOV R7, #LENGTH
MOV R0, #BUFFER
LOOP: MOV @R0, #0
BJNZ R7, LOOP
.
END
-
7/30/2019 8051 Chap7 Assembly Programming
8/12
17-May-
Example 2:
XSEG AT 4000HXLENGTH: EQU 1000
XBUFFER: DS XLENGTH
PROG SEGMENT CODE
MOV DPTR, #XLENGTH
LOOP: CLR A
MOVX @DPTR, A
INC DTPR
MOV A, DPL
CJNE A, #LOW(XBUFFER+XLENGTH+1),LOOP
MOV A, DPH
CJNE A, #HIGH(XBUFFER+XLENGTH+1),LOOP
.END
FIGURE 74 Use of the EXTRN and PUBLIC assembler directives
Multi-file : EXTERN, PUBLIC directive(3) Program link
-
7/30/2019 8051 Chap7 Assembly Programming
9/12
17-May-
FIGURE 75 Defining and initiat ing absolute and relocatable segments
RSEG directive reallocatable segment
FIGURE 76 Assembler controls supported by ASM51
-
7/30/2019 8051 Chap7 Assembly Programming
10/12
17-May-
FIGURE 76 (continued) Assembler controls supported by ASM51
FIGURE 77 Linker operation
-
7/30/2019 8051 Chap7 Assembly Programming
11/12
17-May-
FIGURE 78a Annotated example: linking relocatable segments and modules. (a) ECHO.LST. (b) IO.LST. (c)EXAMPLE.M51.
Address-relative content
Need to fix in linkage
- reallocatable
FIGURE 78a Annotated example: linking relocatable segments and modules. (a) ECHO.LST. (b) IO.LST. (c)
EXAMPLE.M51.
Symbol Table
-
7/30/2019 8051 Chap7 Assembly Programming
12/12
17-May-
FIGURE 78d (continued) Annotated example: linking relocatable segments and modules. (a) ECHO.LST. (b) IO.LST.(c) EXAMPLE.M51.
Output of linkage editor
-Symbol table
-Reallocatable address were
computed already