Está en la página 1de 12

17-May-12

Chapter 7 Assembly Language Programming

Chap 7 Assembly Language Programming
• Assembler
– Change mnemonic code into machine code – Label can be used to represent symbolic address/data – Directives : like pre-processing operator (#) in C language.

• Linkage Editor
– Link objective code into executable file (*.obj → *.exe)

1

Computing address/symbol PASS 2 – Convert mnemonic code into machine code 2 .17-May-12 FIGURE 7–1 Assembling a source program Assembler FIGURE 7–2 Pseudo code sketch of a two-pass operator PASS 1 – Establish symbol table .

17-May-12 FIGURE 7–3 Use of the generic JMP mnemonic Symbol Table : Symbol →Address/Data • Assembly program – Machine instructions MOV A. to EOL ……. this is a comment 3 . . #0 – Assembler Directives • Like Variable declaration in high-level language – Assembler controls • Conditional compiling – Comments After .

#define symbol .* / MOD – Logic : AND OR NOT XOR – Relational : EQ NE LT LE GT GE = <> < <= > >= – Special : SHR SHL HIGH LOW () 4 . comment Example : PAR … EQU JNB 500 TI. HERE • Constant expression – Implement by assembler Examples: MOV A.17-May-12 • Formant of Assembly language – case insensitive [label:] mnemonic [operation] [. HERE: JNB TI. ‘ ‘ means char constant • Operators in constant expressions – Arithmetic : + . .. ‘9’-’0’ . $ .operand].

END 5 . now AR7 means $23H ….17-May-12 • Precedence of constant () HIGH LOW / MOD SHR SHL +EQ NE LT LE GT GE = NOT AND OR XOR <> < <= > >= • Directives (1) Assembler state control • ORG – define the location of the code • END – directive to tell assembler the end of source file • USING – set the register bank Examples : ORG 100H ORG $+100H USING 3 PUSH AR7 .

00-7fH) • IDATA (indirect address space. the programmer need to manage the location of program/data in memory symbol …. the following program was form a segment . 00-7FH 80-FFH for 8052) • BIT (bit address space) • CSEG AT (equivalent to SEGMENT CODE) • DSEG AT • XSEG AT • ISEG AT • BSEG AT 6 .. The content is segment_type (code or data) segment_type can be one of • CODE (program) • XDATA (the extended data segment) • DATA (direct address space. SEGMENT segment_type . called symbol. .17-May-12 (2) Symbol define – – – – – Segment EQU Storage initialization/reservation Program link Segment selection (A) Segment define In low-level language.

low-byte in lower address) Example 1: DSEG AT 30H EQU 40 DS LENGTH SEGMENT MOV MOV MOV BJNZ END CODE LENGTH: BUFFER: PROG … LOOP: …. #0 R7. R7. $(current location) (C) Storage initialization/reservation – – – – DS DBIT DB DW (define space.17-May-12 (B) EQU like the named constant define in C (#define) Example: BASE EQU other constants : 10 #10H. #LENGTH R0. like unintialized array) (define bit data) (define byte data) (define word data. LOOP 7 . #BUFFER @R0.

A DTPR A. DPL A.LOOP A. #LOW(XBUFFER+XLENGTH+1). DPH A. #XLENGTH A @DPTR. FIGURE 7–4 Use of the EXTRN and PUBLIC assembler directives (3) Program link Multi-file : EXTERN. PUBLIC directive 8 .17-May-12 Example 2: XSEG AT 4000H EQU 1000 DS XLENGTH SEGMENT MOV CLR MOVX INC MOV CJNE MOV CJNE END CODE XLENGTH: XBUFFER: PROG … LOOP: DPTR.LOOP …. #HIGH(XBUFFER+XLENGTH+1).

17-May-12 FIGURE 7–5 Defining and initiating absolute and relocatable segments RSEG directive – reallocatable segment FIGURE 7–6 Assembler controls supported by ASM51 9 .

17-May-12 FIGURE 7–6 (continued) Assembler controls supported by ASM51 FIGURE 7–7 Linker operation 10 .

(a) ECHO. (b) IO.17-May-12 FIGURE 7–8a Annotated example: linking relocatable segments and modules. (c) EXAMPLE. Address-relative content Need to fix in linkage . Symbol Table 11 .M51.LST.LST.reallocatable FIGURE 7–8a Annotated example: linking relocatable segments and modules.LST. (a) ECHO.LST.M51. (b) IO. (c) EXAMPLE.

Annotated example: linking relocatable segments and modules.LST.M51. (b) IO.17-May-12 FIGURE 7–8d (continued) (c) EXAMPLE. Output of linkage editor -Symbol table -Reallocatable address were computed already 12 . (a) ECHO.LST.