Assembler MCS51

Download Report

Transcript Assembler MCS51

Assembler MCS51
- machine language
Assembler MCS51
2/16
Structure of programme
In general a single assembler programme line has following structure:
<label> <instr. name> <operands> <comment>
for example:
go_here:add
a,r0
;adding to accumulator number from R0
mov
r6,a
;send back result to R6
Assembler MCS51
where:
<label> - text field at least 1 char width, used to declare identifiers/labels
which should be followed by colon and space (': '),
separating label from the rest of the line
<instr. name> - text field for the symbolic name of processor instruction;
also used for placing so called directives
3/16
Assembler MCS51
4/16
where - cont.:
<operands> - optional text field, which contents depends on used
in instruction name field instruction or directive
here the list of instruction operands/directive description
should be placed;
<comment> - optional text field, which starts with semicolon (‘;’),
intended for free text, explaining programmed operations;
comment can start at any place in program line,
especially from the first column (omitting other fields).
Assembler MCS51
Label purpose:
1. Identifiers of the locations in processor address space, for identify:
jump addresses, like:
here:
add A,P0
starting addresses of subroutine, like:
acall dod3B
;add 3-byte numbers
basic addresses of data structure, like:
table1: db 12,234,0,11 ; table of 1-byte values
5/16
Assembler MCS51
Label purpose :
2. Identifiers of the program constants,
- making easier to use them;
- increasing program readability, like:
CR
EQU 13
;carriage return ASCII char
3. Identifiers of the program variables, by assigning to them
their starting address in memory space, like using EQU directive:
date EQU 70h ;variable for day of the month
....
mov r1,#date ;R1<-variable ‘date’ address
6/16
Assembler MCS51
7/16
Constants:
Char or number values predefined during assembly process or read out from
external sources during linking. Examples:
constant
‘A’
‘text’
787, 787D
10011B
2AFh
2A0H
0F00h
0x2AF, $2AF
0457
457Q, 457q
457O, 457o
Identifier
meaning
single ASCII char 41h
string of ASCII chars
decimal number
binary number
hex number
hexadecimal number
hexadecimal number
hexadecimal number
octal number
octal number
octal number
with predefined value
binary representation
74h,65h,78h,74h
0313h
13h
02AFh
02A0h
0F00h
02AFh
012Fh
012Fh
012Fh
according to the value
Assembler MCS51 - expressions
Expressions usage:
Exemplary, instead the declarations:
var1
equ
4500h
var2
equ
4502h
var3
equ
4504h
var4
equ
4508h
we can write:
var1
equ
var2
equ
var3
equ
var4
equ
4500h
var1+2
var2+2
var3+4
Assembly result is the same,
but the second notation makes corrections easier
8/16
Assembler MCS51 – expressions
9/16
Possible operators:
group
arithmetic
shifting
comparing
logical
operator
$
( )
x*y
x/y
x%y
x+y
x-y
x SHL y
x SHR y
x<y
x <= y
x>y
x >= y
x=y
x <> y
NOT y
x AND y
x XOR y
x OR y
x LT y
x LTE y
x GT y
x GTE y
x EQ y
x NE y
operation
current value of the program counter
braces
multiplying x * y
dividing x / y
modulo of x / y
adding x + y
subtracting x - y
shift left x by y bits
shift right x by y bits
(y < 32)
x less then y
x less-equal then y
x greater y
x greater-equal then y
x equal y
x not equal y
bit completion y
bit logical product x i y
bit exclusive or x i y
bit logical sum x i y
Assembler MCS51 - expressions
Dostępne funkcje wyrażeń:
function
usage
operation
LOW
low(value_2B) selecting less sensing byte from
2-byte value
HIGH
high(value_2B) selecting more sensing byte from
2-byte value
Operator precedence:
- braces ( );
- NOT, HIGH, LOW;
- + , - (as a sign of the operand);
- * , / , MOD;
-+,-;
- SHR , SHL;
- AND , OR , XOR;
- < , <= , = , <> , >= , > , LT , LTE , EQ , NE , GTE , GT.
10/16
Assembler MCS51 - directives
directive
INCLUDE
LIST
syntax
$INCLUDE (pathfile)
$LIST
or
NOLIST
$LI
$NOLIST
11/16
usage
Pointing the path and file, which
contents have to be inserted in given
place. If inserted file contains END
directive, it finishes the assembly
process.
It enables full text report of
assembling, placed in *.LST file.
It disables full text report.
or
$NOLI
END
END
It finishes assembly process. Text
following this directive is ignored.
Assembler MCS51 – directives
ORG
label: ORG
expression
or
ORG
expression
EQU
label EQU
expression
SET
label
expression
SET
12/16
It defines address of the first byte of
instruction code or data structure
following this directive. The address
value is equal to the value of
expression, which should be able to be
calculated during assembling. If
directive follows the identifier label the
calculated value is assigned to it.
It assigns to identifier ‘label’ the value
of expression. Identifier defined using
this directive can not be redefined.
It assigns to identifier ‘label’ the value
of expression. Identifier defined using
this directive can be redefined.
Assembler MCS51 - directives
DB
label: DB 1B-value_list
or
DB 1B-value_list
DW
label: DW 2B-value_list
or
DW 2B-value_list
DS
label: DS
expression
or
DS
DBIT
13/16
It allows to define the list of single-byte
values. 1B-value_list should contain at least
one expression, which value can be stored in
1 byte. Especially 1B-value_list can be ASCII
string in double apostrophes ” .
It allows to define the list of single-word
values. 2B-value_list should contain at least
one expression, which value can be stored in
2 bytes. The values are stored in memory in
order: LSB-MSB
It reserves in memory (without initialisation)
the number of bytes equal to the value of the
expression.
expression
label: DBIT
expression
or
DBIT
expression
It reserves in directly addressed bit memory
(without initialisation) the number of bits equal
to the value of the expression.
Assembler MCS51 - directives
BIT
label BIT
CODE
label
DATA
label
IDATA
label
XDATA
label
SFR
SFR
SBIT
SBIT
address
14/16
Directives define the starting address of
identifier label in given memory space:
CODE address
 directly addressed bit memory (0x000xFF) - BIT
DATA address
 program memory (0x0000-0xFFFF) IDATA address
CODE
 internal data memory, addressing
XDATA address
directly (0x00-0xFF) - DATA
 internal data memory, addressing
indirectly (0x00-0xFF) - IDATA
 external data memory (0x0000-0xFFFF)
- XDATA
Address can have the form of expression.
sfr_name = address It defines new name (sfr_name) of register
in SFR space at given location address.
Address can have the form of expression
bit_name = bit_adr
It defines new directly addressed bit
(bit_name) at given bit_adr location.
bit_adr should have the form of:
reg_name ^nb or reg_addr ^ nb (nb=0..7)
Assembler MCS51 - directives
15/16
CSEG, DSEG, ISEG, BSEG, XSEG – define the memory space segment
(CODE, internal RAM addressed directly or indirectly, directly addressed bits
or external RAM) for the following objects (instructions, constants, data
structures, labels, etc.).
Possible usage form:
xSEG
– switching to selected memory spaces;
if selected segment was already used,
its addressing is continued,
either addressing starts from 0000h
xSEG AT address
- switching to selected memory spaces
with defining the start address
Assembler MCS51 - directives
16/16
Exemplary usage:
bseg at 10h
;switching to directly addressed bits with start address
;equal to 10h (it matches with bit #0 of byte placed
;in internal data memory at location 22h)
flag1:
dbit
1
;reservation of single-bit variables at bit locations:
flag2:
dbit
1
;10h & 11h (22h.0 & 22h.1)
cseg at 200h
;switching to program memory space at address 200h
numbers:db
23,33,51,92,99 ;5-byte table with program constants
;placed at addresses 200h..204h
org
0
ajmp
ini
;begin of the program