Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 805 (Phần 6) - Hồ Trung Mỹ
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
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
1
System & Program
Developments of 8051
Program Structure and Design
Introduction
Advantages and Disadvantages of Structured
Programming
The Three Structures: statements, loops, choice
Pseudo Code Syntax
Assembly Language Programming
Tools & Techniques for Program Development
The Development Cycle
Integration and Verification
Command and Environments
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
2
Assembly Language
Programming
PROGRAM.OBJ
PROGRAM.SRC
LIBRARY
ASM51
PROGRAM.LST
PROGRAM.ABS
PROGRAM.MAP
RL51
FILE1.OBJ
FILE2.OBJ
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
3
ASM(input_file) /*assemble source program in input_file)*/
BEGIN
/*pass 1: build the symbol table */
lc = 0;
/*lc=location counter; default to 0*/
mnemonic = null;
open input_file;
WHILE (mnemonic != end) DO BEGIN
get_line();
/*get line from input_file */
scan_line();
/*scan line & get label/symbol & mnemonic */
IF (label) THEN enter_into_symbol_table(label, lc);
CASE mnemonic OF BEGIN
null, comment, END: ; /*do nothing */
ORG:
EQU:
DB:
lc = operand_value;
enter_in_symbol_table( symbol, operand_value);
WHILE (got_operand) DO increment_lc;
/* increment number of bytes defined */
lc = lc + operand_value;
DS:
1_byte_instruction:
2_byte_instruction:
3_byte_instruction:
lc = lc + 1;
lc = lc + 2;
lc = lc + 3;
END
END
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
4
/*pass 2: create the object program*/
rewind_input_file_pointer;
lc = 0;
mnemonic = null;
open_output_file;
WHILE (mnemonic != end) DO BEGIN
get_line();
scan_line(); /* determine mnemonic op code and value(s) of operand(s)*/
/*Note: if symbols are used in operand field, their values are looked-up*/
/* in the symbol table created during pass 1
CASE mnemonic OF BEGIN
*/
null, comment, EQU, END: ;
/*do nothing */
ORG:
lc = operand_value;
DB: WHILE (operand) DO BEGIN
put_in_objectfile(operand);
lc = lc + 1;
END
/* increment number of bytes defined */
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
5
DS: lc = lc + operand;
1_byte_instruction:
2_byte_instruction:
put_in_objectfile(inst_code);
put_in_objectfile(inst_code);
put_in_objectfile(operand);
3_byte_instruction:
put_in_objectfile(inst_code);
put_in_objectfile(operand high-byte);
put_in_objectfile(operand low-byte);
lc = lc + size_of_instruction;
END
END
close_input_file;
close_output_file;
END
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
6
Assembly Language
Program Format
Assembly language program contains:
Machine instructions (ANL, MOV)
Assembler directives (ORG,..)
Assembler controls ($TITLE)
Comments
Lines of machine instructions or
assembler directives:
[label:] Mnemonic [operand] [,operand] […] [;comment]
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
7
Assembly Language
Program Format
Label & symbol
PAR EQU 500
;PAR is a symbol
; which represents the
; value 500
START: MOV A,#0FFH ;START is a label
;which represents the
;address of the MOV
;instruction
Special Assembler Symbols
A, R0-R7, DPTR, PC, C, AB, $
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
8
Assemble-Time Expression
Evaluation
MOV A,#10 + 10H (MOV A,#1AH)
MOV A,#25 MOD 7 (MOV A,#4)
MOV A,#’9’ AND 0FH (MOV A,#9)
THREE
EQU 3
Minus_three EQU -3
MOV
MOV
MOV
A,#(NOT THREE)+1
A,#Minus_three
A,#11111101B
MOV A,#8 SHL 1 (MOV A,#10H)
MOV A,#HIGH 1234H (MOV A,12H)
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
9
Assemble-Time Expression
Evaluation
Relational operators: result is always false
(0000H) or true (FFFFH)
EQ
=
equal
NE
LT
<>
<
not equal
less than
LE
GT
GE
<=
>
>=
less than or equal to
greater than
greater than or equal to
MOV
MOV
MOV
MOV
MOV
A,#5 = 5
A,#’X’ LT ‘Z’
A,#5 NE 4
A,#’X’ >= ‘X’
A,#$ > 0
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
10
Assemble-Time Expression
Evaluation
Expression Examples:
‘B’ - ‘A’ 0001H
‘A’ SHL 8
4100H
8/3
155 MOD 2 0001H
4*4 0010H
8 AND 7 0000H
NOT 1 FFFEH
0002H
LOW 65535 00FFH
(8 + 1)*2
5 EQ 4
0012H
0000H
FFFFH
FFFFH
‘A’ LT ‘B’
3 <= 3
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
11
Assemble-Time Expression
Evaluation
Operator Precedence
( )
HIGH LOW
* / MOD SHL SHR
+ -
EQ NE LT LE GT GE = <> < <= > >=
NOT
AND
OR XOR
When same precedence, operators are evaluated
left-to-right
HIGH (‘A’ SHL 8) 0041H
HIGH ‘A’ SHL 8 0000H
NOT ‘A’ - 1
FFBFH
‘A’ OR ‘A’ SHL 8 4141H
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
12
Assembler Directives
Assembler state control (ORG, END, USING)
Symbol definition (SEGMENT, EQU, SET,
DATA, IDATA, XDATA, BIT, CODE)
Storage initialization/reservation (DS, DB,
DW, DBIT)
Program linkage (PUBLIC, EXTRN, NAME)
Segment selection (RSEG, CSEG, DSEG,
ISEG, BSEG, XSEG)
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
13
Assembler State Controls
ORG, END, USING
ORG
ORG
100H
($ + 1000H) AND 0F000H
;set to next
;4k boundary
END
;should be the last statement in the source file
USING
expression
;inform ASM51 of the currently
;active register bank
MOV
PSW,#00011000B
;select RB 3, the only way
;to switch register banks
USING
PUSH
MOV
USING
PUSH
3
;use register bank 3
AR7 ;1FH (R7 in bank 3)
PSW,#00001000B
1
AR7 ;0FH
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
14
Symbol Definition
The symbol definition directive creates
symbols representing segments,
registers, numbers, & addresses.
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
15
Symbol Definition
Segment (CODE, XDATA, DATA,IDATA,BIT)
symbol SEGMENT segment_type
CODE (code segment)
DATA (the internal data space accessible by direct
addressing 00-7FH)
IDATA (the entire internal data space accessible by
indirect addressing, 00-7FH on 8051, 00-FFH on
8052)
XDATA (the external data space)
BIT (the bit space; overlapping byte locations 20H-
2FH of the internal data space)
EPROM SEGMENT CODE (declares that EPROM is
a code segment. To actually begin using this
segment, the RSEG directive is used)
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
16
Symbol Definition
EQU and SET -- numbers
symbol EQU expression (assigns a numeric
value to a specific symbol name)
N27
HERE
EQU 27
EQU $
MESSAGE: DB ‘This is a message’
LENGTH EQU $-MESSAGE
symbol SET expression (similar to EQU except
that symbol can be redefined
later using another SET directive)
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
17
Symbol Definition
DATA, IDATA, XDATA, BIT, & CODE: assign
addresses of the corresponding segment
type to a symbol.
e.g.,
FLAG1
FLAG2
EQU
BIT
05H
05H
SETB
SETB
MOV
MOV
FLAG1
FLAG2
FLAG1,#0
FLAG2,#0
(error message: data segment address expected)
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
18
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
MOV @R0,#0
LOOP:
INC
R0
DJNZ R7,LOOP
2011/12/7
T. L. Jong, Dept. of E.E., NTHU
19
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
20
Tải về để xem bản đầy đủ
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Vi xử lý - Chương 3: Họ vi điều khiển 805 (Phần 6) - Hồ Trung Mỹ", để tải tài liệu gốc về máy hãy click vào nút Download ở trên
File đính kèm:
bai_giang_vi_xu_ly_chuong_3_ho_vi_dieu_khien_805_phan_6_ho_t.pdf

