Assembler MCS51 - machine language Assembler MCS51 2/16 Structure of programme In general a single assembler programme line has following structure: for.
Download ReportTranscript Assembler MCS51 - machine language Assembler MCS51 2/16 Structure of programme In general a single assembler programme line has following structure: for.
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 mov a,r0 r6,a ; adding to accumulator number from R0 ;send back result to R6
Assembler MCS51 3/16
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
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 5/16
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
Assembler MCS51 6/16
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
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 8/16
Expressions usage: Exemplary, instead the declarations: var1 equ 4500h var2 var3 var4 equ equ equ 4502h 4504h 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
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
LT
y x
<=
y x
LTE
y x
>
y x
GT
y x
>=
y x
GTE
y x
=
y x
EQ
y x
<>
y x
NE
y
NOT
y x
AND
y x
XOR
y x
OR
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 10/16
Dostępne funkcje wyrażeń:
function
LOW HIGH
usage operation
low(
value_2B
) selecting less sensing byte from 2-byte value 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.
Assembler MCS51 - directives 11/16 directive
INCLUDE
syntax
$INCLUDE (
pathfile
)
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. LIST NOLIST END $LIST or $LI $NOLIST or $NOLI END It disables full text report. It finishes assembly process. Text following this directive is ignored.
Assembler MCS51 – directives 12/16
ORG
label
: ORG
expression
or ORG
expression
EQU SET
label label
EQU SET
expression expression
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 13/16
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
expression
DBIT
label
: DBIT
expression
or DBIT
expression
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 doub le 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
. It reserves in directly addressed bit memory (without initialisation) the number of bits equal to the value of the
expression
.
Assembler MCS51 - directives 14/16
BIT CODE DATA IDATA XDATA SFR SBIT
label label label label label
BIT CODE DATA IDATA XDATA
address address address address address
Directives define the starting
address
of identifier
label
in given memory space: directly addressed bit memory (0x00 0xFF) - BIT program memory (0x0000-0xFFFF) - CODE internal data memory, addressing 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
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
SBIT
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 org ajmp 0 ini ;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: flag2: dbit dbit 1 1 ;reservation of single-bit variables at bit locations: ;10h & 11h (22h.0 & 22h.1) cseg at 200h numbers:db ;switching to program memory space at address 200h 23,33,51,92,99 ;5-byte table with program constants ;placed at addresses 200h..204h
;begin of the program