+ All Categories
Home > Documents > What is an Assembler2

What is an Assembler2

Date post: 06-Dec-2015
Category:
Upload: elreyleon1
View: 213 times
Download: 0 times
Share this document with a friend
Description:
manual
56
What is an Assembler? An assembler is a program that translates symbolic code (assembly language) into executable object code. This object code can be executed with a 80C51-compatible microcontroller. If you have ever written a computer program directly in machine- recognizable form, such as binary or hexadecimal code, you will appreciate the advantages of programming in symbolic assembly language. Assembly language operation codes (mnemonics) are easily remembered (MOV for move instructions, ADD for addition, and so on). You can also symbolically express addresses and values referenced in the operand field of instructions. Because you assign these names, you can make them as meaningful as the mnemonics for the instructions. For example, if your program must manipulate a date as data, you can assign it the symbolic name DATE. If your program contains a set of instructions used as a timing loop (executed repeatedly until a specific amount of time has passed), you can name the instruction group TIMER_LOOP. An assembly program has three parts: Machine instructions - Code the machine can execute. Detailed discussion of the machine instructions is in the hardware manuals of the 80C51 microcontroller. Assembler directives - Define the program structure and symbols, and generate non executable code (data, messages, and so on.). Assembler controls - Set assembly modes and direct assembly flow. Assembly Statements Home » Writing Assembly Programs » Assembly Statements Assembly program source files are made up of statements that may include controls, assembler control statements, or 8051 MCU instructions (mnemonics). For example: $TITLE(Demo Program #1) CSEG AT 0000h JMP $ END This example program consists of four statements. $TITLE is a directive , CSEG and END are control statements , and JMP is an 8051 MCU instruction.
Transcript
Page 1: What is an Assembler2

What is an Assembler?

An assembler is a program that translates symbolic code (assembly language) into executable object code. This object code can be executed with a 80C51-compatible microcontroller. If you have ever written a computer program directly in machine-recognizable form, such as binary or hexadecimal code, you will appreciate the advantages of programming in symbolic assembly language.

Assembly language operation codes (mnemonics) are easily remembered (MOV for move instructions, ADD for addition, and so on). You can also symbolically express addresses and values referenced in the operand field of instructions. Because you assign these names, you can make them as meaningful as the mnemonics for the instructions. For example, if your program must manipulate a date as data, you can assign it the symbolic name DATE. If your program contains a set of instructions used as a timing loop (executed repeatedly until a specific amount of time has passed), you can name the instruction group TIMER_LOOP.

An assembly program has three parts:

Machine instructions - Code the machine can execute. Detailed discussion of the machine instructions is in the hardware manuals of the 80C51 microcontroller.

Assembler directives - Define the program structure and symbols, and generate non executable code (data, messages, and so on.).

Assembler controls - Set assembly modes and direct assembly flow.

Assembly StatementsHome » Writing Assembly Programs » Assembly Statements

Assembly program source files are made up of statements that may include controls, assembler control statements, or 8051 MCU instructions (mnemonics). For example:

$TITLE(Demo Program #1) CSEG AT 0000h JMP $ END

This example program consists of four statements. $TITLE is a directive, CSEG and END are control statements, and JMP is an 8051 MCU instruction.

Each line of an assembly program can contain only one directive, control statement, or MCU instruction. Statements must be contained in exactly one line. Multi–line statements are not allowed.

Statements in x51 assembly programs are not column sensitive. Directives, control statements, or MCU instructions may start in any column. Indentation used in the examples in this manual is done for program clarity and is neither required nor expected by the assembler. The only exception is that arguments and instruction operands must be separated from directives, control statements, or MCU instructions by at least one space.

Page 2: What is an Assembler2

All x51 assembly programs must include the END control statement. This control statement signals to the assembler that this is the end of the assembly program. Any MCU instructions, directives, or control statements found after the END control statements are ignored. The shortest valid assembly program contains only an END control statement.

ControlsHome » Writing Assembly Programs » Assembly Statements » Controls

Assembler controls instruct the assembler how to process subsequent assembly language instructions. Controls also provide a way for you to define program constants and reserve space for variables.

Assembler controls direct the operation of the assembler when generating a listing file or object file. Typically, controls do not impact the code that is generated by the assembler. Controls can be specified on the command line or within an assembler source file.

The conditional assembly controls are the only assembler controls that will impact the code that is assembled by the Ax51 assembler. The IF, ELSE, ENDIF, and ELSEIF assembler control statements provide a powerful set of conditional operators that can be used to include or exclude certain parts of your program from the assembly.

The topic Control Statements describes the available assembler controls in detail and provides an example of each. Refer to this topic for more information about control statements.

InstructionsHome » Writing Assembly Programs » Assembly Statements » Instructions

Assembly language instructions specify the program code that is to be assembled by the Ax51 assembler. The Ax51 assembler translates the assembly instructions in your program into machine code and stores the resulting code in an object file.

Assembly instructions have the following general format:

« label: » mnemonic « operand » « , operand » « /, operand » « ; comment »

Where

label symbol name that is assigned the address at which the instruction is located.mnemonic is the ASCII text string that symbolically represents a machine language

instruction.operand is an argument that is required by the specified mnemonic.comment is an optional description or explanation of the instruction. A comment may contain

any text you wish. Comments are ignored by the assembler.

Refer to the x51 microcontrollers 8051 Instruction Set Manual, where they are listed by mnemonic and by machine language opcode, for more information about assembler instructions.

Page 3: What is an Assembler2

CommentsHome » Writing Assembly Programs » Comments

Comments are lines of text that you may include in your program to identify and explain the program. Comments are ignored by the Ax51 assembler and are not required in order to generate working programs.

You may include comments anywhere in your assembler program. Comments must be preceded with a semicolon character (;). A comment can appear on a line by itself or can appear at the end of an instruction. For example:

;This is a comment NOP ;This is also a comment

When the assembler recognizes the semicolon character on a line, it ignores subsequent text on that line. Anything that appears on a line to the right of a semicolon will be ignored by the Ax51 assembler. Comments have no impact on object file generation or the code contained therein.

Symbols and Symbol NamesHome » Writing Assembly Programs » Symbols and Symbol Names

A symbol is a name that you define to represent a value, text block, address, or register name. You can also use symbols to represent numeric constants and expressions.

Symbol Names

Symbols are composed of up to 31 characters from the following list:

A Z, a z, 0 9, _, and ?

A symbol name can start with any of these characters except the digits 0 9.

Symbols can be defined in a number of ways. You may define a symbol to represent an expression using the EQU or SET control statements:

NUMBER_FIVE EQU 5TRUE_FLAG SET 1FALSE_FLAG SET 0

You may define a symbol to be a label in your assembly program:

LABEL1: DJNZ R0, LABEL1

You can define a symbol to refer to a variable location:

SERIAL_BUFFER DATA 99h

Symbols are used throughout assembly programs. A symbolic name is much easier to understand and remember than an address or numeric constant. The following topics provide more information about how to use and define

Page 4: What is an Assembler2

LabelsHome » Writing Assembly Programs » Labels

A label defines a "place" (an address) in your program or data space. All rules that apply to symbol names also apply to labels. When defined, a label must be the first text field in a line. It may be preceded by tabs or spaces. A colon character (:) must immediately follow the symbol name to identify it as a label. Only one label may be defined on a line. For example:

LABEL1: DS 2LABEL2: ;label by itselfNUMBER: DB 27, 33, 'STRING', 0 ;label at a messageCOPY: MOV R6, #12H ;label in a program

In the above example, LABEL1, LABEL2, NUMBER, and COPY are all labels.

When a label is defined, it receives the current value of the location counter of the currently selected segment. Refer to Location Counter for more information about the location counter.

You may use a label just like you would use a program offset within an instruction. Labels can refer to program code, to variable space in internal or external data memory, or can refer to constant data stored in the program or code space.

You may use a label to transfer program execution to a different location. The instruction immediately following a label can be referenced by using the label. Your program can jump to or make a call to the label. The code immediately following the label will be executed.

You may use labels to provide information to simulators and debuggers. A simulator or debugger can provide the label symbols while debugging. This can help to simplify the debugging process.

Labels may only be defined once. They may not be redefined.

Using Operands and ExpressionsHome » Writing Assembly Programs » Using Operands and Expressions

Operands are arguments, or expressions, that are specified along with assembler directives or instructions. Assembler directives require operands that are constants or symbols. For example:

VVV EQU 3 DS 10h

Assembler instructions support a wider variety of operands than do directives. Some instructions require no operands and some may require up to 3 operands. Multiple operands are separated by commas. For example:

MOV R2, #0

The number of operands that are required and their types depend on the instruction or directive that is specified. In the following table, the first four operands can also be expressions. Instruction operands can be classified as one the following types:

Page 5: What is an Assembler2

Operand Type Description

Immediate Data Symbols or constants the are used as an numeric value.

Direct Bit Address Symbols or constants that reference a bit address.

Program Addresses Symbols or constants that reference a code address.

Direct Data Addresses Symbols or constants that reference a data address.

Indirect Addresses Indirect reference to a memory location, optionally with offset.

Special Assembler Symbol Register names.

Special Assembler SymbolsHome » Writing Assembly Programs » Special Assembler Symbols

The Ax51 assembler defines and reserves names of the x51 register set. These predefined names are used in x51 programs to access the processor registers. Following, is a list of the each of the 8051, 80C51MX, and 251 registers along with a brief description:

Register Description

A Represents the 8051 Accumulator. It is used with many operations including multiplication and division, moving data to and from external memory, Boolean operations, etc.

DPTR The DPTR register is a 16 bit data pointer used to address data in XDATA or CODE memory.

PC The PC register is the 16 bit program counter. It contains the address of the next instruction to be executed.

C The Carry flag; indicates the status of operations that generate a carry bit. It is also used by operations that require a borrow bit.

AB The A and B register pair used in MUL and DIV instructions.

R0 – R7 The eight 8 bit general purpose 8051 registers in the currently active register bank. A Maximum of four register banks are available.

AR0 – AR7

Represent the absolute data addresses of R0 through R7 in the current register bank. The absolute address for these registers changes depending on the register bank that is currently selected. These symbols are only available when the USING assembler statement is given. Refer to the USING assembler statement for more information on selecting the register bank. These representations are suppressed by the NOAREGS directive off the Cx51 compiler.

PR0, PR1

The Universal Pointer Registers of the 80C51MX architecture. Universal Pointer can access the complete 16MB address space of the 80C51MX. PR0 is composed of registers R1, R2, and R3. PR1 is composed of registers R5, R6, and R7.

EPTR Additional extended data pointer register of the 80C51MX architecture. EPTR may be used to access the complete memory space.

Immediate DataHome » Writing Assembly Programs » Immediate Data

An immediate data operand is a numeric expression that is encoded as a part of the machine language instruction. Immediate data values are used literally in an instruction to

Page 6: What is an Assembler2

change the contents of a register or memory location. The pound (or number) sign (#) must precede any expression that is to be used as an immediate data operand. The following shows some examples of how the immediate data is typically used:

MY_VAL EQU 50H ; an equate symbol

MOV A,IO_PORT2 ; direct memory access to DATA MOV A,#0E0h ; load 0xE0 into the accumulator MOV DPTR,#0x8000 ; load 0x8000 into the data pointer ANL A,#128 ; AND the accumulator with 128 XRL A,#0FFh ; XOR A with 0ffh MOV R5,#MY_VAL ; load R5 with the value of MY_VAL

Memory AccessHome » Writing Assembly Programs » Memory Access

A memory access reads or writes a value in to the various memory spaces of the A51 system.

Direct memory access encodes the memory address in the instruction that to reads or writes the memory. With direct memory accesses, you may access variables in the memory class DATA and BIT.

Indirect memory accesses uses the content of a register in the instruction that reads or writes into the memory. With indirect address operands it is possible to access all memory classes of the A51.

The examples in DATA and BIT show how to access the different memory classes of an A51 system.

DATAHome » Writing Assembly Programs » Memory Access » DATA

Memory locations in the memory class DATA can be addressed with both direct and indirect memory accesses. Special Function Registers (SFR) of the A51 have addresses above 0x80 in the DATA memory class. SFR locations can only be addressed with direct memory accesses. An indirect memory access to SFRs is not supported in the A51 microcontrollers.

Example for all 8051 variants

?DT?myvar SEGMENT DATA ; define a SEGMENT of class DATA RSEG ?DT?myvarVALUE: DS 1 ; reserve 1 BYTE in DATA space

IO_PORT2 DATA 0A0H ; special function registerVALUE2 DATA 20H ; absolute memory location

?PR?myprog SEGMENT CODE ; define a segment for program code RSEG ?PR?myprog MOV A,IO_PORT2 ; direct memory access to DATA ADD A,VALUE MOV VALUE2,A MOV R1,#VALUE ; load address of VALUE to R1

Page 7: What is an Assembler2

ADD A,@R1 ; indirect memory access to VALUE

BITHome » Writing Assembly Programs » Memory Access » BIT

Memory locations in the memory class BIT are addressed with the bit instructions of the 8051. The Special Function Registers (SFR) that are located in bit-addressable memory locations can be addressed with bit instructions. Bit-addressable SFR locations are: 80H, 88H, 90H, 98H, 0A0H, 0A8H, 0B0H, 0B8H, 0C0H, 0C8H, 0D0H, 0D8H, 0E0H, 0E8H, 0F0H, and 0F8H.

Example for all 8051 variants

?BI?mybits SEGMENT BIT ; define a SEGMENT of class BIT RSEG ?BI?mybitsFLAG: DBIT 1 ; reserve 1 Bit in BIT spaceP1 DATA 90H ; 8051 SFR PORT1GREEN_LED BIT P1.2 ; GREEN LED on I/O PORT P1.2

?PR?myprog SEGMENT CODE ; define a segment for program code RSEG ?PR?myprog SETB GREEN_LED ; P1.2 = 1 JB FLAG,is_on ; direct memory access to DATA SETB FLAG CLR ACC.5 ; reset bit 5 in register A :is_on: CLR FLAG CLR GREEN_LED ; P1.2 = 0

IDATAHome » Writing Assembly Programs » Memory Access » IDATA

Variables in this memory class are accessed via registers R0 or R1.

Example for all 8051 variants

?ID?myvars SEGMENT IDATA ; define a SEGMENT of class IDATA RSEG ?EB?mybitsBUFFER: DS 100 ; reserve 100 Bytes

?PR?myprog SEGMENT CODE ; define a segment for program code RSEG ?PR?myprog MOV R0,#BUFFER ; load the address in R0 MOV A,@R0 ; read memory location buffer INC R0 ; increment memory address in R0 MOV @R0,A ; write memory location buffer+1

EDATAHome » Writing Assembly Programs » Memory Access » EDATA

The EDATA memory is only available in the NXP 80C51MX.

Page 8: What is an Assembler2

In the NXP 80C51MX, the EDATA memory can be accessed via EPTR or the Universal Pointers PR0 and PR1. Universal Pointers can access any memory location in the 16MB address space.

Example for NXP 80C51MX

?ED?my_seg SEGMENT EDATA ; define a SEGMENT of class EDATA RSEG ?ED?my_segSTRING: DS 100 ; reserve 100 Bytes

?PR?myprog SEGMENT CODE ; define a segment for program code RSEG ?PR?myprog MOV R1,#BYTE0 STRING ; load address of STRING in PR0 MOV R2,#BYTE1 STRING MOV R3,#BYTE2 STRING MOV A,@PR0 ; load first byte of STRING in A

XDATAHome » Writing Assembly Programs » Memory Access » XDATA

The XDATA memory class can be accessed with the instruction MOVX via the register DPTR. A single page of the XDATA memory can be also accessed via the registers R0, R1. At the C Compiler level this memory type is called pdata and the segment prefix ?PD? is used. The high address for this pdata page is typically set with the P2 register. But in new 8051 variants there are also dedicated special function registers that define the XDATA page address.

Example for all 8051 variants

?XD?my_seg SEGMENT XDATA ; define a SEGMENT of class XDATA RSEG ?ED?my_segXBUFFER: DS 100 ; reserve 100 Bytes

?PD?myvars SEGMENT XDATA INPAGE ; define a paged XDATA segment RSEG ?PD?myvarsVAR1: DS 1 ; reserve 1 byte

?PR?myprog SEGMENT CODE ; define a segment for program code RSEG ?PR?myprog MOV P2,#HIGH ?PD?myvars ; load page address register : MOV DPTR,#XBUFFER ; load address MOVX A,@DPTR ; access via DPTR MOV R1,#VAR1 ; load address MOVX @R1,A ; access via R0 or R1

CODEHome » Writing Assembly Programs » Memory Access » CODE

CODE memory can be accessed with the instruction MOVC via the DPTR register.

Example for all 8051 variants

Page 9: What is an Assembler2

?CO?my_seg SEGMENT CODE ; define a SEGMENT of class CODE RSEG ?CO?my_segTABLE: DB 1,2,4,8,0x10 ; a table with constant values

?PR?myprog SEGMENT CODE ; define a segment for program code RSEG ?PR?myprog MOV DPTR,#TABLE ; load address of table MOV A,#3 ; load offset into table MOVC A,@A+DPTR ; access via MOVC instruction

Program AddressesHome » Writing Assembly Programs » Memory Access » Program Addresses

Program addresses are absolute or relocatable expressions with the memory class CODE or ECODE. Typically, program addresses are used in jump and call instructions. For indirect jumps or calls, it is required to load a program address in a register or a jump table. The following jumps and calls are possible:

Program Addresses Description

SJMP JZ JNZ … Relative jumps include conditional jumps (CJNE, DJNZ, JB, JBC, JC, …) and the unconditional SJMP instruction. The addressable offset is –128 to +127 bytes from the first byte of the instruction that follows the relative jump. When you use a relative jump in your code, you must use an expression that evaluates to the code address of the jump destination. The assembler does all the offset computations. If the address is out of range, the assembler will issue an error message.

ACALL AJMP In-block jumps and calls permit access only within a 2KByte block of program space. The low order 11 bits of the program counter are replaced when the jump or call is executed. For Dallas 390 contiguous mode the block size is 512KB or 19 bits. If ACALL or AJMP is the last instruction in a block, the high order bits of the program counter change and the jump will be within the block following the ACALL or AJMP.

LCALL LJMP Long jumps and calls allow access to any address within a 64KByte segment of program space. The low order 16 bits of the program counter are replaced when the jump or call is executed. For Dallas 390 contiguous mode: the block size is 16MB or 24 bits. On NXP 80C51MX: if LCALL or LJMP is the last instruction in a 64KByte segment, the high order bits of the program counter change and the jump will into the segment following the LCALL or LJMP.

ECALL EJMP Extended jumps and calls allow access within the extended program space of the NXP 80C51MX.

CALL JMP Generic jumps and calls are two instruction mnemonics that do not represent a specific opcode. JMP may assemble to SJMP, AJMP, LJMP or EJMP. CALL may assemble to ACALL, LCALL or ECALL. These generic mnemonics always evaluate to an instruction, not necessarily the shortest, that will reach the specified program address operand.

Page 10: What is an Assembler2

Example for all 8051 Variants

EXTRN CODE (my_function)

CSEG AT 3 JMP ext_int ; an interrupt vector

?PR?myintr SEGMENT CODE ; define a segment for program code RSEG ?PR?myintrext_int: JB FLAG,flag_OK INC my_varflag_OK: CPL FLAG RETI?PR?myprog SEGMENT CODE INBLOCK ; a segment within a 2K block RSEG ?PR?myprogfunc1: CALL sub_func ; will generate ACALLloop: CALL my_function ; external function -> LCALL MOV A,my_var JNZ loop RET

sub_func: CLR FLAG MOV R0,#20loop1: CALL my_function DJNZ R0,loop1 RET

Example with EJMP, ECALL for NXP 80C51MX

EXTRN ECODE:FAR (my_farfunc)

Reset EQU ECODE 0FF0000H ; Reset location on 251

?PR?my_seg SEGMENT ECODE ; define a SEGMENT of class EDATA RSEG ?PR?my_seg

func1 PROC FAR ; far function called with ECALL CALL func2 ; generates LCALL CALL my_farfunc ; generates ECALL JNB Flag,mylab EJMP Resetmylab: ERET ENDP

func2 PROC NEAR CALL my_farfunc ; generates ECALL RET ENDP

Expressions and OperatorsHome » Writing Assembly Programs » Expressions and Operators

Page 11: What is an Assembler2

An operand may be a numeric constant, a symbolic name, a character string or an expression.

Operators are used to combine and compare operands within your assembly program. Operators are not assembly language instructions nor do they generate A51 assembly code. They represent operations that are evaluated at assembly time. Therefore, operators can only handle calculations of values that are known when the program is assembled.

An expression is a combination of numbers, character string, symbols, and operators that evaluate to a single 32 bit binary number (for A51: 16-bit binary number). Expressions are evaluated at assembly time and can, therefore, be used to calculate values that would otherwise be difficult to determine beforehand.

The following topics describe operators and expressions and how they are used in A51 assembly programs.

NumbersHome » Writing Assembly Programs » Expressions and Operators » Numbers

Numbers may be specified in hexadecimal (base 16), decimal (base 10), octal (base 8), and binary (base 2). The default representation is decimal. A decimal, octal, or binary number's first character must always be a digit (0-9). Hexadecimal numbers whose first character is not a digit (0-9) must be prefixed with a zero ('0').

The base of a number is specified by the last character in the number. A number that is specified without an explicit base is interpreted as decimal number.

The following table illustrates various types of numbers:

Base Suffix Legal Characters Examples

Hexadecimal H,h 0-9, A-F, a-f 1234H 99H 123H 0A0F0H 0FFH

Decimal D,d 0-9 1234 65590D 20d 123

Octal O,o,Q,q 0-7 177O 7777o 25O 123o 177777O

Binary B,b 0-1 1111B 10011111B 101010101B

Note

Hexadecimal numbers may be written using C notation. For example, 0x12AB.

Hexadecimal numbers must begin with a 0 if the first digit is A-F.

The dollar sign character ('$') may be used in numbers to make them more readable (as long it is not the first or last character). For example:

1111$0000$1010$0011B - is equivalent to - 1111000010100011B

1$2$3$4 - is equivalent to - 1234

Characters

Home » Writing Assembly Programs » Expressions and Operators » Characters

ASCII characters may be used in an expression to generate numeric values. Expressions may have up to two ASCII characters enclosed in single quotes ('). More than two characters in an expression causes an error. Following are several examples:

Page 12: What is an Assembler2

Expression Value

'A' 0041h

'AB' 4142h

'a' 0061h

'ab' 6162h

'' Error: Null string is invalid.

'ABC' Error: More than 2 characters.

Characters may be used anywhere in your program as a immediate data operand. For example:

LETTER_A EQU 'A'

TEST: MOV @R0, #'F'

SUBB A, #'0'

Character Strings

Home » Writing Assembly Programs » Expressions and Operators » Character Strings

Character strings can be used in combination with the DB assembler statement to define messages that are used in your Ax51 assembly program. Character strings must be enclosed within single quotes ('). For example:

KEYMSG: DB 'Press any key to continue.'

generates the hexadecimal data (50h, 72h, 65h, 73h, 73h, 20h, … 6Eh, 75h, 65h, 2Eh) starting at KEYMSG. You can mix string and numeric data on the same line. For example:

EOLMSG: DB 'End of line', 00h

appends the value 00h to the end of the string 'End of line'.

Two successive single quote characters can be used to insert a single quote into a string. For example:

MSGTXT: DB 'ISN''T A QUOTE REQUIRED HERE?'.

Location Counter

Home » Writing Assembly Programs » Expressions and Operators » Location Counter

Page 13: What is an Assembler2

The Ax51 assembler maintains a location counter for each segment which contains the offset of the instruction or data being assembled. The location counter increments after each line by the number of bytes of code or data in that line.

The location counter is initialized to 0 for each segment, but may be changed using the ORG statement.

The dollar sign character ('$') may be used in an expression to obtain the current value of the location counter. For example, the following uses the location counter to determine the length of a string.

msg: DB 'This is a message', 0

msg_len: EQU $-msg

You may use the location counter in instructions. For example, the following creates an infinite loop:

JMP $ ; While (1)

OperatorsHome » Writing Assembly Programs » Expressions and Operators » Operators

Operators may be unary (requiring one operand) or binary (requiring two operands). The combination of an operator and its operand(s) is an expression. Parentheses may be used in expressions with multiple operators to specify the order in which operators are evaluated. If no parentheses are used in an expression, operator precedence determines the evaluation order.

Following is the operator precedence table:

MBYTE

Level Operators

1 ( )

2 NOT HIGH LOWBYTE0 BYTE1 BYTE2 BYTE3

WORD0 WORD2MBYTE

3 Unary + Unary -

4 * / MOD

5 + -

6 SHL SHR

7 AND OR XOR

8 EQ = NE <> LT < LTE <= GT > GTE >=

Page 14: What is an Assembler2

( ) Assembler OperatorHome » Writing Assembly Programs » Expressions and Operators » Operators » ( )

Syntax 

None.

Example 

None.

* Assembler OperatorHome » Writing Assembly Programs » Expressions and Operators » Operators » *

Syntax

 

operand * operand

Description  

The multiplication operator ('*') multiplies the specified absolute operands. The result is absolute.

See Also   /, MOD

Example

 

MOV R1,#3*4

MOV R2,#99*45

+ Assembler OperatorHome » Writing Assembly Programs » Expressions and Operators » Operators » +

Syntax

 

+ operand

operand + operand

Description

  The plus sign ('+') is used as the unary plus operator and as the addition operator.

Page 15: What is an Assembler2

The unary plus operator is used to assign a positive value to the specified operand. This operator does effectively nothing to alter the value of the operand.

The addition operator is used to add the values of two operands which may be absolute or relocatable. The type of the resulting expression is determined by the operand types as shown in the following table:

Operand TypesResulting Expression Type

absolute + absolute absolute

absolute + relocatable relocatable

relocatable + absolute relocatable

relocatable + relocatable Error: Not allowed.Note

As a general rule, relocatable expressions must evaluate to a relocatable symbol plus or minus an optional constant value (displacement).

See Also   -

Example

 

labx: MOV R1, #1234+5678

MOV R2, labx+10h

- Assembler OperatorHome » Writing Assembly Programs » Expressions and Operators » Operators » -

Syntax

 

- operand

operand1 - operand2

Description

  The minus sign ('-') is used as the unary minus operator and as the subtraction operator.

The unary minus operator is used to change the sign of the specified operand. If the value of the operand is positive, the sign is changed to negative. If the value is negative, it is changed to positive.

The subtraction operator is used to subtract the value of operand2 from the value of operand1. The specified operands may be absolute or relocatable. The type of the resulting expression is determined by the operand types as shown in the following table:

Page 16: What is an Assembler2

Operand TypesResulting Expression Type

absolute - absolute absolute

absolute - relocatable Error: Not allowed.

relocatable - absolute relocatable

relocatable - relocatable absolute1

1. Relocatable operands are allowed if both are defined in the same parent section. External operands are not allowed.

Note

As a general rule, relocatable expressions must evaluate to a relocatable symbol plus or minus an optional constant value (displacement).

See Also   +

Example

 

labx: MOV R1, #5678-1234

laby: MOV R2, laby-labx

/ Assembler OperatorHome » Writing Assembly Programs » Expressions and Operators » Operators » /

Syntax

 

operand1 / operand2

Description  

The division operator ('/') divides the value of operand1 by the value of operand2. Both operands must be absolute. The result is absolute.

See Also   *, MOD

Example

 

MOV R1,#12/4

MOV R2,#99/9

Page 17: What is an Assembler2

Control StatementsHome » Control Statements

The Ax51 Assembler provides a number of control statements that permit you to define symbol values, reserve and initialize storage, and control the placement of your code.

These statements should not be confused with processor instructions or with assembler directives. They do not produce executable code and, with the exception of the DB, DD, and DW statements, they have no direct effect on the contents of code memory. These controls change the state of the assembler, define user symbols, and add information to the object file.

Control statements may be divided into the following categories:

Address Control

Statement Description

EVEN1 Forces the location counter to the next even address.

ORG Sets the location counter to a specifies offset or address.

USING Specifies which register bank to use.

Conditional Assembly

Statement Description

IF Begins an IF-ELSE-ENDIF block.

ELSEIF Begins an alternate IF block.

ELSE Begins an ELSE block.

ENDIF Terminates an IF block.

Memory Initialization

Statement Description

DB Allocates memory for one or more defined byte values.

DD1 Allocates memory for one or more defined double word values.

DW Allocates memory for one or more defined word values.

Memory Reservation

Statement Description

DBIT Reserves space for one or more bits.

DS Reserves space for one or more bytes.

DSB1 Reserves space for one or more bytes.

DSD1 Reserves space for one or more double words.

DSW1 Reserves space for one or more words.

Page 18: What is an Assembler2

Procedure Declaration

Statement Description

ENDP1 Defines the end of a function.

LABEL1 Assigns an address to a symbolic name.

PROC1 Defines the beginning of a function.

Program Linkage

Statement Description

EXTERN1 Defines external symbols.

EXTRN Defines external symbols.

NAME Specifies the name of the current module.

PUBLIC Defines symbols which may be used in other modules.

Segment Control

Statement Description

BSEG Defines an absolute bit segment.

CSEG Defines an absolute code segment.

DSEG Defines an absolute data segment.

ISEG Defines an absolute idata segment.

RSEG Selects a relocatable segment.

SEGMENT Defines a relocatable segment.

XSEG Defines an absolute xdata segment.

Symbol Definition

Statement Description

BIT Defines an address in bit space.

CODE Defines an address in code space.

DATA Defines an address in data space.

EQU Sets a permanent symbol value.

IDATA Defines an address in idata space.

LIT1 Assigns a text string to a symbol name.

SBIT Defines a bit SFR.

SET Sets or resets a symbol value.

SFR Defines a byte SFR.

SFR16 Defines a word SFR.

XDATA Defines an address in xdata space.

Page 19: What is an Assembler2

Miscellaneous

Statement Description

__ERROR__ Generates an error message.

END Signals the end of the assembly module.

Note

1. This directive is available in the AX51 Assembler only.

Page 20: What is an Assembler2
Page 21: What is an Assembler2

Symbols and Symbol NamesHome » Writing Assembly Programs » Symbols and Symbol Names

A symbol is a name that you define to represent a value, text block, address, or register name. You can also use symbols to represent numeric constants and expressions.

Symbol Names

Symbols are composed of up to 31 characters from the following list:

A Z, a z, 0 9, _, and ?

A symbol name can start with any of these characters except the digits 0 9.

Symbols can be defined in a number of ways. You may define a symbol to represent an expression using the EQU or SET control statements:

NUMBER_FIVE EQU 5TRUE_FLAG SET 1FALSE_FLAG SET 0

You may define a symbol to be a label in your assembly program:

LABEL1: DJNZ R0, LABEL1

You can define a symbol to refer to a variable location:

SERIAL_BUFFER DATA 99h

Symbols are used throughout assembly programs. A symbolic name is much easier to understand and remember than an address or numeric constant. The following topics provide more information about how to use and define symbols.

Labels

Labels are special cases of symbols. Labels are used only before statements that have physical addresses associated with them.

Examples of such statements are assembly language instructions, data storage directives (DB and DW), and data reservation directives (DS and DBIT). Labels must follow all the rules of symbol creation with the additional requirement that they be followed by a colon. The following are legal examples of label uses:

TABLE_OF_CONTROL_CONSTANTS:

DB 0,1,2,3,4,5 (Data storage)

MESSAGE: DB 'HELP' (Data storage)

VARIABLES: DS 10 (Data reservation)

Page 22: What is an Assembler2

BIT_VARIABLES: DBIT 16 (Data reservation)

START: MOV A,#23 (Assembly language instruction)

Directives

The Ax51 Assembler provides a number of directives you may use to control source file assembly. Directives are composed of one or more letters or digits and, unless otherwise specified, may be specified after the filename on the command line or within the source file when preceded by a dollar sign ('$'). For example:

A51 SAMPLE.A51 SYMBOLS DEBUG

or

$SYMBOLS DEBUG

or

$SYMBOLS$DEBUG

The source file to assemble is SAMPLE.A51 and SYMBOLS and DEBUG are the directives.

Assembler directives may be divided into two groups:

Primary directives are specified on the assembler command line or in first few lines of the assembly source file. These directives control how the assembler behaves for the entire module. If conflicting primary directives are specified on the command line and in the source file, the command line directive takes precedence.

General directives may be specified on the command line or anywhere in the source file. These directives control the immediate behaviour of the assembler and may be changed during assembly.

Note

Syntax is the same for directives specified on the command line and those specified in the source file.

Some directives may not be specified on the command line. If one of these directives is specified on the command line, the assembler generates a fatal error and aborts.

The following table is an alphabetical list of the control directives available in the Ax51 Assembler.

Directive Group Description

CASE Primary

Enables case-sensitive symbol names.

COND General

Includes (in the listing file) conditional source lines skipped by the preprocessor.

Page 23: What is an Assembler2

DATE Primary

Specifies the date to use in the listing file header.

DEBUG Primary

Includes debugging information in the object file.

DEFINE Primary

Defines C preprocessor symbols on the command line.

EJECT1 General

Inserts a form feed character into the listing file.

ELSE General

Assemble block if the condition of a previous IF is false.

ELSEIF General

Assemble block if condition is true and a previous IF or ELSEIF is false.

ENDIF General

Ends an IF block.

ERRORPRINT Primary

Specifies the file name for error messages.

GEN General

Includes all macro expansions in the listing file.

IF General

Assemble block if condition is true.

INCDIR Primary

Sets additional include file paths.

INCLUDE2 General

Includes the contents of another file.

LIST General

Includes the assembly source text in the listing file.

MACRO Primary

Enables preprocessor expansion of standard macros.

MOD_CONT Primary

Enables 24-bit contiguous addressing for Dallas Semiconductor devices.

MOD_MX51 Primary

Enables instruction set extensions for the Philips 80C51MX architecture.

MOD51 Primary

Enables code generation and defines SFRs for classic 8051 devices.

MPL Primary

Enables preprocessor expansion of MPL macros.

NOAMAKE Primary

Excludes build information from the object file.

NOCASE Primary

Disables case-sensitive symbol names. All symbols are converted to uppercase.

NOCOND Primary

Excludes (from the listing file) conditional source lines skipped by the preprocessor.

NODEBUG Primary

Excludes debugging information from the object file.

NOERRORPRINT Primary

Disables error messages output to the screen.

NOGEN General

Excludes macro expansions from the listing file.

NOLINES Primar Excludes line number information from the generated object

Page 24: What is an Assembler2

y module.

NOLIST General

Excludes the assembly source text from the listing file.

NOMACRO Primary

Disables preprocessor expansion of standard and MPL macros.

NOMOD51 Primary

Suppresses SFRs definitions for classic 8051 devices

NOMPL Primary

Disables preprocessor expansion of MPL macros.

NOOBJECT Primary

Disables object file generation.

NOPRINT Primary

Disables listing file generation.

NOREGISTERBANK

Primary

Disables memory space reservation for register banks.

NOSYMBOLS Primary

Excludes the symbol table from the listing file.

NOSYMLIST General

Excludes subsequently defined symbols from the symbol table.

NOXREF Primary

Excludes the cross-reference table from the listing file.

OBJECT Primary

Specifies the name for the object file.

PAGELENGTH Primary

Specifies the number of lines on a page in the listing file.

PAGEWIDTH Primary

Specifies the number of characters on a line in the listing file.

PRINT Primary

Specifies the name for the listing file.

REGISTERBANK Primary

Reserves memory space for register banks.

REGUSE General

Specifies registers modified by the specified function.

RESET General

Sets symbols, which may be tested by IF or ELSEIF, to false.

RESTORE1 General

Restores settings for the LIST and GEN directives.

SAVE1 General

Saves settings for the LIST and GEN directives.

SET General

Sets symbols, which may be tested by IF or ELSEIF, to true or a specified value.

SYMBOLS Primary

Includes the symbol table in the listing file.

SYMLIST General

Includes subsequently defined symbols in the symbol table.

TITLE Primary

Specifies the page header title in the listing file.

XREF Primary

Includes the cross-reference table in the listing file.

Page 25: What is an Assembler2

Note

1. These directives may not be specified on the command line. They may only be specified in the source file.

2. Primary directives may not be specified after an INCLUDE directive.

Page 26: What is an Assembler2

Control Statements

The Ax51 Assembler provides a number of control statements that permit you to define symbol values, reserve and initialize storage, and control the placement of your code.

These statements should not be confused with processor instructions or with assembler directives. They do not produce executable code and, with the exception of the DB, DD, and DW statements, they have no direct effect on the contents of code memory. These controls change the state of the assembler, define user symbols, and add information to the object file.

Control statements may be divided into the following categories:

Address Control

Statement Description

ORG Sets the location counter to a specifies offset or address.

USING Specifies which register bank to use.

Conditional Assembly

Statement Description

IF Begins an IF-ELSE-ENDIF block.

ELSEIF Begins an alternate IF block.

ELSE Begins an ELSE block.

ENDIF Terminates an IF block.

Memory Initialization

Statement Description

DB Allocates memory for one or more defined byte values.

DW Allocates memory for one or more defined word values.

Memory Reservation

Statement Description

DBIT Reserves space for one or more bits.

Page 27: What is an Assembler2

DS Reserves space for one or more bytes.

Program Linkage

Statement Description

EXTRN Defines external symbols.

NAME Specifies the name of the current module.

PUBLIC Defines symbols which may be used in other modules.

Segment Control

Statement Description

BSEG Defines an absolute bit segment.

CSEG Defines an absolute code segment.

DSEG Defines an absolute data segment.

ISEG Defines an absolute idata segment.

RSEG Selects a relocatable segment.

SEGMENT Defines a relocatable segment.

XSEG Defines an absolute xdata segment.

Symbol Definition

Statement Description

BIT Defines an address in bit space.

CODE Defines an address in code space.

DATA Defines an address in data space.

EQU Sets a permanent symbol value.

IDATA Defines an address in idata space.

SBIT Defines a bit SFR.

Page 28: What is an Assembler2

SET Sets or resets a symbol value.

SFR Defines a byte SFR.

SFR16 Defines a word SFR.

XDATA Defines an address in xdata space.

Miscellaneous

Statement Description

__ERROR__ Generates an error message.

END Signals the end of the assembly module.

Page 29: What is an Assembler2

ORG Assembler Statement

Syntax ORG expression

Description

The ORG statement alters the location counter for the current segment and sets a new origin for subsequent statements. The expression must be a simple relocatable expression with no forward references. Only absolute addresses or symbol values in the current segment may be used. The dollar-sign character ('$'), which represents the current value of the location counter, may be used in the expression.

When the ORG statement is encountered, the assembler calculates the value of the expression and changes the location counter.

If the ORG statement appears in an absolute segment, the location counter is assigned the absolute address value specified. The location counter may not be set to an address below the base address of the segment.

If the ORG statement appears in a relocatable segment, the location counter is assigned the offset of the specified expression. For example, if the relocatable segment starts at address 1000h and if the ORG expression has a value of 1234h, the absolute address of the next statement is 2234h (1000h + 1234h).

The ORG statement changes the location counter, which may create a gap, but does not create a new segment.

Note

It is possible to use the ORG statement to change the location counter and overwrite (or overlay) existing code or data. This is supported because of legacy programs that used this technique to define multiple variables at the same physical address. No warning is generated if the ORG statement is used this way.

See Also SEGMENT

Example ORG 100hORG RESTARTORG EXIT1ORG ($ + 15) AND 0FFF0h

Page 30: What is an Assembler2

USING Assembler Statement

Syntax USING expression

Description

The USING statement specifies the register bank (0-3) expression to use for encoding the >AR0-AR7 registers. The register bank selected is noted in the object file and the memory area is reserved by the linker.

Some 8051 instructions (like PUSH and POP) allow only absolute addresses to be used. The assembler replaces absolute registers (AR0-AR7) with the physical address of the register in the current register bank. So, while the instruction PUSH R0 is not valid, PUSH AR0 is valid. However, the assembler must know which register bank is used so that the correct physical address is calculated. This is the purpose for the USING statement.

The USING statement does not generate any code to switch the current register bank. The assembler program must select the correct register bank. For example, the following code selects register bank 2:

PUSH PSW ; save the current register bankMOV PSW, #(2 SHL 3) ; set register bank 2...POP PSW ; restore saved register bank

The physical address is calculated as follows:

(register bank × 8) + register

Note

Exercise caution when using the EQU statement to define a symbol for an absolute register (AR0-AR7). When using EQU, the symbol value is calculated at the time it is defined (not when it is used). If the register bank is subsequently changed with the USING statement, the defined symbol will have the incorrect address and the code generated is likely to fail.

Example USING 3 ; select register bank 3PUSH AR2 ; push R2 in bank 3 (address 1Ah)

USING 1 ; select register bank 1PUSH AR7 ; push R7 in bank 1 (address 1Fh)

Page 31: What is an Assembler2

DB Assembler Statement

Syntax « label: » DB expression « , expression ... »

Description

The DB statement initializes memory with one or more byte values. label is a symbol that is assigned the current memory address. expression is a byte value that is stored in memory. Each expression may be a symbol, a string, or an expression.

The DB statement may be specified only within a code or const segment. An error is generated if it is used in a different segment.

See Also DBIT, DD, DS, DSB, DSD, DSW, DW

Example MSG: DB 'Press A Key To Continue', 0TAB: DB 2, 3, 5, 7, 11, 13, 17, 19, ';'

Page 32: What is an Assembler2

DBIT Assembler Statement

Syntax « label: » DBIT expression

Description

The DBIT statement reserves the specified number of bits in a bit or ebit segment. label is a symbol that is assigned the current memory address. expression is the number of bits to reserve.

This statement reserves space in the current memory space and increments the location counter by the number of bits reserved.

See Also DS, DSB, DSD, DSW

Example A_FLAG: DBIT 1B_FLAG: DBIT 1

Page 33: What is an Assembler2

DS Assembler Statement

Syntax « label: » DS expression

Description

The DS statement reserves the specified number of bytes in the current memory space. label is a symbol that is assigned the current memory address. expression is the number of bytes to reserve.

This statement reserves space and increments the location counter by the number of bytes reserved.

Note

See Also DBIT, DSB, DSD, DSW

Example GAP: DS (($ + 15) AND 0FFF0h) - $ ; 16-byte alignment DS 10TIME: DS 8

Page 34: What is an Assembler2

EXTRN Assembler Statement

Syntax EXTRN class (symbol « , symbol ... »)

Description The EXTRN statement (which may appear anywhere in the assembler source file) specifies symbols that the current source file uses but which are defined in other object modules. The module where the symbols are defined must export them using a PUBLIC statement.

Valid classes are:

class Description

BIT A symbol located in BIT memory space.

CODE A symbol located in CODE space.

DATA A symbol located in DATA space.

IDATA A symbol located in IDATA memory.

XDATA A symbol located in XDATA memory.

NUMBER A symbol located in any memory space.

The linker resolves all external symbols and verifies that the classes and types match. Symbols whose class is NUMBER match any memory class.

See Also EXTERN, PUBLIC

Example EXTRN CODE (main)EXTRN NUMBER (tabsize)EXTRN DATA (counter)

Page 35: What is an Assembler2

DW Assembler Statement

Syntax « label: » DW expression « , expression ... »

Description

The DW statement initializes memory with one or more word (2-byte) values. label is a symbol that is assigned the current memory address. expression is a word value that is stored in memory. Each expression may be a symbol, a string, or an expression.

The DW statement may be specified only within a code or const segment. An error is generated if it is used in a different segment.

See Also DB, DBIT, DD, DS, DSB, DSD, DSW

Example TABLE: DW TABLE, TABLE+10, HEREHERE: DW 0CTAB: DW CASE0, CASE1, CASE2, CASE3 DW $

Page 36: What is an Assembler2

BSEG Assembler Statement

Syntax BSEG « AT address »

Description

The BSEG statement selects an absolute segment within BIT space.

If the optional address is included, the assembler starts the absolute segment from that address. The valid address range is 20h-2Fh.

If the optional address is omitted, the assembler starts the absolute segment from address 0 (if no prior absolute BIT segment was defined). If an absolute BIT segment was previously defined, the assembler continues from the end of that segment.

Note

The start address must be an absolute expression.

The AX51 Assembler converts BSEG statements into the following:

?BI?modulename?n SEGMENT OFFS address

Where

modulename is the name of the source file.

n is a sequential number.

address is the address specified in the BSEG statement.

See Also BIT, CSEG, DSEG, ISEG, XSEG

Example BSEG AT 10 ; absolute BIT segment at 0x20+10 bits = 0x21.2DEC_FLAG: DBIT 1 ; absolute bit with the name DEC_FLAGINC_FLAG: DBIT 1 ; absolute bit with the name INC_FLAG

Page 37: What is an Assembler2

CSEG Assembler Statement

Syntax CSEG « AT address »

Description

The CSEG statement selects an absolute segment within CODE space.

If the optional address is included, the assembler starts the absolute segment from that address. The valid address range is 0000h-0FFFFh.

If the optional address is omitted, the assembler starts the absolute segment from address 0 (if no prior absolute CODE segment was defined). If an absolute CODE segment was previously defined, the assembler continues from the end of that segment.

Note

The start address must be an absolute expression.

The AX51 Assembler converts CSEG statements into the following:

?CO?modulename?n SEGMENT OFFS address

Where

modulename is the name of the source file.

n is a sequential number.

address is the address specified in the CSEG statement.

See Also BSEG, CODE, DSEG, ISEG, XSEG

Example CSEG AT 0003h ; absolute code segement at address 0x3VECT_0: LJMP ISR_0 ; jump instruction for the interrupt vector location

CSEG AT 0x100 ; absolute code segment at address 0x100CRight: DB "(C) MyCompany" ; copyright string at fixed location

CSET AT 1000H ; absolute code segment at address 0x1000Parity_TAB: ; table with the name Parity_TAB DB 00H ; fixed encoding for parity information DB 01H DB 01H DB 00H

Page 38: What is an Assembler2
Page 39: What is an Assembler2

DSEG Assembler Statement

Syntax DSEG « AT address »

Description

The DSEG statement selects an absolute segment within DATA space.

If the optional address is included, the assembler starts the absolute segment from that address. The valid address range is 00h-0FFh (data memory resides from 00h-7Fh and SFRs reside from 80h-0FFh).

If the optional address is omitted, the assembler starts the absolute segment from address 0 (if no prior absolute DATA segment was defined). If an absolute DATA segment was previously defined, the assembler continues from the end of that segment.

Note

The start address must be an absolute expression.

The AX51 Assembler converts DSEG statements into the following:

?DT?modulename?n SEGMENT OFFS address

Where

modulename is the name of the source file.

n is a sequential number.

address is the address specified in the DSEG statement.

Example DSEG AT 0x40 ; absolute DATA segment at 40HTMP_A: DS 2 ; absolute data word variable with name TMP_ATEM_B: DS 4 ; absolute data dword (32-bit) variable with name TMP_B

Page 40: What is an Assembler2

ISEG Assembler Statement

Syntax   ISEG « AT address »

Description

  The ISEG statement selects an absolute segment within IDATA space.

If the optional address is included, the assembler starts the absolute segment from that address. The valid address range is 00h-0FFh.

If the optional address is omitted, the assembler starts the absolute segment from address 0 (if no prior absolute IDATA segment was defined). If an absolute IDATA segment was previously defined, the assembler continues from the end of that segment.

Note

The start address must be an absolute expression.

The AX51 Assembler converts ISEG statements into the following:

?ID?modulename?n SEGMENT OFFS address

Where

modulename is the name of the source file.

n is a sequential number.

address is the address specified in the ISEG statement.

See Also   BSEG, CSEG, DSEG, IDATA, XSEG

Example   ISEG AT 0xC0 ; absolute IDATA segment at 0C0HTMP_IA: DS 2 ; absolute idata word variable with name TMP_IATEM_IB: DS 4 ; absolute idata dword (32-bit) variable with name TMP_IB

Page 41: What is an Assembler2

SEGMENT Assembler Statement

Syntax segname SEGMENT class relocation alignment

Description

The SEGMENT statement declares a generic segment along with memory class and segment location options.

Where

segname

specifies the symbol name to assign to the segment. This symbol is references by subsequent RSEG statements. It may also be used in expressions to represent the base or starting address of the combined segment.

class is the memory classification for the segment. The class specifies the memory space where the segment is located.

relocation

determines what relocation options are available to the linker for this segment.

alignment

determines what address alignment options are available to the linker for this segment.

The name of each segment in a source module must be unique. The linker combines segments that have the same type.

Class

The segment class specifies the memory space for the segment and is used by the linker to access all segments that belong to that class. The following table lists the basic classes.

class Description

BIT The BIT address space (from 20h-2Fh).

CODE The CODE address space (from 0000h-0FFFFh).

DATA The DATA address space (from 00h-7Fh).

IDATA The IDATA address space (from 00h-0FFh).

XDATA The XDATA address space (from 0000h-0FFFFh).

Following are a few examples of segments defined using the basic classes.

Page 42: What is an Assembler2

seg1 SEGMENT XDATAseg3 SEGMENT DATA

Relocation

The relocation type specifies how the linker may relocate the segment. The following table lists the valid kinds of relocation.

relocation Description

BITADDRESSABLE

specifies that the segment is located in bit-addressable memory. This relocation type is allowed only for segments in the DATA class whose length does not exceed 16 bytes.

INBLOCK specifies that the segment must be located in a single 2048-byte block. This relocation type may be specified only for segments in the CODE class. This is typically used for segments with routines that use ACALL and AJMP instructions.

INPAGE specifies that the segment must be located in a single 256-byte page.

OVERLAYABLE specifies that the segment may be overlaid with and share the memory of other segments. Segments declared with the OVERLAYABLE relocation type may be overlaid with each other. OVERLAYABLE segments must be declared using the naming conventions of the C51.

Alignment

The alignment is optional and specifies how the linker allocates the segment. The following table lists the valid alignment types.

1

alignment Description

BIT1 specifies bit alignment for the segment. This is the default for all segments with the class BIT.

BYTE specifies byte alignment for the segment. This is the default for all segments, except for segments with the class BIT.

PAGE specifies 256-byte page alignment for the segment. The segment start must be on a 256-byte page boundary.

Page 43: What is an Assembler2

See Also BSEG, CSEG, DSEG, ISEG, RSEG, XSEG

Example ; a segment with the name ?ID?IDS and the memory class IDATA.?ID?IDS SEGMENT IDATA

; a segment with the name ?XD?ABC in the memory class XDATA. The; alignment PAGE forces to segment to start on a 256 byte page boundary.?XD?ABS SEGMENT XDATA PAGE

RSEG Assembler Statement

Syntax RSEG segment

Description

The RSEG statement selects a relocatable segment that was previously declared using the SEGMENT statement.

See Also SEGMENT

Example MYPROG SEGMENT CODE ; Declare the segment RSEG MYPROG ; Select the segment

Page 44: What is an Assembler2

2.7. Bit Addressing

The period (.) has special meaning to the Cross Assembler when

used in a symbol. It is used to explicitly specify a bit in a

bit-addressable symbol. For example, it you wanted to specify

the most significant bit in the Accumulator, you could write

ACC.7, where ACC was previously defined as the Accumulator

address. The same bit can also be selected using the physical

address of the byte it's in. For example, the Accumulator's

physical address is 224. The most significant bit of the

Accumulator can be selected by specifying 224.7. If the symbol

ON was defined to be equal to the value 7, you could also specify

the same bit by either ACC.ON or 224.ON.

2.8. ASCII Literals

Printable characters from the ASCII character set can be used

directly as an immediate operand, or they can used to define

symbols or store ASCII bytes in Program Memory. Such use of the

ASCII character set is called ASCII literals. ASCII literals are

identified by the apostrophe (') delimiter. The apostrophe

itself can be used as an ASCII literal. In this case, use two

apostrophes in a row. Below are examples of using ASCII

literals.

MOV A,#'m' ;Load A with 06DH (ASCII m)

QUOTE EQU '''' ;QUOTE defined as 27H (ASCII single quote)

DB '8051' ;Store in Program Memory

Page 45: What is an Assembler2

2.9. Comments

Comments are user defined character strings that are not

processed by the Cross Assembler. A comment begins with a

semicolon ( ; ) and ends at the carriage return/line feed pair

that terminates the line. A comment can appear anywhere in a

line, but it has to be the last field. The following are

examples of comment lines:

; Begin initialization routine here

$TITLE(8051 Program Vers. 1.0) ;Place version number here

TEN EQU 10 ;Constant

; Comment can begin anywhere in a line

MOV A,Serial_Port_Buffer ; Get character

2.10. The Location Counter

The Cross Assembler keeps a location counter for each of the five

segments (code, internal data, external data, indirect internal

data and bit data). Each location counter is initialized to zero

and can be modified using Assembler Directives described in

Chapter 5.

The dollar sign ($) can be used to specify the current value of

the location counter of the active segment. The following are

examples of how this can be used:

JNB FLAG,$ ;Jump on self until flag is reset

CPYRGHT: DB 'Copyright, 1983'

CPYRGHT_LENGTH

EQU $-CPYRGHT-1 ;Calculate length of copyright message

Page 46: What is an Assembler2

2.12. Numbers and Operators

The Cross Assembler accepts numbers in any one of four radices:

binary, octal, decimal and hexadecimal. To specify a number in a

specific radix, the number must use the correct digits for the

particular radix and immediately following the number with its

radix designator. Decimal is the default radix and the use of

its designator is optional. An hexadecimal number that would

begin with a letter digit must be preceded by a 0 (zero) to

distinguish it from a symbol. The internal representation of

numbers is 16-bits, which limits the maximum number possible.

Table 2-4 summarizes the radices available.

MAXIMUM LEGAL

RADIX DESIGNATOR LEGAL DIGITS NUMBER

----------- ---------- ------------ -----------------

Binary B 0,1 1111111111111111B

Octal O,Q 0,1,2,3,4,5, 177777O

6,7 177777Q

Decimal D,(default) 0,1,2,3,4,5, 65535D

6,7,8,9 65535

Hexadecimal H 0,1,2,3,4,5, 0FFFFH

6,7,8,9,A,B,

C,D,E,F

Table 2-4: Cross Assembler Radices

No spaces or tabs are allowed between the number and the radix

designator. The letter digits and radix designators can be in

Page 47: What is an Assembler2

upper or lower case. The following examples list the decimal

number 2957 in each of the available radices:

101110001101B (Binary)

5615o or 5615Q (Octal)

2957 or 2957D (Decimal)

0B8DH, 0b8dh (Hexadecimal)

When using radices with explicit bit symbols, the radix

designator follows the byte portion of the address as shown in

the following examples:

0E0H.7 Bit seven of hexadecimal address 0E0

200Q.ON Bit ON of octal address 200

The Cross Assembler also allows assembly time evaluation of

arithmetic expressions up to thirty-two levels of embedded

parentheses. All calculations use integer numbers and are done

in sixteen bit precision.

OPERATOR SYMBOL OPERATION

--------------- ------------------------

+ Addition

Unary positive

- Subtraction

Unary negation (2's complement)

* Multiplication

/ Integer division (no remainder)

MOD Modulus (remainder of integer division)

SHR Shift right

Page 48: What is an Assembler2

SHL Shift left

NOT Logical negation (1's complement)

AND Logical and

OR Inclusive or

XOR Exclusive or

LOW Low order 8-bits

HIGH High order 8-bits

EQ, = Relational equal

NE, <> Relational not equal

GT, > Relational greater than

GE, >= Relational greater than or equal

LT, < Relational less than

LE, <= Relational less than or equal

( ) Parenthetical statement

Table 2-5: Assembly Time Operations

The relational operators test the specified values and return

either a True or False. False is represented by a zero value,

True is represented by a non zero value (the True condition

actually returns a 16-bit value with every bit set; i.e.,

0FFFFH). The relational operators are used primarily with the

Conditional Assembly capability of the Cross Assembler.

Table 2-5 lists the operations available while Table 2-6 lists

the operations precedence in descending order. Operations with

higher precedence are done first. Operations with equal

precedence are evaluated from left to right.

Page 49: What is an Assembler2

OPERATION PRECEDENCE

--------- ----------

(,) HIGHEST

HIGH,LOW

*,/,MOD,SHR,SHL

+,-

EQ,LT,GT,LE,GE,NE,=,<,>,<=,>=,<>

NOT

AND

OR,XOR LOWEST

Table 2-6: Operators Precedence

The following are examples of all the available operations and

their result:

HIGH(0AADDH) will return a result of 0AAH

LOW(0AADDH) will return a result of 0DDH

7*4 will return a result of 28

7/4 will return a result of 1

7 MOD 4 will return a result of 3

1000B SHR 2 will return a result of 0010B

1010B SHL 2 will return a result of 101000B

10+5 will return a result of 15

+72 will return a result of 72

25-17 will return a result of 8

-1 will return a result of 1111111111111111B

NOT 1 will return a result of 1111111111111110B

Page 50: What is an Assembler2

7 EQ 4, 7 = 4 will return a result of 0

7 LT 4, 7 < 4 will return a result of 0

7 GT 4, 7 > 4 will return a result of 0FFFFH

7 LE 4, 7 <= 4 will return a result of 0

7 GE 4, 7 >= 4 will return a result of 0FFFFH

7 NE 4, 7 <> 4 will return a result of 0FFFFH

1101B AND 0101B will return a result of 0101B

1101B OR 0101B will return a result of 1101B

1101B XOR 0101B will return a result of 1000B


Recommended