System & Program Developments of 8051

Assembly Language Programming

“ Assembler Operation

“ Assembly Language Program Format

“ Assemble-Time Expression Evaluation

“ Assembler Directives

“ Assembler Controls

“ Linker Operation

“ Linking Relocatable Segments and Modules

“ Macros

pdf49 trang | Chuyên mục: Vi Xử Lý – Vi Điều Khiển | Chia sẻ: tuando | Lượt xem: 629 | Lượt tải: 1download
Tóm tắt nội dung System & Program Developments of 8051, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
0
MOV FLAG2,#0
(error message: data segment address expected)
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 19
Storage 
Initialization/Reservation 
“ DS (define storage)
[label:] DS expression (reserves spaces in byte units, 
can be used in any segment type 
except BIT)
DSEG AT 30H ;put in data segment 
;(absolute , internal)
LENGTH EQU 40
BUFFER: DS LENGTH ;reserve 40 bytes
MOV R7,#LENGTH
MOV R0,#BUFFER ;R0=30H
LOOP: MOV @R0,#0
INC R0
DJNZ R7,LOOP
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 20
Storage 
Initialization/Reservation 
“ Create 1000 bytes in external RAM at 4000H
XSTART EQU 4000H
XLENGTH EQU 1000
XSEG AT XSTART ;put I data segment 
;(absolute , internal)
XBUFFER: DS XLENGTH ;reserve 40 bytes
MOV DPTR,#XBUFFER
LOOP: CLR A
MOV @DPTR,A
INC DPTR
MOV A,DPL
CJNE A,#LOW(XBUFFER + XLENGTH + 1),LOOP
MOV A,DPH
CJNE A,#HIGH(XBUFFER + XLENGTH + 1),LOOP
(continue)
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 21
Storage Initialization/Reservation 
“ DBIT: reserve space in bit units
[label:] DBIT expression
BSEG ;bit segment, absolute (00H-7FH)
KBFLAG: DBIT 1 ;keyboard status
PRFLAG: DBIT 1 ;printer status
DKFLAG: DBIT 1 ;disk status
“ DB (define byte): initialize code memory w bye values
[label:] DB expression [,expression] []
CSEG AT 0100H
SQUARES:DB 0,1,4,9,16,25 ;squares of number 0-5
MESSAGE:DB ‘Login:’,0 ;null-terminated char string
“ DW (define word)
[label:] DW expression [,expression] []
CSEG AT 0200H
DW $,’A’,1234H,2,’BC’ ;02 00 00 41 12 34 00 
;02 42 43
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 22
Program Linkage 
“ Allows separately assembled modules (files) 
to communicate by permitting intermodule
referencing and naming of the modules
“ PUBLIC (declare public for other modules to reference)
PUBLIC symbol [,symbol] []
allows the list of specified symbols to be known and used 
outside the currently assembled module.
“ EXTRN (declare symbols defined outside current module)
EXTRN symbol [,symbol] []
EXTRN CODE(HELLO,GOOD_BYE)
CALL HELLO
CALL GOOD_BYE
END
PUBLIC HELLO,GOOD_BYE
HELLO: (begin sub)
...
RET
GOOD_BYE: (begin sub)
RET
MESSAGE.SRCMAIN.SRC
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 23
Segment Selection 
“RSEG (selecting relocatable segment)
RSEGsegment_name
segment_name is previously defined by SEGMENT 
directive.
“Selecting Absolute Segments
CSEG [AT address]
DSEG [AT address]
ISEG [AT address]
BSEG [AT address]
XSEG [AT address]
“Each segment has its own location 
counter which is set to 0 initially
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 24
Segment Selection 
LOC OBJ LINE SOURCE
1 ONCHIP SEGMENT DATA
2 EPROM SEGMENT CODE
3
---- 4 BSEG AT 70H ;begin abs bit seg
0070 5 FLAG1: DBIT 1
0071 6 FLAG2 DBIT 1
7
---- 8 RSEG ONCHIP ;begin relocatable data seg
0000 9 TOTAL: DS 1
0001 10 COUNT: DS 1
0002 11 SUM16: DS 2
12
---- 13 RSEG EPROM ;begin relocatable code seg
0000 750000 F 14 BEGIN: MOV TOTAL,#0
15 (continue program)
16 END
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 25
Assembler Controls
“ Establish the format of the listing and 
object files. Controls the look of listing file, 
without having any effect on the program.
“ Can be entered on the invocation line or 
placed in the source program (preceded 
with $)
“ Primary controls and general controls
“ e.g., DATE, INCLUDE, LIST, MACRO(50), 
XREF
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 26
Assembler Controls
NAME Primary/
General
DEFAULT Abbrev
.
Meaning
DATE(date) P DATA() DA Places string in header (9 Char.
max.)
DEBUG P NODEBUG DB Outputs debug symbol information 
to object file
NODEBUG P NODEBUG NODB Symbol information not placed in 
object file
EJECT G Not applicable EJ Continue listing on next page
ERRORPRINT P NOERRORPRINT EP Designates a file to receive error 
Messages in addition to the listing 
file (defaults to console)
NOERRORPRINT P NOERRORPRINT NOEP Designates that error messages 
will be printed in listing file only
GEN P GENONLY GO List only the fully expanded source 
as if all lines generated by a macro 
call were already in the source file
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 27
Assembler Controls
GENONLY G GENONLY NOGE List only the original source 
text in the listing file
INCLUDE(file) G Not applicable IC Designates a file to be included as part of the 
program
LIST G NOLIST LI Print subsequent lines of source code in listing file
NOLIST G NOLIST NOLI Do not print subsequent lines of source code in listing 
file
MACRO(mem_percent
)
P MACRO(50) MR Evaluate and expand all macro calls. Allocate percentage of 
free memory for macro 
processing
NOMACRO P MACRO(50) NOMR Do not evaluate macro calls
MOD51 P MOD51 MO Recognize the 8051-specific predefined special function 
registers
NOMOD51 P MOD51 NOMO Do not recognize 8051-specific predefined special 
function registers
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 28
Assembler Controls
OBJECT(file) P OBJECT(source.O
BJ)
OJ Designates file to receive object 
code
NOOBJECT P OBJECT(source.O
BJ)
NOOJ Designates that no object file will be created
PAGING P PAGING PI Designates that listing file be broken into pages and each 
will have a header
NOPAGING P PAGING NOPI Designates that listing file will 
contain no page breaks
PAGELENGTH P PAGELENGTH(60) PL Sets maximum number of lines in 
each page of listing file (range = 10 
to 65,536)
PAGEWIDTH P PAGEWIDTH(120) PW Sets maximum number of 
characters in each line of listing file 
(range = 72 to 132)
PRINT(file) P PRINT(source.LST) PR Designates file to receive source 
listing
NOPRINT P PRINT(source.LST) NOPR Designates that no listing file will be 
created
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 29
Assembler Controls
SAVE G Not applicable SA Stores current control settings from 
SAVE stack
RESTORE G Not applicable RS Restores control settings from SAVE stack
REGISTERBANK(rb,..) P REGISTERBANK(0) RB Indicates one or more banks used in program module
NOREGISTERBANK P REGISTERBANK(0) NORB Indicates that no register banks are 
used
SYMBOLS P SYMBOLS SB Creates a formatted table of all 
symbols used in program
NOSYMBOLS P SYMBOLS NOSB Designates that no symbol table is 
created
TITLE(string) G TITLE() TT Places a string in all subsequent 
page headers (max. 60 characters)
WORKFILES(path) P Same as source WF Designates alternate path for 
temporary workfiles
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 30
Assembler Controls
XREF P NOXREF XR Creates a cross reference listing of 
all symbols used in program
NOXREF P NOXREF NOXR Designates that no cross reference list is created
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 31
Linker Operations
“ Intel RL51: links modules into an output 
file:
RL51 input_list [TO output_file] [location_controls]
input_list: a list of relocatable object modules (files) 
separated by commas.
Output_file: the name of the output absolute object 
module (executable program).
Location controls: set start addresses for the named 
segments.
“e.g., RL51 MAIN.OBJ,MESSAGE.OBJ, 
SUBROUTINE.OBJ TO EXAMPLE & 
CODE (EPROM(4000H)) 
DATA(ONCHIP(30H))
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 32
Linker Operations
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 33
Annotated Example: ECHO.LST
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 34
Annotated Example: ECHO.LST
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 35
Annotated Example: IO.LST
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 36
Annotated Example
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 37
Annotated Example
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 38
Annotated Example
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 39
Annotated Example: ECHO+IO
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 40
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 41
MACROS
“ Macro allows frequently used sections of 
code to be defined once using a simple 
mnemonic and used anywhere in the 
program by inserting the mnemonic.
“ ASM51’s MPL: string replacement.
“%DEFINE (call_pattern) (macro_body)
“%DEFINE (PUSH_DPTR)
(PUSH DPH
PUSH DPL)
“%PUSH_DPTR will be replaced by PUSH 
DPH and PUSH DPL two instructions in 
the .LST file
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 42
Advantages of Using Macros
“More readable
“The source program is shorter and 
requires less typing
“Using macros reduces bugs
“Using macros frees the programmer 
from dealing with low-level details
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 43
Parameter Passing
“%DEFINE 
(macro_name(parameter_list)) 
(macro_body)
“%DEFINE (CMPA# (VALUE)) 
(CJNE A,#%VALUE, $ + 3
)
“%CMPA# (20H) = CJNE A,#20H,$+3
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 44
Parameter Passing
“JUMP if A is greater than X:
“%DEFINE (macro_name(parameter_list)) 
(macro_body)
“%DEFINE (JGT(VALUE,LABEL)) 
(CJNE A,#%VALUE+1, $ + 3 ;
JNC %LABEL ;JGT
)
“%JGT(‘Z’,GREATER_THAN)
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 45
Local Labels
“%DEFINE (macro_name [(parameter_list)])
[LOCAL list_of_local_labels]
(macro_body)
“%DEFINE (DEC_DPTR) LOCAL SKIP 
(DEC DPL 
MOV A,DPL
CJNE A,#0FFH,%SKIP
DEC DPH
%SKIP: )
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 46
Local Labels
“%DEC_DPTR = 
“ DEC DPL 
MOV A,DPL
CJNE A,#0FFH, SKIP00
DEC DPH
SKIP00:
“Side effect: A is used and changed
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 47
Preserve A by Push-Pop
“%DEFINE (DEC_DPTR) LOCAL SKIP 
(PUSH A
DEC DPL 
MOV A,DPL
CJNE A,#0FFH,%SKIP
DEC DPH
%SKIP: POP A
)
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 48
Repeat Operations-- Built-in 
Macros
“%REPEAT (expression) (text)
“%REPEAT (100)
(NOP
)
2011/12/7 T. L. Jong, Dept. of E.E., NTHU 49
Control Flow Operations
“Conditional Assembly in ASM51: 
“%IF (expression) THEN (balanced_text)
[ELSE (balanced_text)]
INTERNAL EQU 1 ;1=8051 serial I/O drivers
. ;0=8251 serial I/O drivers
%IF (INTERNAL) THEN
(INCHAR: . ;8051 driver
.
OUTCHR: .
.
) ELSE
(INCHAR: . ;8251 driver
.
OUTCHR: .
.
)

File đính kèm:

  • pdfsystem_program_developments_of_8051.pdf
Tài liệu liên quan