Professional Documents
Culture Documents
#d antages of coding in assem"l! language are: Pro ides more control o er handling particular hardware components *a! generate smaller, more compact e)ecuta"le modules +ften results in faster e)ecution ,isad antages: Not porta"le *ore comple) -e$uires understanding of hardware details (interfaces)
Assem%&er' #n assem"ler does the following: .. /enerate machine instructions - e aluate the mnemonics to produce their machine code - e aluate the s!m"ols, literals, addresses to produce their e$ui alent machine addresses - con ert the data constants into their machine representations 2. Process pseudo operations
2! ()o Pass Assem%&er # two0pass assem"ler performs two se$uential scans o er the source code: Pass 1: s!m"ols and literals are defined Pass 2: o"%ect program is generated Parsing: mo ing in program lines to pull out op0codes and operands
Data Stru#tures'
Location counter (LC): points to the ne)t location where the code will "e placed Op-co e translation table: contains s!m"olic instructions, their lengths and their op0codes (or su"routine to use for translation) !ymbol table (!"): contains la"els and their alues !tring storage bu##er (!!$): contains #1C22 characters for the strings Con#iguration table: contains pointer to the string in 113 and offset where its alue will "e inserted in the o"%ect code
Pass. 1!m"ol ta"le Configuration ta"le 1tring storage "uffer Partiall! configured o"%ect file
Pass 2
place in Pass 1
-183 +p,#ode (a%&e Mnemonic L,# 183 C+*P L,( #,, T2( ?LT ?/T Addressing mode immediate immediate immediate immediate inde)ed direct direct direct Opcode 6. ., 2< 64 .> 2C 9> 9: Sym%o& (a%&e Symbol L++P
implied
:C
Value 6.69
C+8NT: A+-, ; 'N, Sym%o& (a%&e Symbol L++P L21T C+8NT Address 6.6; 6..2 6..4
Configuration (a%&e Offset 666= 666# SSB pointer for the symbol ,C66 ,C64 SSB :C7 :<7 497 4:7 4'7
,C64
Pass #ll s!m"ols are identified and put in 1T #ll op0codes are translated *issing s!m"ol alues are mar&ed
LC B origin -ead ne)t statement Parse the statement C Comment N D'N,E N N N La"el C N 'nter la"el in 1T 'nter la"el in 1T C 'nter la"el in 1T Call translator Place constant in machine code #d ance LC #d ance LC "! the num"er of "!tes specified in the pseudo0op C 'nter la"el in 1T La"el N La"el 'G8 A+-,H 3CT' -'1AH-'13 pseudo0op C what &indF C Pass 2
(rans&ator Routine
@ind opcode and the num"er of "!tes in +p0code Ta"le Arite opcode in machine code
Arite the data or address that is &nown at this time in machine code more information will "e needed in Pass 2 F N
$igure -& %lowchart o# a translator routine Pass 2 0 @ills addresses and data that was un&nown during Pass ..
Pass . *ore lines in Configuration Ta"le C /et the ne)t line -etrie e the name of the s!m"ol from 113 /et the alue of the s!m"ol from 1T Compute the location in memor! where this alue will "e placed (starting address I offset) Place the s!m"ol alue at this location N ,one
$igure .& !econ pass o# a two-pass assembler& Re&o#ata%&e Code Producing an o"%ect code, which can "e placed to an! specific area in memor!. 'irect A ress "able ('A"): contains offset locations of all direct addresses in the program (e.g., >6>6 instructions that specif! direct addresses are L,#, 1T#, all conditional %umps...). To relocate the program, the loader adds the loading point to all these locations. assem"l! language program machine language program and ,#T $igure /! Assembler output #or a relocatable co e& #ssem"ler
E*amp&e 3' @ollowing relocata"le o"%ect code and ,#T are generated for ')ample ..
assem"l! language program 00000000000000000000000 1T#-T L,# #6 L,( L++P: #,, T2( ?LT -183 L21T: A+-, 266 #6 L21T, ( C+8NT L++P memor! address 6666 666. 6662 6669 666: 6664 666; 666= 666> 666< 666# 6663 666C 666, 666' 666@ 66.6 66.. 66.2 66.9 66.: 66.4 66.; 66.= o"%ect code in memor! 6. 66 66 64 66 66 .> 66 .2 2C 66 .4 9> 66 6; :C 66 66 66 62 66 66 66 6;
DA( 666= 666# 666, @orward and "ac&ward references in the machine code are generated relati e to address 6666. To relocate the code, the loader adds the new load0point to the references in the machine code which are pointed "! the ,#T.
=
+ne,Pass Assem%&ers Two methods can "e used: 0 (liminating #orwar re#erences 'ither all la"els used in forward references are defined in the source program "efore the! are referenced, or forward references to data items are prohi"ited. - )enerating the ob*ect co e in memory No o"%ect program is written out and no loader is needed. The program needs to "e re0assem"led e er! time. Mu&ti,Pass Assem%&ers *a&e as man! passes as needed to process the definitions of s!m"ols. E*amp&e 3' # 3 C 'G8 3 'G8 C ,1 . 9 passes are re$uired to find the address for #.
1uch references can also "e sol ed in two passes: entering s!m"ol definitions that in ol e forward references in the s!m"ol ta"le. 1!m"ol ta"le also indicates which s!m"ols are dependent on the alues of others. E*amp&e -' # 3 C , 'G8 'G8 'G8 ,1 3 , , .
266
<