System Software

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 61

RAJALAKSHMI ENGINEERING COLLEGE

Thandalam, Chennai 602 105

CS 2304 - SYSTEM SOFTWARE NOTES ON LESSON UNIT 1 Introduction


Sy tem So!t"are # $achine %rchitecture The Sim&li!ied In tructional Com&uter SIC and SIC'(E Traditional )CISC* $achine + Com&le, In truction Set Com&uter -ISC $achine + -educed In truction Set Com&uter

1.0 Introduction
The u/0ect introduce the de i1n and im&lementation o! y tem o!t"are. So!t"are i et o! in truction or &ro1ram "ritten to carry out certain ta 2 on di1ital com&uter . It i cla i!ied into y tem o!t"are and a&&lication o!t"are. Sy tem o!t"are con i t o! a 3ariety o! &ro1ram that u&&ort the o&eration o! a com&uter. %&&lication o!t"are !ocu e on an a&&lication or &ro/lem to /e ol3ed. Sy tem o!t"are con i t o! a 3ariety o! &ro1ram that u&&ort the o&eration o! a com&uter. E,am&le !or y tem o!t"are are O&eratin1 y tem, com&iler, a em/ler, macro &roce or, loader or lin2er, de/u11er, te,t editor, data/a e mana1ement y tem ) ome o! them* and, o!t"are en1ineerin1 tool . The e o!t"are4 ma2e it &o i/le !or the u er to !ocu on an a&&lication or other &ro/lem to /e ol3ed, "ithout needin1 to 2no" the detail o! ho" the machine "or2 internally.

1.1 Sy tem So!t"are and $achine %rchitecture


One characteri tic in "hich mo t o!t"are i machine de&endency. y tem o!t"are di!!er !rom a&&lication

Sy tem o!t"are u&&ort o&eration and u e o! com&uter. %&&lication o!t"are + olution to a &ro/lem. % em/ler tran late mnemonic in truction into machine code. The in truction !ormat , addre in1 mode etc., are o! direct concern in a em/ler de i1n. Similarly, Com&iler mu t 1enerate machine lan1ua1e code, ta2in1 into account uch hard"are characteri tic a the num/er and ty&e o! re1i ter and the machine in truction a3aila/le. O&eratin1 y tem are directly concerned "ith the mana1ement o! nearly all o! the re ource o! a com&utin1 y tem.

There are a &ect o! y tem o!t"are that do not directly de&end u&on the ty&e o! com&utin1 y tem, 1eneral de i1n and lo1ic o! an a em/ler, 1eneral de i1n and lo1ic o! a com&iler and, code o&timi5ation techni6ue , "hich are inde&endent o! tar1et machine . Li2e"i e, the &roce o! lin2in1 to1ether inde&endently a em/led u/&ro1ram doe not u ually de&end on the com&uter /ein1 u ed.

1.2 The Sim&li!ied In tructional Com&uter )SIC*


Sim&li!ied In tructional Com&uter )SIC* i a hy&othetical com&uter that include the hard"are !eature mo t o!ten !ound on real machine . There are t"o 3er ion o! SIC, they are, tandard model )SIC*, and, e,ten ion 3er ion )SIC'(E* )e,tra e6ui&ment or e,tra e,&en i3e*.

1.2.1 SIC $achine %rchitecture


7e di cu here the SIC machine architecture "ith re &ect to it $emory and -e1i ter , 8ata 9ormat , In truction 9ormat , %ddre in1 $ode , In truction Set, In&ut and Out&ut

$emory
There are 215 /yte in the com&uter memory, that i :2,;6< /yte , It u e Little Endian !ormat to tore the num/er , : con ecuti3e /yte !orm a "ord , each location in memory contain <+/it /yte .

-e1i ter
There are !i3e re1i ter , each 2= /it in len1th. Their mnemonic, num/er and u e are 1i3en in the !ollo"in1 ta/le.

$nemonic % ( L BC S7

Num/er 0 1 2 < C

>e %ccumulator? u ed !or arithmetic o&eration Inde, re1i ter? u ed !or addre in1 Lin2a1e re1i ter? @S>A Bro1ram counter Statu "ord, includin1 CC

8ata 9ormat
Inte1er are tored a 2=+/it /inary num/er , 24 com&lement re&re entation i u ed !or ne1ati3e 3alue , character are tored u in1 their <+/it %SCII code , No !loatin1+ &oint hard"are on the tandard 3er ion o! SIC.

In truction 9ormat
O&code)<* , %ddre )15*

%ll machine in truction on the tandard 3er ion o! SIC ha3e the 2=+/it !ormat a ho"n a/o3e

%ddre in1 $ode

Mode 8irect Inde,ed

Ind !"# on ,D0 ,D1

T"$%e# "dd$e&& !"'!('"# on T% D addre T% D addre E ),*

There are t"o addre in1 mode a3aila/le, "hich are a ho"n in the a/o3e ta/le. Barenthe e are u ed to indicate the content o! a re1i ter or a memory location.

In truction Set
SIC &ro3ide , load and tore in truction )L8%, L8(, ST%, ST(, etc.* . Inte1er arithmetic o&eration F )%88, S>A, $>L, 8IG, etc.*. %ll arithmetic o&eration in3ol3e re1i ter % and a "ord in memory, "ith the re ult /ein1 le!t in the re1i ter. T"o in truction are &ro3ided !or u/routine lin2a1e. CO$B com&are the 3alue in re1i ter % "ith a "ord in memory, thi in truction et a condition code CC to indicate the re ult. There are conditional 0um& in truction F )@LT, @EH, @IT*, the e in truction te t the ettin1 o! CC and 0um& accordin1ly. @S>A 0um& to the u/routine &lacin1 the return addre in re1i ter L, -S>A return /y 0um&in1 to the addre contained in re1i ter L.

In&ut and Out&ut

In&ut and Out&ut are &er!ormed /y tran !errin1 1 /yte at a time to or !rom the ri1htmo t < /it o! re1i ter % )accumulator* . The Te t 8e3ice )T8* in truction te t "hether the addre ed de3ice i ready to end or recei3e a /yte o! data . -ead 8ata )-8*, 7rite 8ata )78* are u ed !or readin1 or "ritin1 the data.

8ata mo3ement and Stora1e 8e!inition


L8%, ST%, L8L, STL, L8(, ST( ) %+ %ccumulator, L Lin2a1e -e1i ter, ( Inde, -e1i ter*) all u e :+/yte "ord. L8CJ, STCJ a ociated "ith character u e 1+/yte. There are no memory+memory mo3e in truction . Stora1e de!inition are 7O-8 + -ES7 + AKTE + -ESA + ONE+7O-8 CONST%NT ONE+7O-8 G%-I%ALE ONE+AKTE CONST%NT ONE+AKTE G%-I%ALE

E,am&le Bro1ram )SIC*


E*"+,'e 1-S +,'e d"#" "nd !."$"!#e$ +o/e+en# o,e$"# on0 L8% 9IGE ST% %LBJ% L8CJ CJ%-L STCJ C1 . %LBJ% 9IGE CJ%-L C1 -ES7 1 7O-8 5 AKTE C4L4 -ESA 1

E*"+,'e 2- A$ #.+e# ! o,e$"# on&0 L8% %LBJ% %88 INCS>A ONE ST% AEET% MM.. MM.. MM.. MM.. 7O-8 1 -ES7 1 =

ONE %LBJ%

AEET% INC-

-ES7 1 -ES7 1

E*"+,'e 3-Loo, n% "nd Inde* n% o,e$"# on0 L8( LE-O F (D0 $OGECJ L8CJ ST-1, ( F LO%8 % 9-O$ ST-1 STCJ ST-2, ( F STO-E % TO ST-2 TI( ELEGEN F %88 1 TO (, TEST @LT $OGECJ . . . ST-1 AKTE C NJELLO 7O-L84 ST-2 -ESA 11 LE-O 7O-8 0 ELEGEN 7O-8 11 E*"+,'e 4- In,(# "nd O(#,(# o,e$"# on0 INLOOB T8 IN8EG @EH INLOOB -8 IN8EG STCJ 8%T% . . O>TLB T8 O>T8EG @EH O>TLB L8CJ 8%T% 78 O>T8EG . . IN8EG AKTE ( N954 O>T8EG AKTE ( N0<4 8%T% -ESA 1 F TEST INB>T 8EGICE F LOOB >NTIL 8EGICE IS -E%8K F -E%8 ONE AKTE INTO % F STO-E % TO 8%T% F TEST O>TB>T 8EGICE F LOOB >NTIL 8EGICE IS -E%8K F LO%8 8%T% INTO % F 7-ITE % TO O>TB>T 8EGICE F INB>T 8EGICE N>$AEF O>TB>T 8EGICE N>$AEF ONE+AKTE G%-I%ALE

E*"+,'e 1 -To #$"n&2e$ #3o .(nd$ed 45#e& o2 d"#" 2$o+ n,(# de/ !e #o +e+o$50 L8( LE-O CLOOB T8 @EH -8 IN8EG CLOOB IN8EG

STCJ -ECO-8, ( TI( A200 @LT CLOOB . . IN8EG AKTE ( N954 -ECO-8 -ESA 200 LE-O 7O-8 0 A200 7O-8 200 E*"+,'e 6 -S(4$o(# ne #o #$"n&2e$ #3o .(nd$ed 45#e& o2 d"#" 2$o+ n,(# de/ !e #o +e+o$50 @S>A -E%8 MMMM. MMMM. -E%8 L8( LE-O CLOOB T8 IN8EG @EH CLOOB -8 IN8EG STCJ -ECO-8, ( TI( A200 F add 1 to inde, com&are 200 )A200* @LT CLOOB -S>A MM.. MM.. IN8EG AKTE ( N954 -ECO-8 -ESA 200 LE-O 7O-8 0 A200 7O-8 200

1.2.2 SIC'(E $achine %rchitecture $emory


$a,imum memory a3aila/le on a SIC'(E y tem i 1 $e1a/yte )220 /yte *

-e1i ter
%dditional A, S, T, and 9 re1i ter are &ro3ided /y SIC'(E, in addition to the re1i ter o! SIC $nemonic Num/er S&ecial u e

A S T 9

: = 5 6

Aa e re1i ter Ieneral "or2in1 re1i ter Ieneral "or2in1 re1i ter 9loatin1+&oint accumulator )=< /it *

9loatin1+&oint data ty&e


There i a =<+/it !loatin1+&oint data ty&e, 9O2)e+102=* 1 11 :6 S e,&onent !raction

In truction 9ormat
The ne" et o! in truction !ormat !ro SIC'(E machine architecture are a !ollo" . 9ormat 1 )1 /yte*F contain only o&eration code ) trai1ht !rom ta/le*. 9ormat 2 )2 /yte *F !ir t ei1ht /it !or o&eration code, ne,t !our !or re1i ter 1 and !ollo"in1 !our !or re1i ter 2. The num/er !or the re1i ter 1o accordin1 to the num/er indicated at the re1i ter ection )ie, re1i ter T i re&laced /y he, 5, 9 i re&laced /y he, 6*. 9ormat : ): /yte *F 9ir t 6 /it contain o&eration code, ne,t 6 /it contain !la1 , la t 12 /it contain di &lacement !or the addre o! the o&erand. O&eration code u e only 6 /it , thu the econd he, di1it "ill /e a!!ected /y the 3alue o! the !ir t t"o !la1 )n and i*. The !la1 , in order, areF n, i, ,, /, &, and e. It !unctionality i e,&lained in the ne,t ection. The la t !la1 e indicate the in truction !ormat )0 !or : and 1 !or =*. 9ormat = )= /yte *F ame a !ormat : "ith an e,tra 2 he, di1it )< /it * !or addre e that re6uire more than 12 /it to /e re&re ented. Fo$+"# 1 -1 45#e0 7 O, Fo$+"# 2 -2 45#e&0 7 o, 4 $1 4 $2

9ormat 1 and 2 are in truction do not re!erence memory at all Fo$+"# 3 -3 45#e&0 6 o, 1 1 1 1 1 1 12 N * 4 , e d &,

Fo$+"# 4 -4 45#e&0 6 o, 1 1 1 1 1 1 20 n * 4 , e "dd$e&&

%ddre in1 mode # 9la1 Ait


9i3e &o i/le addre in1 mode &lu the com/ination are a !ollo" . 8 $e!# ),, /, and & all et to 0*F o&erand addre 1oe a it i . n and i are /oth et to the ame 3alue, either 0 or 1. 7hile in 1eneral that 3alue i 1, i! et to 0 !or !ormat : "e can a ume that the re t o! the !la1 ),, /, &, and e* are u ed a a &art o! the addre o! the o&erand, to ma2e the !ormat com&ati/le to the SIC !ormat Re'"# /e )either / or & e6ual to 1 and the other one to 0*F the addre o! the o&erand hould /e added to the current 3alue tored at the A re1i ter )i! / D 1* or to the 3alue tored at the BC re1i ter )i! & D 1* I++ed "#e )i D 1, n D 0*F The o&erand 3alue i already enclo ed on the in truction )ie. lie on the la t 12'20 /it o! the in truction* addre Ind $e!# )i D 0, n D 1*F The o&erand 3alue &oint to an addre !or the o&erand 3alue. that hold the

Inde*ed ), D 1*F 3alue to /e added to the 3alue tored at the re1i ter , to o/tain real addre o! the o&erand. Thi can /e com/ined "ith any o! the &re3iou mode e,ce&t immediate. The 3ariou !la1 /it u ed in the a/o3e !ormat ha3e the !ollo"in1 meanin1 e + e D 0 mean !ormat :, e D 1 mean !ormat =

<

Ait ,,/,&F > ed to calculate the tar1et addre addre in1 $ode Ait i and nF Say , ho" to u e the tar1et addre

u in1 relati3e, direct, and inde,ed

/ and & + /oth et to 0, di & !ield !rom !ormat : in truction i ta2en to /e the tar1et addre . 9or a !ormat = /it / and & are normally et to 0, 20 /it addre i the tar1et addre , + , i et to 1, ( re1i ter 3alue i added !or tar1et addre calculation iD1, nD0 Immediate addre in1, TAF T% i u ed a the o&erand 3alue, no memory re!erence iD0, nD1 Indirect addre in1, --TA00F The "ord at the T% i !etched. Galue o! T% i ta2en a the addre o! the o&erand 3alue iD0, nD0 or iD1, nD1 Sim&le addre in1, -TA0FT% i ta2en a the addre o! the o&erand 3alue T"o ne" relati3e addre in1 mode are a3aila/le !or u e "ith in truction a em/led u in1 !ormat :. Mode Aa e relati3e Bro1ram+counter relati3e Ind !"# on /D1,&D0 /D0,&D1 T"$%e# "dd$e&& !"'!('"# on T%D)A*E di & )0di & =0C5* T%D)BC*E di & )+20=<di & 20=;*

In truction Set
SIC'(E &ro3ide all o! the in truction that are a3aila/le on the tandard 3er ion. In addition "e ha3e, In truction to load and tore the ne" re1i ter L8A, STA, etc, 9loatin1+&oint arithmetic o&eration , %889, S>A9, $>L9, 8IG9, -e1i ter mo3e in truction F -$O, -e1i ter+to+re1i ter arithmetic o&eration , %88-, S>A-, $>L-, 8IG- and, Su&er3i or call in truction F SGC.

In&ut and Out&ut


There are I'O channel that can /e u ed to &er!orm in&ut and out&ut "hile the CB> i e,ecutin1 other in truction . %llo" o3erla& o! com&utin1 and I'O, re ultin1 in more e!!icient y tem o&eration. The in truction SIO, TIO, and JIO are u ed to tart, te t and halt the o&eration o! I'O channel .

E,am&le Bro1ram )SIC'(E*

E*"+,'e 1 -S +,'e d"#" "nd !."$"!#e$ +o/e+en# o,e$"# on0 L8% P5 ST% %LBJ% L8% PC0 STCJ C1 . . %LBJ% -ES7 1 C1 -ESA 1 E*"+,'e 2-A$ #.+e# ! o,e$"# on&0 L8S INCL8% %LBJ% %88 S,% S>A P1 ST% AEET% MMMM. MMMM.. %LBJ% -ES7 1 AEET% -ES7 1 INC- -ES7 1 E*"+,'e 3-Loo, n% "nd Inde* n% o,e$"# on0 L8T P11 L8( P0 F (D0 L8CJ ST-1, ( F LO%8 % 9-O$ ST-1 STCJ ST-2, ( F STO-E % TO ST-2 TI(T F %88 1 TO (, TEST )T* @LT $OGECJ MMM. MMM. MMM AKTE C NJELLO 7O-L84 -ESA 11

$OGECJ

ST-1 ST-2

E*"+,'e 4 -To #$"n&2e$ #3o .(nd$ed 45#e& o2 d"#" 2$o+ n,(# de/ !e #o +e+o$50 L8T L8( T8 @EH -8 STCJ TI(P200 P0 IN8EG CLOOB IN8EG -ECO-8, ( T

CLOOB

10

@LT CLOOB . . IN8EG AKTE ( N954 -ECO-8 -ESA 200

E*"+,'e 1 -S(4$o(# ne #o #$"n&2e$ #3o .(nd$ed 45#e& o2 d"#" 2$o+ n,(# de/ !e #o +e+o$50 @S>A -E%8 MMM. MMM. -E%8 L8T P200 L8( P0 CLOOB T8 IN8EG @EH CLOOB -8 IN8EG STCJ -ECO-8, ( TI(- T F add 1 to inde, com&are T @LT CLOOB -S>A MM.. MM.. IN8EG AKTE ( N954 -ECO-8 -ESA 200

1.: 8i!!erent %rchitecture


The !ollo"in1 ection introduce the architecture o! CISC and -ISC machine . CISC machine are called traditional machine . In addition to the e "e ha3e recent -ISC machine . 8i!!erent machine /elon1in1 to /oth o! the e architecture are com&ared "ith re &ect to their $emory, -e1i ter , 8ata 9ormat , In truction 9ormat , %ddre in1 $ode , In truction Set, In&ut and Out&ut

1.:.1 CISC machine


Traditional )CISC* $achine , are nothin1 /ut, Com&le, In truction Set Com&uter , ha relati3ely lar1e and com&le, in truction et, di!!erent in truction !ormat , di!!erent len1th , di!!erent addre in1 mode , and im&lementation o! hard"are !or the e com&uter i com&le,. G%( and Intel ,<6 &roce or are e,am&le !or thi ty&e o! architecture.

1.:.1.1 G%( %rchitecture

11

Me+o$5 + The G%( memory con i t o! <+/it /yte . %ll addre e u ed are /yte addre e . T"o con ecuti3e /yte !orm a "ord, 9our /yte !orm a lon1"ord, ei1ht /yte !orm a 6uad"ord, i,teen /yte !orm a octa"ord. %ll G%( &ro1ram o&erate in a 3irtual addre &ace o! 2:2 /yte , One hal! i called y tem &ace, other hal! &roce &ace. Re% &#e$& There are 16 1eneral &ur&o e re1i ter )IB- * , :2 /it each, named a -0 to -15, BC )-15*, SB )-1=*, 9rame Bointer 9B ) -1:*, %r1ument Bointer %B )-12* ,Other a3aila/le !or 1eneral u e. There i a Broce tatu lon1"ord )BSL* !or !la1 . 8"#" Fo$+"#& + Inte1er are tored a /inary num/er in /yte, "ord, lon1"ord, 6uad"ord, octa"ord. 24 com&lement notation i u ed !or torin1 ne1ati3e num/er . Character are tored a <+/it %SCII code . 9our di!!erent !loatin1+&oint data !ormat are al o a3aila/le. In&#$(!# on Fo$+"#& + G%( architecture u e 3aria/le+len1th in truction !ormat o& code 1 or 2 /yte , ma,imum o! 6 o&erand &eci!ier de&endin1 on ty&e o! in truction. Ta/a2 %d3anced $icro&roce or )2nd edition* $cIra"+Jill, 1CC5, 1i3e more in!ormation. Add$e&& n% Mode& + G%( &ro3ide a lar1e num/er o! addre in1 mode . They are -e1i ter mode, re1i ter de!erred mode, autoincrement, autodecrement, /a e relati3e, &ro1ram+counter relati3e, inde,ed, indirect, and immediate. In&#$(!# on Se# In truction are ymmetric "ith re &ect to data ty&e + > e &re!i, ty&e o! o&eration, u!!i, ty&e o! o&erand , a modi!ier num/er o! o&erand . 9or e,am&le, %8872 + add, "ord len1th, 2 o&erand , $>LL: + multi&ly, lon1"ord , : o&erand CGTCL + con3er ion !rom "ord to lon1"ord. G%( al o &ro3ide in truction to load and tore multi&le re1i ter . In,(# "nd O(#,(# + > e I'O de3ice controller . 8e3ice control re1i ter are ma&&ed to e&arate I'O &ace. So!t"are routine and memory mana1ement routine are u ed !or in&ut'out&ut o&eration .

1.:.1.2 Bentium Bro %rchitecture


Introduced /y Intel in 1CC5. Me+o$5 + con i t o! <+/it /yte , all addre e u ed are /yte addre e . T"o con ecuti3e /yte !orm a "ord, !our /yte !orm a dou/le "ord )d"ord*. Gie"ed a collection o! e1ment , and, addre D e1ment num/er E o!! et. There are code, data, tac2 , e,tra e1ment . Re% &#e$& There are :2+/it, ei1ht IB- , namely E%(, EA(, EC(, E8(, ESI, E8I, EAB, ESB. E%(, EA(, EC(, E8( are u ed !or data mani&ulation, other !our are u ed to hold addre e . EIB :2+/it contain &ointer to ne,t in truction to /e e,ecuted. 9L%IS i an :2 + /it !la1 re1i ter. CS, SS, 8S, ES, 9S, IS are the i, 16+/it e1ment re1i ter .

12

8"#" Fo$+"#& + Inte1er are tored a <, 16, or :2 /it /inary num/er , 24 com&lement !or ne1ati3e num/er , AC8 i al o u ed in the !orm o! un&ac2ed AC8, &ac2ed AC8. There are three !loatin1 &oint data !ormat , they are in1le, dou/le, and e,tended+ &reci ion. Character are tored a one &er /yte %SCII code . In&#$(!# on Fo$+"#& In truction u e &re!i,e to &eci!y re&etition count, e1ment re1i ter, !ollo"in1 &re!i, )i! &re ent*, an o&code ) 1 or 2 /yte *, then num/er o! /yte to &eci!y o&erand , addre in1 mode . In truction !ormat 3arie in len1th !rom 1 /yte to 10 /yte or more. O&code i al"ay &re ent in e3ery in truction Add$e&& n% Mode& + % lar1e num/er o! addre in1 mode are a3aila/le. They are immediate mode, re1i ter mode, direct mode, and relati3e mode. > e o! /a e re1i ter, inde, re1i ter "ith di &lacement i al o &o i/le. In&#$(!# on Se# Thi architecture ha a lar1e and com&le, in truction et, a&&ro,imately =00 di!!erent machine in truction . Each in truction may ha3e one, t"o or three o&erand . 9or e,am&le -e1i ter+to+re1i ter, re1i ter+to+memory, memory+to+ memory, trin1 mani&ulation, etcMare the ome the in truction . In,(# "nd O(#,(# + In&ut i !rom an I'O &ort into re1i ter E%(. Out&ut i !rom E%( to an I'O &ort

1.:.2 -ISC $achine


-ISC mean -educed In truction Set Com&uter . The e machine are intended to im&li!y the de i1n o! &roce or . They ha3e Ireater relia/ility, !a ter e,ecution and le e,&en i3e &roce or . %nd al o they ha3e tandard and !i,ed in truction len1th. Num/er o! machine in truction , in truction !ormat , and addre in1 mode relati3ely mall. >ltraSB%-C %rchitecture and Cray T:E %rchitecture are e,am&le o! -ISC machine .

1.:.2.1 >ltraSB%-C %rchitecture


Introduced /y Sun $icro y tem . SB%-C Scala/le Broce or %-Chitecture. SB%-C, Su&erSB%-C, >ltraSB%-C are u&"ard com&ati/le machine and hare the ame /a ic tructure. Me+o$5 + Con i t o! <+/it /yte , all addre e u ed are /yte addre e . T"o con ecuti3e /yte !orm a hal!"ord, !our /yte !orm a "ord , ei1ht /yte !orm a dou/le "ord. > e 3irtual addre &ace o! 26= /yte , di3ided into &a1e . Re% &#e$& + $ore than 100 IB- , "ith 6= /it len1th each called -e1i ter !ile. There are 6= dou/le &reci ion !loatin1+&oint re1i ter , in a &ecial !loatin1+&oint unit )9B>*. In addition to the e, it contain BC, condition code re1i ter , and control re1i ter . 8"#" Fo$+"#& + Inte1er are tored a <, 16, :2 or 6= /it /inary num/er . Si1ned, un i1ned !or inte1er and 24 com&lement !or ne1ati3e num/er . Su&&ort /oth /i1+ endian and little+endian /yte orderin1 . 9loatin1+&oint data !ormat in1le, dou/le and 6uad+&reci ion are a3aila/le. Character are tored a <+/it %SCII 3alue.

1:

In&#$(!# on Fo$+"#& + :2+/it lon1, three /a ic in truction !ormat , !ir t t"o /it identi!y the !ormat. 9ormat 1 u ed !or call in truction. 9ormat 2 u ed !or /ranch in truction . 9ormat : u ed !or load, tore and !or arithmetic o&eration . Add$e&& n% Mode& + Thi architecture u&&ort immediate mode, re1i ter+direct mode,BC+relati3e, -e1i ter indirect "ith di &lacement, and -e1i ter indirect inde,ed. In&#$(!# on Se# It ha !e"er than 100 machine in truction . The only in truction that acce memory are load and tore . %ll other in truction are re1i ter+to+re1i ter o&eration . In truction e,ecution i &i&elined thi re ult in !a ter e,ecution, and hence &eed increa e . In,(# "nd O(#,(# + Communication throu1h I'O de3ice i accom&li hed throu1h memory. % ran1e o! memory location i lo1ically re&laced /y de3ice re1i ter . 7hen a load or tore in truction re!er to thi de3ice re1i ter area o! memory, the corre &ondin1 de3ice i acti3ated. There are no &ecial I'O in truction .

1.:.2.2 Cray T:E %rchitecture


%nnounced /y Cray -e earch Inc., at the end o! 1CC5 and i a ma i3ely &arallel &roce in1 )$BB* y tem, contain a lar1e num/er o! &roce in1 element )BE *, arran1ed in a three+dimen ional net"or2. Each BE con i t o! a 8EC %l&ha EG5 -ISC &roce or, and local memory. Me+o$5 - Each BE in T:E ha it o"n local memory "ith a ca&acity o! !rom 6= me1a/yte to 2 1i1a/yte , con i t o! <+/it /yte , all addre e u ed are /yte addre e . T"o con ecuti3e /yte !orm a "ord, !our /yte !orm a lon1"ord, ei1ht /yte !orm a 6uad"ord. Re% &#e$& There are :2 1eneral &ur&o e re1i ter )IB- *, "ith 6= /it len1th each called -0 throu1h -:1, contain 3alue 5ero al"ay . In addition to the e, it ha :2 !loatin1+&oint re1i ter , 6= /it lon1, and 6=+/it BC, tatu , and control re1i ter . 8"#" Fo$+"#& + Inte1er are tored a lon1 and 6uad"ord /inary num/er . 24 com&lement notation !or ne1ati3e num/er . Su&&ort only little+endian /yte orderin1 . T"o di!!erent !loatin1+&oint data !ormat G%( and IEEE tandard. Character tored a <+/it %SCII 3alue. In&#$(!# on Fo$+"#& + :2+/it lon1, !i3e /a ic in truction !ormat . 9ir t i, /it al"ay identi!y the o&code. Add$e&& n% Mode& + Thi architecture u&&ort , immediate mode, re1i ter+direct mode, BC+relati3e, and -e1i ter indirect "ith di &lacement. In&#$(!# on Se# + Ja a&&ro,imately 1:0 machine in truction . There are no /yte or "ord load and tore in truction . Smith and 7ei QBo"erBC 601 and %l&ha 2106=F % Tale o! T7O -ISC Q Ii3e more in!ormation.

1=

In,(# "nd O(#,(# + Communication throu1h I'O de3ice i accom&li hed throu1h multi&le &ort and I'O channel . Channel are inte1rated into the net"or2 that interconnect the &roce in1 element . %ll channel are acce i/le and controlla/le !rom all BE . RRRRRRRRRRRR

UNIT- 2 % em/ler 8e i1n


% em/ler i y tem o!t"are "hich i u ed to con3ert an a em/ly lan1ua1e &ro1ram to it e6ui3alent o/0ect code. The in&ut to the a em/ler i a ource code "ritten in a em/ly lan1ua1e )u in1 mnemonic * and the out&ut i the o/0ect code. The de i1n o! an a em/ler de&end u&on the machine architecture a the lan1ua1e u ed i mnemonic lan1ua1e. 19 :"& ! A&&e+4'e$ F(n!# on&; The /a ic a em/ler !unction areF Tran latin1 mnemonic lan1ua1e code to it e6ui3alent o/0ect code. % i1nin1 machine addre e to ym/olic la/el .

The de i1n o! a em/ler can /e to &er!orm the !ollo"in1F Scannin1 )to2eni5in1* Bar in1 )3alidatin1 the in truction * Creatin1 the ym/ol ta/le -e ol3in1 the !or"ard re!erence Con3ertin1 into the machine lan1ua1e The de i1n o! a em/ler in other "ord F Con3ert mnemonic o&eration code to their machine lan1ua1e e6ui3alent Con3ert ym/olic o&erand to their e6ui3alent machine addre e 8ecide the &ro&er in truction !ormat Con3ert the data con tant to internal machine re&re entation 7rite the o/0ect &ro1ram and the a em/ly li tin1 So !or the de i1n o! the a em/ler "e need to concentrate on the machine architecture o! the SIC'(E machine. 7e need to identi!y the al1orithm and the 3ariou data tructure to /e u ed. %ccordin1 to the a/o3e re6uired te& !or a em/lin1 the a em/ler al o ha 15

to handle assembler directives, the e do not 1enerate the o/0ect code /ut direct the a em/ler to &er!orm certain o&eration. The e directi3e areF SIC % em/ler 8irecti3eF ST%-TF S&eci!y name # tartin1 addre . EN8F End o! the &ro1ram, &eci!y the !ir t e,ecution in truction. AKTE, 7O-8, -ESA, -ES7 End o! recordF a null char)00* End o! !ileF a 5ero len1th record The a em/ler de i1n can /e doneF Sin1le &a a em/ler $ulti+&a a em/ler S n%'e-,"&& A&&e+4'e$; In thi ca e the "hole &roce o! cannin1, &ar in1, and o/0ect code con3er ion i done in in1le &a . The only &ro/lem "ith thi method i re ol3in1 !or"ard re!erence. Thi i ho"n "ith an e,am&le /elo"F 10 ++ ++ ++ ++ C5 1000 9I-ST STL -ET%81=10::

10::

-ET%8-

-ES7

In the a/o3e e,am&le in line num/er 10 the in truction STL "ill tore the lin2a1e re1i ter "ith the content o! -ET%8-. Aut durin1 the &roce in1 o! thi in truction the 3alue o! thi ym/ol i not 2no"n a it i de!ined at the line num/er C5. Since I in1le+ &a a em/ler the cannin1, &ar in1 and o/0ect code con3er ion ha&&en imultaneou ly. The in truction i !etched? it i canned !or to2en , &ar ed !or ynta, and emantic 3alidity. I! it 3alid then it ha to /e con3erted to it e6ui3alent o/0ect code. 9or thi the o/0ect code i 1enerated !or the o&code STL and the 3alue !or the ym/ol -ET%8- need to /e added, "hich i not a3aila/le. 8ue to thi rea on u ually the de i1n i done in t"o &a e . So a multi+&a a em/ler re ol3e the !or"ard re!erence and then con3ert into the o/0ect code. Jence the &roce o! the multi+&a a em/ler can /e a !ollo" F Pass-1 % i1n addre e to all the tatement Sa3e the addre e a i1ned to all la/el to /e u ed in Pass-2 Ber!orm ome &roce in1 o! a em/ler directi3e uch a -ES7, -ESA to !ind the len1th o! data area !or a i1nin1 the addre 3alue . 8e!ine the ym/ol in the ym/ol ta/le)1enerate the ym/ol ta/le* Pass-2 16

% em/le the in truction )tran latin1 o&eration code and loo2in1 u& addre e *. Ienerate data 3alue de!ined /y AKTE, 7O-8 etc. Ber!orm the &roce in1 o! the a em/ler directi3e not done durin1 pass-1. 7rite the o/0ect &ro1ram and a em/ler li tin1.

A&&e+4'e$ 8e& %n; The mo t im&ortant thin1 "hich need to /e concentrated i the 1eneration o! Sym/ol ta/le and re ol3in1 forward references. Sym/ol Ta/leF Thi i created durin1 &a 1 %ll the la/el o! the in truction are ym/ol Ta/le ha entry !or ym/ol name, addre 3alue. 9or"ard re!erenceF Sym/ol that are de!ined in the later &art o! the &ro1ram are called !or"ard re!erencin1. There "ill not /e any addre 3alue !or uch ym/ol in the ym/ol ta/le in &a 1. E*"+,'e <$o%$"+; The e,am&le &ro1ram con idered here ha a main module, t"o u/routine Bur&o e o! e,am&le &ro1ram + -ead record !rom in&ut de3ice )code 91* + Co&ie them to out&ut de3ice )code 05* + %t the end o! the !ile, "rite EO9 on the out&ut de3ice, then -S>A to the o&eratin1 y tem 8ata tran !er )-8, 78* +% /u!!er i u ed to tore record +Au!!erin1 i nece ary !or di!!erent I'O rate +The end o! each record i mar2ed "ith a null character )00*16 +The end o! the !ile i indicated /y a 5ero+len1th record Su/routine )@S>A, -S>A* +-8-EC, 7--EC +Sa3e lin2 re1i ter !ir t /e!ore ne ted 0um&

1;

The !ir t column ho" the line num/er !or that in truction, econd column ho" the addre e allocated to each in truction. The third column indicate the la/el 1i3en to the tatement, and i !ollo"ed /y the in truction con i tin1 o! o&code and o&erand. The la t column 1i3e the e6ui3alent o/0ect code. The object code later "ill /e loaded into memory !or e,ecution. The im&le o/0ect &ro1ram "e u e contain three ty&e o! record F Jeader record + Col. 1 J + Col. 2S; Bro1ram name + Col. <S1: Startin1 addre o! o/0ect &ro1ram )he,* + Col. 1=S1C Len1th o! o/0ect &ro1ram in /yte )he,* Te,t record + Col. 1 T + Col. 2S; Startin1 addre !or o/0ect code in thi record )he,* + Col. <SC Len1th o! o/0ect code in thi record in /yte )he,* 1<

+ Col. 10S6C O/0ect code, re&re ented in he, )2 col. &er /yte* End record + Col.1 E + Col.2S; %ddre o! !ir t e,ecuta/le in truction in o/0ect &ro1ram )he,* QTU i only !or e&aration only O4=e!# !ode 2o$ #.e e*"+,'e ,$o%$"+;

Some o! the !eature in the &ro1ram de&end on the architecture o! the machine. I! the &ro1ram i !or SIC machine, then "e ha3e only limited in truction !ormat and hence limited addre in1 mode . 7e ha3e only in1le o&erand in truction . The o&erand i al"ay a memory re!erence. %nythin1 to /e !etched !rom memory re6uire more time. Jence the im&ro3ed 3er ion o! SIC'(E machine &ro3ide more in truction !ormat and hence more addre in1 mode . The moment "e chan1e the machine architecture the a3aila/ility o! num/er o! in truction !ormat and the addre in1 mode chan1e . There!ore the de i1n u ually re6uire con iderin1 t"o thin1 F $achine+de&endent !eature and $achine+inde&endent !eature . 39 M"!. ne-8e,enden# Fe"#($e&; In truction !ormat and addre in1 mode Bro1ram

relocation

391 In&#$(!# on 2o$+"#& "nd Add$e&& n% Mode& The in truction !ormat de&end on the memory or1ani5ation and the i5e o! the memory. In SIC machine the memory i /yte addre a/le. 7ord i5e i : /yte . So the i5e o! the memory i 212 /yte . %ccordin1ly it u&&ort only one in truction !ormat. It ha only t"o re1i ter F re1i ter % and Inde, re1i ter. There!ore the addre in1 mode u&&orted /y thi architecture are direct, indirect, and inde,ed. 7herea the memory o! a SIC'(E machine i 220 /yte )1 $A*. Thi u&&ort !our di!!erent ty&e o! in truction ty&e , they areF 1 /yte in truction 2 /yte in truction : /yte in truction = /yte in truction In truction can /eF In truction in3ol3in1 re1i ter to re1i ter In truction "ith one o&erand in memory, the other in %ccumulator )Sin1le o&erand in truction* E,tended in truction !ormat %ddre in1 $ode areF Inde, %ddre in1)SIC*F O&code m, , Indirect %ddre in1F O&code Vm 1C

BC+relati3eF O&code m Aa e relati3eF O&code m Immediate addre in1F O&code Pc

1. Translations for the Instruction involving Register-Register addressing mode: 8($ n% ,"&& 1 the re1i ter can /e entered a &art o! the ym/ol ta/le it el!. The 3alue !or the e re1i ter i their e6ui3alent numeric code . 8($ n% ,"&& 2) the e 3alue are a em/led alon1 "ith the mnemonic o/0ect code. I! re6uired a e&arate ta/le can /e created "ith the re1i ter name and their e6ui3alent numeric 3alue . 2. Tran lation in3ol3in1 -e1i ter+$emory in truction F In SIC'(E machine there are !our in truction !ormat and !i3e addre in1 mode . 9or !ormat and addre in1 mode re!er cha&ter 1. %mon1 the in truction !ormat , !ormat +: and !ormat+= in truction are -e1i ter+ $emory ty&e o! in truction. One o! the o&erand i al"ay in a re1i ter and the other o&erand i in the memory. The addre in1 mode tell u the "ay in "hich the o&erand !rom the memory i to /e !etched. There are t"o "ay F Program-counter relative and Base-relative. Thi addre in1 mode can /e re&re ented /y either u in1 !ormat+: ty&e or !ormat+= ty&e o! in truction !ormat. In !ormat+:, the in truction ha the o&code !ollo"ed /y a 12+/it di &lacement 3alue in the addre !ield. 7here a in !ormat+= the in truction contain the mnemonic code !ollo"ed /y a 20+/it di &lacement 3alue in the addre !ield. 2. Program-Counter Relative: In thi u ually !ormat+: in truction !ormat i u ed. The in truction contain the o&code !ollo"ed /y a 12+/it di &lacement 3alue. The ran1e o! di &lacement 3alue are !rom 0 +20=<. Thi di &lacement ) hould /e mall enou1h to !it in a 12+/it !ield* 3alue i added to the current content o! the &ro1ram counter to 1et the tar1et addre o! the o&erand re6uired /y the in truction. Thi i relati3e "ay o! calculatin1 the addre o! the o&erand relati3e to the &ro1ram counter. Jence the di &lacement o! the o&erand i relati3e to the current &ro1ram counter 3alue. The !ollo"in1 e,am&le ho" ho" the addre i calculatedF

20

3. Base-Relative Addressing ode: in thi mode the /a e re1i ter i u ed to mention the di &lacement 3alue. There!ore the tar1et addre i T% D )/a e* E di &lacement 3alue Thi addre in1 mode i u ed "hen the ran1e o! di &lacement 3alue i not u!!icient. Jence the o&erand i not relati3e to the in truction a in BC+relati3e addre in1 mode. 7hene3er thi mode i u ed it i indicated /y u in1 a directi3e A%SE. The moment the a em/ler encounter thi directi3e the ne,t in truction u e /a e+relati3e addre in1 mode to calculate the tar1et addre o! the o&erand. 7hen NOA%SE directi3e i u ed then it indicate the /a e re1i ter i no more u ed to calculate the tar1et addre o! the o&erand. % em/ler !ir t choo e BC+relati3e, "hen the di &lacement !ield i not enou1h it u e Aa e+relati3e. L8A PLENITJ )instruction* A%SE LENITJ )directive* F NOA%SE 9or e,am&leF 12 1: FF 100 105 FF 160 165 000: L8A A%SE 00:: 00:6 LENITJ A>99EPLENITJ LENITJ -ES7 -ESA A>99E-, T 1 =0C6 ( A<50 5;C00: 6C2028

10=E STCJ 1051 TI(-

In the a/o3e e,am&le the u e o! directi3e A%SE indicate that Aa e+relati3e addre in1 mode i to /e u ed to calculate the tar1et addre . BC+relati3e i no lon1er u ed. The 3alue o! the LENITJ i tored in the /a e re1i ter. I! BC+relati3e i u ed then the tar1et addre calculated i F The L8A in truction load the 3alue o! len1th in the /a e re1i ter "hich 00::. A%SE directi3e e,&licitly tell the a em/ler that it ha the 3alue o! LENITJ. A>99E- i at location )00:6*16 )A* D )00::*16 di & D 00:6 00:: D )000:*16

20

000%

L8%

LENITJ

0:2026

21

FF 1;5

1056

E(IT

ST(

LENITJ

1:=000

Con ider Line 1;5. I! "e u e BC+relati3e 8i & D T% )BC* D 00:: 105C D E98% BC relati3e i no lon1er a&&lica/le, o "e try to u e A%SE relati3e addre in1 mode. !. Immediate Addressing ode

In thi mode no memory re!erence i in3ol3ed. I! immediate mode i u ed the tar1et addre i the o&erand it el!.

I! the ym/ol i re!erred in the in truction a the immediate o&erand then it i immediate "ith BC+relati3e mode a ho"n in the e,am&le /elo"F

". Indirect and PC-relative mode; In thi ty&e o! in truction the ym/ol u ed in the in truction i the addre o! the location "hich contain the addre o! the o&erand. The addre o! thi i !ound u in1 BC+relati3e addre in1 mode. 9or e,am&leF

22

The in truction 0um& the control to the addre location -ET%8- "hich in turn ha the addre o! the o&erand. I! addre o! -ET%8- i 00:0, the tar1et addre i then 000: a calculated a/o3e.

:.2 Bro1ram -elocation


Sometime it i re6uired to load and run e3eral &ro1ram at the ame time. The y tem mu t /e a/le to load the e &ro1ram "here3er there i &lace in the memory. There!ore the e,act tartin1 i not 2no"n until the load time. A4&o'(#e <$o%$"+ In thi the addre i mentioned durin1 a em/lin1 it el!. Thi i called Absolute Assembly. Con ider the in tructionF 55 101A L8% TJ-EE 001028

Thi tatement ay that the re1i ter % i loaded "ith the 3alue tored at location 1028. Su&&o e it i decided to load and e,ecute the &ro1ram at location 2000 in tead o! location 1000. Then at addre 1028 the re6uired 3alue "hich need to /e loaded in the re1i ter % i no more a3aila/le. The addre al o 1et chan1ed relati3e to the di &lacement o! the &ro1ram. Jence "e need to ma2e ome chan1e in the addre &ortion o! the in truction o that "e can load and e,ecute the &ro1ram at location 2000. %&art !rom the in truction "hich "ill under1o a chan1e in their o&erand addre 3alue a the &ro1ram load addre chan1e . There e,i t ome &art in the &ro1ram "hich "ill remain ame re1ardle o! "here the &ro1ram i /ein1 loaded. Since a em/ler "ill not 2no" actual location "here the &ro1ram "ill 1et loaded, it cannot ma2e the nece ary chan1e in the addre e u ed in the &ro1ram. Jo"e3er, the a em/ler identi!ie !or the loader tho e &art o! the &ro1ram "hich need modi!ication. %n o/0ect &ro1ram that ha the in!ormation nece ary to &er!orm thi 2ind o! modi!ication i called the relocata/le &ro1ram. 39291 Con#$o' Se!# on&; % control section i a &art o! the &ro1ram that maintain it identity a!ter a em/ly? each control ection can /e loaded and relocated inde&endently o! the other . 8i!!erent control ection are mo t o!ten u ed !or u/routine or other lo1ical

2:

u/di3i ion . The &ro1rammer can a em/le, load, and mani&ulate each o! the e control ection e&arately. Aecau e o! thi , there hould /e ome mean !or lin2in1 control ection to1ether. 9or e,am&le, in truction in one control ection may re!er to the data or in truction o! other control ection . Since control ection are inde&endently loaded and relocated, the a em/ler i una/le to &roce the e re!erence in the u ual "ay. Such re!erence /et"een di!!erent control ection are called external references. The a em/ler 1enerate the in!ormation a/out each o! the e,ternal re!erence that "ill allo" the loader to &er!orm the re6uired lin2in1. 7hen a &ro1ram i "ritten u in1 multi&le control ection , the /e1innin1 o! each o! the control ection i indicated /y an a em/ler directi3e a em/ler directi3eF CSECT T.e &5n#"* &e!n"+e CSECT e&arate location counter !or each control ection Control ection di!!er !rom &ro1ram /loc2 in that they are handled e&arately /y the a em/ler. Sym/ol that are de!ined in one control ection may not /e u ed directly another control ection? they mu t /e identi!ied a e,ternal re!erence !or the loader to handle. The e,ternal re!erence are indicated /y t"o a em/ler directi3e F E(T8E9 )e,ternal 8e!inition*F It i the tatement in a control ection, name ym/ol that are de!ined in thi ection /ut may /e u ed /y other control ection . Control ection name do not need to /e named in the E(T-E9 a they are automatically con idered a e,ternal ym/ol . E(T-E9 )e,ternal -e!erence*F It name ym/ol that are u ed in thi ection /ut are de!ined in ome other control ection. The order in "hich the e ym/ol are li ted i not i1ni!icant. The a em/ler mu t include &ro&er in!ormation a/out the e,ternal re!erence in the o/0ect &ro1ram that "ill cau e the loader to in ert the &ro&er 3alue "here they are re6uired. H"nd' n% E*#e$n"' Re2e$en!e C"&e 1 15 000: CLOOB E@S>A -8-EC =A100000 The o&erand -8-EC i an e,ternal re!erence. o The a em/ler ha no idea "here -8-EC i o in ert an addre o! 5ero o can only u e e,tended !ormat to &ro3ide enou1h room )that i , relati3e addre in1 !or e,ternal re!erence i in3alid*

2=

C"&e 2 1C0 C"&e 3

The a em/ler 1enerate in!ormation !or each e,ternal re!erence that "ill allo" the loader to &er!orm the re6uired lin2in1.

002< $%(LEN 000000

7O-8

A>9EN8+A>99E-

There are t"o e,ternal re!erence in the e,&re ion, A>9EN8 and A>99E-. The a em/ler in ert a 3alue o! 5ero &a e in!ormation to the loader %dd to thi data area the addre o! A>9EN8 Su/tract !rom thi data area the addre o! A>99E-

On line 10;, A>9EN8 and A>99E- are de!ined in the ame control ection and the e,&re ion can /e calculated immediately. 10; 1000 $%(LEN EH> A>9EN8+A>99E-

O4=e!# Code 2o$ #.e e*"+,'e ,$o%$"+; The a em/ler mu t al o include in!ormation in the o/0ect &ro1ram that "ill cau e the loader to in ert the &ro&er 3alue "here they are re6uired. The a em/ler maintain t"o ne" record in the o/0ect code and a chan1ed 3er ion o! modi!ication record. 8e!ine record )E(T8E9* Col. 1 8 Col. 2+; Name o! e,ternal ym/ol de!ined in thi control ection Col. <+1: -elati3e addre "ithin thi control ection )he,adecimal* Col.1=+;: -e&eat in!ormation in Col. 2+1: !or other e,ternal ym/ol -e!er record )E(T-E9* Col. 1 Col. 2+; Name o! e,ternal ym/ol re!erred to in thi control ection Col. <+;: Name o! other e,ternal re!erence ym/ol $odi!ication record Col. 1 Col. 2+; Col. <+C Col.11+16 $ Startin1 addre o! the !ield to /e modi!ied )he,adecimal* Len1th o! the !ield to /e modi!ied, in hal!+/yte )he,adecimal* E,ternal ym/ol "ho e 3alue i to /e added to or u/tracted !rom

25

the indicated !ield % de!ine record 1i3e in!ormation a/out the e,ternal ym/ol that are de!ined in thi control ection, i.e., ym/ol named /y E(T8E9. % re!er record li t the ym/ol that are u ed a e,ternal re!erence /y the control ection, i.e., ym/ol named /y E(T-E9. The ne" item in the modi!ication record &eci!y the modi!ication to /e &er!ormedF addin1 or u/tractin1 the 3alue o! ome e,ternal ym/ol. The ym/ol u ed !or modi!ication my /e de!ined either in thi control ection or in another ection. The o/0ect &ro1ram i ho"n /elo". There i a e&arate o/0ect &ro1ram !or each o! the control ection . In the Define ecord and refer record the ym/ol named in E(T8E9 and E(T-E9 are included. In the ca e o! Define! the record al o indicate the relati3e addre e,ternal ym/ol "ithin the control ection. 9or E(T-E9 ym/ol , no addre im&ly named in the efer record. o! each

in!ormation i a3aila/le. The e ym/ol are

H"nd' n% E*,$e&& on& n M('# ,'e Con#$o' Se!# on&; The e,i tence o! multi&le control ection that can /e relocated inde&endently o! one another ma2e the handlin1 o! e,&re ion com&licated. It i re6uired that in an e,&re ion that all the relati3e term /e &aired )!or a/ olute e,&re ion*, or that all e,ce&t one /e &aired )!or relati3e e,&re ion *. 7hen it come in a &ro1ram ha3in1 multi&le control ection then "e ha3e an e,tended re triction thatF Aoth term in each &air o! an e,&re ion mu t /e "ithin the ame control ection o I! t"o term re&re ent relati3e location "ithin the ame control ection , their di!!erence i an a/ olute 3alue )re1ardle o! "here the control ection i located. Le%"'; A>9EN8+A>99E- )/oth are in the ame control ection* o I! the term are located in di!!erent control ection , their di!!erence ha a 3alue that i un&redicta/le. I''e%"'; -8-EC+COBK )/oth are o! di!!erent control ection* it i the di!!erence in the load addre e o! the t"o control ection . Thi 3alue de&end on the "ay run+time tora1e i allocated? it i unli2ely to /e o! any u e. Ho3 #o en2o$!e #. & $e&#$ !# on

26

o 7hen an e,&re ion in3ol3e e,ternal re!erence , the a em/ler cannot determine "hether or not the e,&re ion i le1al. o The a em/ler e3aluate all o! the term it can, com/ine the e to !orm an initial e,&re ion 3alue, and 1enerate $odi!ication record . o The loader chec2 the e,&re ion !or error and !ini he the e3aluation. 391 ASSEM:LER 8ESIGN Jere "e are di cu in1 o The tructure and lo1ic o! one+&a a em/ler. The e a em/ler are u ed "hen it i nece ary or de ira/le to a3oid a econd &a o3er the ource &ro1ram. o Notion o! a multi+&a a em/ler, an e,ten ion o! t"o+&a a em/ler that allo" an a em/ler to handle !or"ard re!erence durin1 ym/ol de!inition. 39191 One-<"&& A&&e+4'e$

The main &ro/lem in de i1nin1 the a em/ler u in1 in1le &a "a to re ol3e !or"ard re!erence . 7e can a3oid to ome e,tent the !or"ard re!erence /yF Eliminatin1 !or"ard re!erence to data item , /y de!inin1 all the tora1e re er3ation tatement at the /e1innin1 o! the &ro1ram rather at the end. >n!ortunately, !or"ard re!erence to la/el on the in truction cannot /e a3oided. )!or"ard 0um&in1* To &ro3ide ome &ro3i ion !or handlin1 !or"ard re!erence /y &rohi/itin1 !or"ard re!erence to data item . There are t"o ty&e o! one+&a a em/ler F One that &roduce o/0ect code directly in memory !or immediate e,ecution )Load+and+1o a em/ler *. The other ty&e &roduce the u ual 2ind o! o/0ect code !or later e,ecution. Lo"d-"nd-Go A&&e+4'e$ Load+and+1o a em/ler 1enerate their o/0ect code in memory !or immediate e,ecution. No o/0ect &ro1ram i "ritten out, no loader i needed. It i u e!ul in a y tem "ith !re6uent &ro1ram de3elo&ment and te tin1 o The e!!iciency o! the a em/ly &roce i an im&ortant con ideration. Bro1ram are re+a em/led nearly e3ery time they are run? e!!iciency o! the a em/ly &roce i an im&ortant con ideration.

2;

Fo$3"$d Re2e$en!e n One-<"&& A&&e+4'e$&; In load+and+Io a em/ler "hen a !or"ard re!erence i encountered F Omit the o&erand addre i! the ym/ol ha not yet /een de!ined Enter thi unde!ined ym/ol into SK$T%A and indicate that it i unde!ined %dd the addre o! thi o&erand addre to a li t o! !or"ard re!erence a ociated "ith the SK$T%A entry 7hen the de!inition !or the ym/ol i encountered, can the re!erence li t and in ert the addre . %t the end o! the &ro1ram, re&ort the error i! there are till SK$T%A entrie indicated unde!ined ym/ol . 9or Load+and+Io a em/ler o Search SK$T%A !or the ym/ol named in the EN8 tatement and 0um& to thi location to /e1in e,ecution i! there i no error

A2#e$ S!"nn n% ' ne 40 o2 #.e ,$o%$"+; 40 2021 J> CLOO<

302012

The tatu i that u&to thi &oint the ym/ol --EC i re!erred once at location 201:, EN89IL at 2019 and 7--EC at location 201C. None o! the e ym/ol are de!ined. The !i1ure ho" that ho" the &endin1 de!inition alon1 "ith their addre e are included in the ym/ol ta/le.

2<

T.e &#"#(& "2#e$ &!"nn n% ' ne 160) 3. !. ."& en!o(n#e$ed #.e de2 n # on o2 R8REC "nd EN8FIL & "& % /en 4e'o3; I2 One-<"&& need& #o %ene$"#e o4=e!# !ode; I! the o&erand contain an unde!ined ym/ol, u e 0 a the addre and "rite the Te,t record to the o/0ect &ro1ram. 9or"ard re!erence are entered into li t a in the load+and+1o a em/ler. 7hen the de!inition o! a ym/ol i encountered, the a em/ler 1enerate another Te,t record "ith the correct o&erand addre o! each entry in the re!erence li t. 7hen loaded, the incorrect addre 0 "ill /e u&dated /y the latter Te,t record containin1 the ym/ol de!inition.

M('# ?<"&& A&&e+4'e$; 9or a t"o &a allo"edF a em/ler, !or"ard re!erence in ym/ol de!inition are not

%LBJ% EH> AET% AET% EH> 8ELT% 8ELT% -ES7 1 o Sym/ol de!inition mu t /e com&leted in &a 1. Brohi/itin1 !or"ard re!erence in ym/ol de!inition i not a eriou incon3enience. o 9or"ard re!erence tend to create di!!iculty !or a &er on readin1 the &ro1ram.

2C

I+,'e+en#"# on I&&(e& 2o$ Mod 2 ed T3o-<"&& A&&e+4'e$; Im&lementation I uue "hen !or"ard re!erencin1 i encountered in "ymbol Defining statements F 9or a !or"ard re!erence in ym/ol de!inition, "e tore in the SK$T%AF o The ym/ol name o The de!inin1 e,&re ion o The num/er o! unde!ined ym/ol in the de!inin1 e,&re ion The unde!ined ym/ol )mar2ed "ith a !la1 O* a ociated "ith a li t o! ym/ol de&end on thi unde!ined ym/ol. 7hen a ym/ol i de!ined, "e can recur i3ely e3aluate the ym/ol e,&re ion de&endin1 on the ne"ly de!ined ym/ol.

Cha&ter : Loader and Lin2er Thi Cha&ter 1i3e youM


Aa ic Loader 9unction $achine+8e&endent Loader 9eature $achine+Inde&endent Loader 9eature Loader 8e i1n O&tion Im&lementation E,am&le

:.0 Introduction
The Source Bro1ram "ritten in a em/ly lan1ua1e or hi1h le3el lan1ua1e "ill /e con3erted to o/0ect &ro1ram, "hich i in the machine lan1ua1e !orm !or e,ecution. Thi con3er ion either !rom a em/ler or !rom com&iler , contain tran lated in truction and data 3alue !rom the ource &ro1ram, or &eci!ie addre e in &rimary memory "here the e item are to /e loaded !or e,ecution. Thi contain the !ollo"in1 three &roce e , and they are, Lo"d n% + "hich allocate memory location and /rin1 the o/0ect &ro1ram into memory !or e,ecution + )Loader* L n@ n%+ "hich com/ine t"o or more e&arate o/0ect &ro1ram and u&&lie the in!ormation needed to allo" re!erence /et"een them + )Lin2er* Re'o!"# on + "hich modi!ie the o/0ect &ro1ram o that it can /e loaded at an addre di!!erent !rom the location ori1inally &eci!ied + )Lin2in1 Loader*

:0

:.1 Aa ic Loader 9unction


% loader i a y tem &ro1ram that &er!orm the loadin1 !unction. It /rin1 o/0ect &ro1ram into memory and tart it e,ecution. The role o! loader i a ho"n in the !i1ure :.1. In !i1ure :.1 tran lator may /e a em/ler'com&lier, "hich 1enerate the o/0ect &ro1ram and later loaded to the memory /y the loader !or e,ecution. In !i1ure :.2 the tran lator i &eci!ically an a em/ler, "hich 1enerate the o/0ect loaded, "hich /ecome in&ut to the loader. The !i1ure :.: ho" the role o! /oth loader and lin2er.

:.: Ty&e o! Loader


The di!!erent ty&e o! loader are, a/ olute loader, /oot tra& loader, relocatin1 loader )relati3e loader*, and, direct lin2in1 loader. The !ollo"in1 ection di cu the !unction and de i1n o! all the e ty&e o! loader .

:.:.1 %/ olute Loader


The o&eration o! a/ olute loader i 3ery im&le. The o/0ect code i loaded to &eci!ied location in the memory. %t the end the loader 0um& to the &eci!ied addre to /e1in e,ecution o! the loaded &ro1ram. The role o! a/ olute loader i a ho"n in the !i1ure :.:.1. The ad3anta1e o! a/ olute loader i im&le and e!!icient. Aut the di ad3anta1e are, the need !or &ro1rammer to &eci!y the actual addre , and, di!!icult to u e u/routine li/rarie .

:1

O4=e!# <$o%$"+

1000 A4&o'(#e Lo"de$ O4=e!# ,$o%$"+ $e"d5 2o$ e*e!(# on 2000

Memory F %($e 39391; T.e Ro'e o2 A4&o'(#e Lo"de$ The al1orithm !or thi ty&e o! loader i 1i3en here. The o/0ect &ro1ram and, the o/0ect &ro1ram loaded into memory /y the a/ olute loader are al o ho"n. Each /yte o! a em/led code i 1i3en u in1 it he,adecimal re&re entation in character !orm. Ea y to read /y human /ein1 . Each /yte o! o/0ect code i tored a a in1le /yte. $o t machine tore o/0ect &ro1ram in a /inary !orm, and "e mu t /e ure that our !ile and de3ice con3ention do not cau e ome o! the &ro1ram /yte to /e inter&reted a control character . :e% n read Jeader record 3eri!y &ro1ram name and len1th read !ir t Te,t record 3. 'e record ty&e i WX NE4 do 4e% n Yi! o/0ect code i in character !orm, con3ert into internal re&re entationZ mo3e o/0ect code to &eci!ied location in memory read ne,t o/0ect &ro1ram record end 0um& to addre &eci!ied in End record end

:.:.2 % Sim&le Aoot tra& Loader

:2

7hen a com&uter i !ir t turned on or re tarted, a &ecial ty&e o! a/ olute loader, called /oot tra& loader i e,ecuted. Thi /oot tra& load the !ir t &ro1ram to /e run /y the com&uter ++ u ually an o&eratin1 y tem . The /oot tra& it el! /e1in at addre 0. It load the OS tartin1 addre 0,<0. No header record or control in!ormation, the o/0ect code i con ecuti3e /yte o! memory. The al1orithm !or the /oot tra& loader i a !ollo" :e% n (D0,<0 )the addre o! the ne,t memory location to /e loaded Loo, % IETC )and con3ert it !rom the %SCII character code to the 3alue o! the he,adecimal di1it* a3e the 3alue in the hi1h+order = /it o! S % IETC com/ine the 3alue to !orm one /yte % )%ES* tore the 3alue )in %* to the addre in re1i ter ( ( (E1 End It u e a u/routine IETC, "hich i IETC % read one character i! %D0,0= then 0um& to 0,<0 i! %W=< then IETC % %+=< )0,:0* i! %W10 then return % %+; return

:.= $achine+8e&endent Loader 9eature


%/ olute loader i im&le and e!!icient, /ut the cheme ha &otential di ad3anta1e One o! the mo t di ad3anta1e i the &ro1rammer ha to &eci!y the actual tartin1 addre , !rom "here the &ro1ram to /e loaded. Thi doe not create di!!iculty, i! one &ro1ram to run, /ut not !or e3eral &ro1ram . 9urther it i di!!icult to u e u/routine li/rarie e!!iciently. Thi need the de i1n and im&lementation o! a more com&le, loader. The loader mu t &ro3ide &ro1ram relocation and lin2in1, a "ell a im&le loadin1 !unction .

:.=.1 -elocation

::

The conce&t o! &ro1ram relocation i , the e,ecution o! the o/0ect &ro1ram u in1 any &art o! the a3aila/le and u!!icient memory. The o/0ect &ro1ram i loaded into memory "here3er there i room !or it. The actual tartin1 addre o! the o/0ect &ro1ram i not 2no"n until load time. -elocation &ro3ide the e!!icient harin1 o! the machine "ith lar1er memory and "hen e3eral inde&endent &ro1ram are to /e run to1ether. It al o u&&ort the u e o! u/routine li/rarie e!!iciently. Loader that allo" !or &ro1ram relocation are called relocatin1 loader or relati3e loader .

:.=.2 $ethod !or &eci!yin1 relocation


> e o! modi!ication record and, u e o! relocation /it, are the method a3aila/le !or &eci!yin1 relocation. In the ca e o! modi!ication record, a modi!ication record $ i u ed in the o/0ect &ro1ram to &eci!y any relocation. In the ca e o! u e o! relocation /it, each in truction i a ociated "ith one relocation /it and, the e relocation /it in a Te,t record i 1athered into /it ma 2 . $odi!ication record are u ed in com&le, machine and i al o called -elocation and Lin2a1e 8irectory )-L8* &eci!ication. The !ormat o! the modi!ication record )$* i a !ollo" . The o/0ect &ro1ram "ith relocation /y $odi!ication record i al o ho"n here. $odi!ication record col 1F $ col 2+;F relocation addre col <+CF len1th )hal!/yte* col 10F !la1 )E'+* col 11+1;F e1ment name JCOBK 000000 0010;; T000000 181;20286C2028=<1010:6M=A1058:929EC0:2010 T0000181:09201601000:092008=A101058:E200:=5=9=6 T0010:5 18A=10A=00A==0;5101000M::200<5;C00:A<50 T00105:18:A29E%1:=000=9000091..5:C00:89200<A<50 T000;00;:A29E9=9000005 $00000;05ECOBK $00001=05ECOBK $00002;05ECOBK E000000

The relocation /it method i u ed !or im&le machine . -elocation /it i 0F no modi!ication i nece ary, and i 1F modi!ication i needed. Thi i &eci!ied in the :=

column 10+12 o! te,t record )T*, the !ormat o! te,t record, alon1 "ith relocation /it i a !ollo" . Te,t record col 1F T col 2+;F tartin1 addre col <+CF len1th )/yte* col 10+12F relocation /it col 1:+;2F o/0ect code T"el3e+/it ma 2 i u ed in each Te,t record )colF10+12 relocation /it *, ince each te,t record contain le than 12 "ord , unu ed "ord are et to 0, and, any 3alue that i to /e modi!ied durin1 relocation mu t coincide "ith one o! the e :+/yte e1ment . 9or a/ olute loader, there are no relocation /it column 10+6C contain o/0ect code. The o/0ect &ro1ram "ith relocation /y /it ma 2 i a ho"n /elo". O/ er3e 99C + mean all ten "ord are to /e modi!ied and, E00 + mean !ir t three record are to /e modi!ied. JCOBK 000000 0010;% T0000001E99C1=00::=<10:C0000:62<00:0:00015M:C000: M T00001E15E000C00:6=<10610<00::=C0000M00000:000000 T0010:C1E99C0=00:00000:0M:010:98<10582<00:0... T00105;0% <001000:6=C000091001000 T0010611C9E00=00:0E010;CM50<0:C8C10;C2C00:6... E000000

:.5 Bro1ram Lin2in1


The Ioal o! &ro1ram lin2in1 i to re ol3e the &ro/lem "ith e,ternal re!erence )E(T-E9* and e,ternal de!inition )E(T8E9* !rom di!!erent control ection . EAT8EF -e*#e$n"' de2 n # on0 + The E(T8E9 tatement in a control ection name ym/ol , called e,ternal ym/ol , that are de!ined in thi )&re ent* control ection and may /e u ed /y other ection . e,F E(T8E9 A>99E-, A>99EN8, LENITJ E(T8E9 LIST%, EN8% EATREF -e*#e$n"' $e2e$en!e0 + The E(T-E9 tatement name in thi )&re ent* control ection and are de!ined el e"here. e,F E(T-E9 -8-EC, 7--EC E(T-E9 LISTA, EN8A, LISTC, EN8C Ho3 #o +,'e+en# EAT8EF "nd EATREF :5 ym/ol u ed

The a em/ler mu t include in!ormation in the o/0ect &ro1ram that "ill cau e the loader to in ert &ro&er 3alue "here they are re6uired in the !orm o! 8e!ine record )8* and, -e!er record)-*. 8e2 ne $e!o$d The !ormat o! the 8e!ine record )8* alon1 "ith e,am&le i a Col. 1 Col. 2+; Col. <+1: Col.1=+;: ho"n here9

8 Name o! e,ternal ym/ol de!ined in thi control ection -elati3e addre "ithin thi control ection )he,adecimal* -e&eat in!ormation in Col. 2+1: !or other e,ternal ym/ol

E*"+,'e $e!o$d& 8 LISTA 000040 EN8A 000014 8 LIST: 000060 EN8: 0000B0 Re2e$ $e!o$d The !ormat o! the -e!er record )-* alon1 "ith e,am&le i a Col. 1 Col. 2+; Col. <+;: ho"n here9

Name o! e,ternal ym/ol re!erred to in thi control ection Name o! other e,ternal re!erence ym/ol

E*"+,'e $e!o$d& R LIST: EN8: LISTC EN8C R LISTA EN8A LISTC EN8C R LISTA EN8A LIST: EN8: Jere are the three &ro1ram named a B-OI%, B-OIA and B-OIC, "hich are e&arately a em/led and each o! "hich con i t o! a in1le control ection. LIST%, EN8% in B-OI%, LISTA, EN8A in B-OIA and LISTC, EN8C in B-OIC are e,ternal de!inition in each o! the control ection . Similarly LISTA, EN8A, LISTC, EN8C in B-OI%, LIST%, EN8%, LISTC, EN8C in B-OIA, and LIST%, EN8%, LISTA, EN8A in B-OIC, are e,ternal re!erence . The e am&le &ro1ram 1i3en here are u ed to illu trate lin2in1 and relocation. The !ollo"in1 !i1ure 1i3e the am&le &ro1ram and their corre &ondin1 o/0ect &ro1ram . O/ er3e the o/0ect &ro1ram , "hich contain 8 and - record alon1 "ith other record . 0000 <ROGA ST%-T 0

:6

0020 002: 002; 00=0 005= 005= 005; 005% 0058 0060

-E91 -E92 -E9: LIST% EN8% -E9= -E95 -E96 -E9; -E9<

E(T8E9 E(T-E9 MMM.. MMM. L8% EL8T L8( . . EH> EH> 7O-8 7O-8 7O-8 7O-8 7O-8 EN8

LIST%, EN8% LISTA, EN8A, LISTC, EN8C LIST% LISTAE= PEN8%+LIST% O O EN8%+LIST%ELISTC 00001= EN8C+LISTC+10 999996 EN8C+LISTCELIST%+1 0000:9 EN8%+LIST%+)EN8A+LISTA* 00001= LISTA+LIST% 9999C0 -E91 0:2018 ;;10000= 05001=

0000

<ROG:

00:6 -E91 00:% -E92 00:8 -E9: 0060 00;0 00;0 00;: 00;6 00;C 00;C LISTA EN8A -E9= -E95 -E96 -E9; -E9<

ST%-T E(T8E9 E(T-E9 MMM.. MMM. EL8% L8T EL8( . . EH> EH> 7O-8 7O-8 7O-8 7O-8 7O-8 EN8

0 LISTA, EN8A LIST%, EN8%, LISTC, EN8C LIST% LISTAE= PEN8%+LIST% O O EN8%+LIST%ELISTC EN8C+LISTC+10 EN8C+LISTCELIST%+1 EN8%+LIST%+)EN8A+LISTA* LISTA+LIST% 000000 999996 999999 999990 000060 0:100000 ;;202; 05100000

0000

<ROGC

ST%-T

:;

001< -E91 001C -E92 0020 -E9: 00:0 00=2 00=2 00=5 00=5 00=A 00=E LISTC EN8C -E9= -E95 -E96 -E9; -E9<

E(T8E9 E(T-E9 MMM.. MMM.. EL8% EL8T EL8( . . EH> EH> 7O-8 7O-8 7O-8 7O-8 7O-8 EN8

LISTC, EN8C LIST%, EN8%, LISTA, EN8A LIST% LISTAE= PEN8%+LIST% O O EN8%+LIST%ELISTC EN8C+LISTC+10 EN8C+LISTCELIST%+1 EN8%+LIST%+)EN8A+LISTA* LISTA+LIST% 0000:0 00000< 000011 000000 000000 0:100000 ;;10000= 05100000

J <ROGA 000000 00006: 8 LISTA 000040 EN8A 000014 R LIST: EN8: LISTC EN8C . . T 000020 0% 0:2018 ;;10000= 05001= . . T 00005= 09 00001= 99996 0000:9 00001= 9999C0 $00002= 05ELISTA $00005= 06ELISTC $00005; 06EEN8C $00005; 06 +LISTC $00005%06EEN8C $00005%06 +LISTC $00005%06EB-OI% $00005806+EN8A $00005806ELISTA $00006006ELISTA $00006006+B-OI% E000020 J <ROG: 000000 0000;9

:<

8 LIST: 000060 EN8: 0000B0 R LISTA EN8A LISTC EN8C . T 0000:6 0A 0:100000 ;;202; 05100000 . T 00000; 09 000000 999996 999999 999990 000060 $0000:; 05ELIST% $0000:E 06EEN8% $0000:E 06 +LIST% $0000;0 06 EEN8% $0000;0 06 +LIST% $0000;0 06 ELISTC $0000;: 06 EEN8C $0000;: 06 +LISTC $0000;: 06 EEN8C $0000;6 06 +LISTC $0000;6 06ELIST% $0000;C 06EEN8% $0000;C 06 +LIST% $0000;C 06EB-OIA $0000;C 06+LIST% E J <ROGC 000000 000051 8 LISTC 000030 EN8C 000042 R LISTA EN8A LIST: EN8: . T 00001< 0C 0:100000 ;;10000= 05100000 . T 0000=2 09 0000:0 00000< 000011 000000 000000 $00001C 05ELIST% $000018 06ELISTA $000021 06EEN8% $000021 06 +LIST% $0000=2 06EEN8% $0000=2 06 +LIST% $0000=2 06EB-OIC $0000=< 06ELIST% $0000=A 06EEN8% $0000=A 006+LIST% $0000=A 06+EN8A $0000=A 06ELISTA $0000=E 06ELISTA $0000=E 06+LIST% E

:C

The !ollo"in1 !i1ure ho" the e three &ro1ram a they mi1ht a&&ear in memory a!ter loadin1 and lin2in1. B-OI% ha /een loaded tartin1 at addre =000, "ith B-OIA and B-OIC immediately !ollo"in1.

9or e,am&le, the 3alue !or -E9= in B-OI% i located at addre =05= )the /e1innin1 addre o! B-OI% &lu 005=, the relati3e addre o! -E9= "ithin B-OI%*. The !ollo"in1 !i1ure ho" the detail o! ho" thi 3alue i com&uted. The initial 3alue !rom the Te,t record T00005=0900001=9999960000:900001=9999C0 i 00001=. To thi i added the addre a i1ned to LISTC, "hich i =112 )the /e1innin1 addre o! B-OIC &lu :0*. The re ult i 00=126. That i -E9= in B-OI% i EN8%+LIST%ELISTCD=05=+=0=0E=112D=126. Similarly the load addre !or ym/ol LIST%F B-OI%E00=0D=0=0, LISTAF B-OIAE0060D=0C: and LISTCF B-OICE00:0D=112 [ee&in1 the e detail "or2 throu1h the detail o! other re!erence and 3alue o! the e re!erence are the ame in each o! the three &ro1ram .

:.6 %l1orithm and 8ata tructure !or a Lin2in1 Loader


The al1orithm !or a lin2in1 loader i con idera/ly more com&licated than the a/ olute loader &ro1ram, "hich i already 1i3en. The conce&t 1i3en in the &ro1ram lin2in1 ection i u ed !or de3elo&in1 the al1orithm !or lin2in1 loader. The modi!ication record are u ed !or relocation o that the lin2in1 and relocation !unction are &er!ormed u in1 the ame mechani m. Lin2in1 Loader u e t"o+&a e lo1ic. EST%A )e,ternal ym/ol ta/le* i the main data tructure !or a lin2in1 loader. <"&& 1F % i1n addre e to all e,ternal ym/ol <"&& 2F Ber!orm the actual loadin1, relocation, and lin2in1 ESTA: + EST%A !or the e,am&le )re!er three &ro1ram B-OI% B-OIA and B-OIC* 1i3en i a ho"n /elo". The EST%A ha !our entrie in it? they are name o! the control ection, the ym/ol a&&earin1 in the control ection, it addre and len1th o! the control ection.

=0

Control ection B-OI%

Sym/ol

%ddre =000

Len1th 6:

LIST% EN8% B-OIA LISTA EN8A B-OIC LISTC EN8C

=0=0 =05= =06: =0C: =08: =0E2 =112 =12= 51 ;9

:.6.1 Bro1ram Lo1ic !or Ba

Ba 1 a i1n addre e to all e,ternal ym/ol . The 3aria/le # 8ata tructure u ed durin1 &a 1 are, B-OI%88- )&ro1ram load addre * !rom OS , CS%88)control ection addre *, CSLTJ )control ection len1th* and EST%A. The &a 1 &roce e the 8e!ine -ecord. The al1orithm !or Ba 1 o! Lin2in1 Loader i 1i3en /elo".

=1

:.6.2 Bro1ram Lo1ic !or Ba

Ba 2 o! lin2in1 loader &er!orm the actual loadin1, relocation, and lin2in1. It u e modi!ication record and loo2u& the ym/ol in EST%A to o/tain it addre . 9inally it u e end record o! a main &ro1ram to o/tain tran !er addre , "hich i a tartin1 addre needed !or the e,ecution o! the &ro1ram. The &a 2 &roce Te,t record and $odi!ication record o! the o/0ect &ro1ram . The al1orithm !or Ba 2 o! Lin2in1 Loader i 1i3en /elo".

=2

:.6.: Im&ro3e E!!iciency, Jo"\


The 6ue tion here i can "e im&ro3e the e!!iciency o! the lin2in1 loader. %l o o/ er3e that, e3en thou1h "e ha3e de!ined -e!er record )-*, "e ha3en4t made u e o! it. The e!!iciency can /e im&ro3ed /y the u e o! local earchin1 in tead o! multi&le earche o! EST%A !or the ame ym/ol. 9or im&lementin1 thi "e a i1n a re!erence num/er to each e,ternal ym/ol in the -e!er record. Then thi re!erence num/er i u ed in $odi!ication record in tead o! e,ternal ym/ol . 01 i a i1ned to control ection name, and other num/er !or e,ternal re!erence ym/ol . The o/0ect &ro1ram !or B-OI%, B-OIA and B-OIC are ho"n /elo", "ith a/o3e modi!ication to -e!er record ) O/ er3e - record *.

=:

ym/ol and %ddre e in B-OI%, B-OIA and B-OIC are a ho"n /elo". The e are the entrie o! EST%A. The main ad3anta1e o! re!erence num/er mechani m i that it a3oid multi&le earche o! EST%A !or the ame ym/ol durin1 the loadin1 o! a control ection

-e! No. 1 2 : = 5

Sym/ol B-OI% LISTA EN8A LISTC EN8C

%ddre =000 =0C: =08: =112 =12=

Ref No. 1 2 3 4

Symbol PROGB LISTA ENDA LIST! END!

Address 4063 4040 40 4 4112 4124

-e! No. 1 2 : = 5

Sym/ol B-OIC LIST% EN8% LISTA EN8A

%ddre =06: =0=0 =05= =0C: =08: ==

UNIT 4 Cha&ter =F $acro Broce or


% #acro re&re ent a commonly u ed 1rou& o! tatement in the ource &ro1rammin1 lan1ua1e. % macro in truction )macro* i a notational con3enience !or the &ro1rammer o It allo" the &ro1rammer to "rite horthand 3er ion o! a &ro1ram )module &ro1rammin1* The macro &roce or re&lace each macro in truction "ith the corre &ondin1 1rou& o! ource lan1ua1e tatement )expanding* o Normally, it &er!orm no analy i o! the te,t it handle . o It doe not concern the meanin1 o! the in3ol3ed tatement durin1 macro e,&an ion. The de i1n o! a macro &roce or 1enerally i mac$ine independent% T"o ne" a em/ler directi3e are u ed in macro de!inition o MACRO; identi!y the /e1innin1 o! a macro de!inition o MEN8; identi!y the end o! a macro de!inition Brototy&e !or the macro o Each &arameter /e1in "ith N#4 name $%C-O &arameter F /ody F $EN8 o AodyF the tatement that "ill /e 1enerated a the e,&an ion o! the macro.

491 :"& ! M"!$o <$o!e&&o$ F(n!# on&; #acro Definition and &xpansion #acro Processor Algorit$ms and Data structures

'.1.1 #acro Definition and &xpansionF The !i1ure ho" the $%C-O e,&an ion. The le!t /loc2 ho" the $%C-O de!inition and the ri1ht /loc2 ho" the e,&anded macro re&lacin1 the $%C-O call "ith it /loc2 o! e,ecuta/le in truction.

=5

$1 i a macro "ith t"o &arameter 81 and 82. The $%C-O tore the content o! re1i ter % in 81 and the content o! re1i ter A in 82. Later $1 i in3o2ed "ith the &arameter 8%T%1 and 8%T%2, Second time "ith 8%T%= and 8%T%:. E3ery call o! $%C-O i e,&ended "ith the e,ecuta/le tatement .

F % 491

The tatement $1 8%T%1, 8%T%2 i a macro in3ocation tatement that 1i3e the name o! the macro in truction /ein1 in3o2ed and the ar1ument )$1 and $2* to /e u ed in e,&andin1. % macro in3ocation i re!erred a a $acro Call or In3ocation. #acro &xpansion( The &ro1ram "ith macro i u&&lied to the macro &roce or. Each macro in3ocation tatement "ill /e e,&anded into the tatement that !orm the /ody o! the macro, "ith the ar1ument !rom the macro in3ocation u/ tituted !or the &arameter in the macro &rototy&e. 8urin1 the e,&an ion, the macro de!inition tatement are deleted ince they are no lon1er needed. The ar1ument and the &arameter are a ociated "ith one another accordin1 to their &o ition . The !ir t ar1ument in the macro matche "ith the !ir t &arameter in the macro &rototy&e and o on. %!ter macro processing the e,&anded !ile can /ecome the in&ut !or the Assembler. The #acro )nvocation tatement i con idered a comment and the tatement 1enerated !rom e,&an ion i treated e,actly a thou1h they had /een "ritten directly /y the &ro1rammer. The di!!erence /et"een #acros and "ubroutines i that the tatement !rom the /ody o! the $acro i e,&anded the num/er o! time the macro in3ocation i encountered, "herea the tatement o! the u/routine a&&ear only once no matter ho" many time the u/routine i called. $acro in truction "ill /e "ritten o that the /ody o! the macro contain no la/el . Bro/lem o! the la/el in the /ody o! macroF

=6

o I! the ame macro i e,&anded multi&le time at di!!erent &lace in the &ro1ram M o There "ill /e duplicate labels, "hich "ill /e treated a error /y the a em/ler. Solution F o 8o not u e la/el in the /ody o! macro. o E,&licitly u e BC+relati3e addre in1 in tead. E,, in -8A>99 and 7-A>99 macro , o @EH OE11 o @LT O+1= It i incon3enient and error+&rone.

The !ollo"in1 &ro1ram ho" the conce&t o! $acro In3ocation and $acro E,&an ion.

=;

F % 492

49192 M"!$o <$o!e&&o$ A'%o$ #.+ "nd 8"#" S#$(!#($e; 8e i1n can /e done a t"o+&a a em/ler. or a one+&a macro. In ca e o! t"o+&a

T"o+&a macro &roce or Kou may de i1n a t"o+&a macro &roce or o Ba 1F Broce all macro de!inition o Ba 2F E,&and all macro in3ocation tatement Jo"e3er, one+&a may /e enou1h o Aecau e all macro "ould ha3e to /e de!ined durin1 the !ir t &a /e!ore any macro in3ocation "ere e,&anded. The de!inition o! a macro mu t a&&ear /e!ore any tatement that in3o2e that macro. $oreo3er, the /ody o! one macro can contain de!inition o! the other macro Con ider the e,am&le o! a $acro de!inin1 another $acro. In the e,am&le /elo", the /ody o! the !ir t $acro )$%C-OS* contain tatement that de!ine -8A>99, 7-A>99 and other macro in truction !or SIC machine. The /ody o! the econd $acro )$%C-O(* de!ine the e ame macro !or SIC'(E machine. % &ro&er in3ocation "ould ma2e the ame &ro1ram to &er!orm macro in3ocation to run on either SIC or SIC'(Emachine. =<

$%C-OS !or SIC machine

F % 493-"0

$%C-O( !or SIC'(E $achine

F % 493-40

% &ro1ram that i to /e run on SIC y tem could in3o2e $%C-OS "herea a &ro1ram to /e run on SIC'(E can in3o2e $%C-O(. Jo"e3er, de!inin1 $%C-OS or $%C-O( doe not de!ine -8A>99 and 7-A>99. The e de!inition are &roce ed only "hen an in3ocation o! $%C-OS or $%C-O( i e,&anded.

=C

One-<"&& M"!$o <$o!e&&o$; % one+&a macro &roce or that alternate /et"een macro definition and macro expansion in a recur i3e "ay i a/le to handle recur i3e macro de!inition. -e triction o The de!inition o! a macro mu t a&&ear in the ource &ro1ram /e!ore any tatement that in3o2e that macro. o Thi re triction doe not create any real incon3enience. The de i1n con idered i !or one+&a a em/ler. The data tructure re6uired areF 8E9T%A )8e!inition Ta/le* o Store the macro de!inition includin1 macro prototype and macro body o Comment line are omitted. o -e!erence to the macro in truction &arameter are con3erted to a &o itional notation !or e!!iciency in u/ titutin1 ar1ument . N%$T%A )Name Ta/le* o Store macro name o Ser3e a an inde, to 8E9T%A Bointer to the /e1innin1 and the end o! the macro de!inition )8E9T%A* %-IT%A )%r1ument Ta/le* o Store the ar1ument accordin1 to their &o ition in the ar1ument li t. o % the macro i e,&anded the ar1ument !rom the %r1ument ta/le are u/ tituted !or the corre &ondin1 &arameter in the macro /ody. o The !i1ure /elo" ho" the di!!erent data tructure de cri/ed and their relation hi&.

50

F % 494

The a/o3e !i1ure ho" the &ortion o! the content o! the ta/le durin1 the &roce in1 o! the &ro1ram in &a1e no. :. In !i1 =.=)a* de!inition o! -8A>99 i tored in 8E9T%A, "ith an entry in N%$T%A ha3in1 the &ointer to the /e1innin1 and the end o! the de!inition. The ar1ument re!erred /y the in truction are denoted /y the their &o itional notation . 9or e,am&le, T8 D(4\14 The a/o3e in truction i to te t the a3aila/ility o! the de3ice "ho e num/er i 1i3en /y the &arameter #IN8EG. In the in truction thi i re&laced /y it &o itional 3alue\ 1. 9i1ure =.=)/* ho" the %-T%A a it "ould a&&ear durin1 e,&an ion o! the -8A>99 tatement a 1i3en /elo"F CLOOB -8A>99 91, A>99E-, LENITJ 9or the in3ocation o! the macro -8A>99, the !ir t &arameter i 91 )in&ut de3ice code*, econd i A>99E- )indicatin1 the addre "here the character read are tored*, and the third i LENITJ )"hich indicate total len1th o! the record to /e read*. 7hen the \n notation i encountered in a line !ro 8E9T%A, a im&le inde,in1 o&eration u&&lie the &ro&er ar1ument !rom %-IT%A. The al1orithm o! the $acro &roce or i 1i3en /elo". Thi ha the &rocedure 8E9INE to ma2e the entry o! macro name in the N%$T%A, #acro Prototype in 8E9T%A. E(B%N8 i called to et u& the ar1ument 3alue in %-IT%A and e,&and a #acro )nvocation tatement. Brocedure IETLINE i called to 1et the ne,t line to /e &roce ed either !rom the 8E9T%A or !rom the !ile it el!. 7hen a macro de!inition i encountered it i entered in the 8E9T%A. The normal a&&roach i to continue enterin1 till $EN8 i encountered. I! there i a &ro1ram ha3in1 a $acro de!ined "ithin another $acro. 7hile de!inin1 in the 8E9T%A the 3ery !ir t $EN8 i ta2en a the end o! the $acro de!inition. Thi doe not com&lete the de!inition a there i another outer $acro "hich com&lete the di!intion o! $acro a a "hole. There!ore the 8E9INE &rocedure 2ee& a counter 3aria/le LEGEL. E3ery time a $acro directi3e i encountered thi counter i incremented /y 1. The moment the innermo t $acro end indicated /y the directi3e $EN8 it tart decrea in1 the 3alue o! the counter 3aria/le /y one. The la t $EN8 hould ma2e the counter 3alue et to 5ero. So "hen LEGEL /ecome 5ero, the $EN8 corre &ond to the ori1inal $%C-O directi3e. $o t macro &roce or allo" thr de!inition o! the commonly u ed in truction to a&&ear in a tandard y tem li/rary, rather than in the ource &ro1ram. Thi ma2e the u e o! macro con3enient? de!inition are retrie3ed !rom the li/rary a they are needed durin1 macro &roce in1.

51

F % 491

52

A'%o$ #.+&

5:

F % 496

49193

Co+,"$ &on o2 M"!$o <$o!e&&o$ 8e& %n *ne-pass algorit$m o E3ery macro mu t /e de!ined /e!ore it i called o One+&a &roce or can alternate /et"een macro de!inition and macro e,&an ion o Ne ted macro de!inition are allo"ed /ut ne ted call are not allo"ed. +wo-pass algorit$m o Ba 1F -eco1ni5e macro de!inition o Ba 2F -eco1ni5e macro call o Ne ted macro de!inition are not allo"ed

5=

491 M"!. ne- nde,enden# M"!$o-<$o!e&&o$ Fe"#($e&9 The de i1n o! macro &roce or doe n4t de&end on the architecture o! the machine. 7e "ill /e tudyin1 ome e,tended !eature !or thi macro &roce or. The e !eature areF Concatenation o! $acro Barameter Ieneration o! uni6ue la/el Conditional $acro E,&an ion [ey"ord $acro Barameter 49291 Con!"#en"# on o2 (n C(e '"4e'&; $o t macro &roce or allo" &arameter to /e concatenated "ith other character trin1 . Su&&o e that a &ro1ram contain a erie o! 3aria/le named /y the ym/ol (%1, (%2, (%:,M, another erie o! 3aria/le named (A1, (A2, (A:,M, etc. I! imilar &roce in1 i to /e &er!ormed on each erie o! la/el , the &ro1rammer mi1ht &ut thi a a macro in truction. The &arameter to uch a macro in truction could &eci!y the erie o! 3aria/le to /e o&erated on )%, A, etc.*. The macro &roce or "ould u e thi &arameter to con truct the ym/ol re6uired in the macro e,&an ion )(%1, (/1, etc.*. Su&&o e that the &arameter to uch a macro in truction i named #I8. The /ody o! the macro de!inition mi1ht contain a tatement li2e L8% (#I81

F % 49B

# i the tartin1 character o! the macro in truction? /ut the end o! the &arameter i not mar2ed. So in the ca e o! #I81, the macro &roce or could deduce the meanin1 that "a intended. I! the macro de!inition contain contain #I8 and #I81 a &arameter , the ituation "ould /e una3oida/ly am/i1uou . $o t o! the macro &roce or deal "ith thi &ro/lem /y &ro3idin1 a &ecial concatenation o&erator. In the SIC macro lan1ua1e, thi o&erator i the character . Thu the tatement L8% (#I81 can /e "ritten a L8% (#I8

55

F % 497

The a/o3e !i1ure ho" a macro de!inition that u e the concatenation o&erator a &re3iou ly de cri/ed. The tatement S>$ % and S>$ AET% ho" the in3ocation tatement and the corre &ondin1 macro e,&an ion. 49292 Gene$"# on o2 Un C(e L"4e'&

% di cu ed it i not &o i/le to u e la/el !or the in truction in the macro de!inition, ince e3ery e,&an ion o! macro "ould include the la/el re&eatedly "hich i not allo"ed /y the a em/ler. Thi in turn !orce u to u e relati3e addre in1 in the 0um& in truction . In tead "e can u e the techni6ue o! 1eneratin1 uni6ue la/el !or e3ery macro in3ocation and e,&an ion. 8urin1 macro e,&an ion each ] "ill /e re&laced "ith ]((, "here ,, i a t"o+character al&hanumeric counter o! the num/er o! macro in truction e,&an ion. 9or e,am&le, (( D %%, %A, %CM Thi allo" 12C6 macro e,&an ion in a in1le &ro1ram.

56

The !ollo"in1 &ro1ram ho" the macro de!inition "ith la/el to the in truction.

The !ollo"in1 !i1ure ho" the macro in3ocation and e,&an ion !ir t time.

I! the macro i in3o2ed econd time the la/el may /e e,&anded a ]%ALOOB ]%AE(IT.

5;

49293 Cond # on"' M"!$o E*,"n& on There are a&&lication o! macro &roce or that are not related to a em/ler or a em/ler &ro1rammin1. Conditional a em/ly de&end on &arameter &ro3ide $%C-O #CON8 MM.. I9 )#CON8 NE N4* &art I ELSE &art II EN8I9 MMM EN8$ Bart I i e,&anded i! condition &art i true, other"i e &art II i e,&anded. Com&are o&erator F NE, EH, LE, IT. #acro-+ime ,ariables( $acro+time 3aria/le )o!ten called a SET Sym/ol* can /e u ed to tore "or2in1 3alue durin1 the macro e,&an ion. %ny ym/ol that /e1in "ith ym/ol # and not a macro in truction &arameter i con idered a macro-time variable. %ll uch 3aria/le are initiali5ed to 5ero.

F % 49D-"0

5<

9i1ure =.5)a* 1i3e the de!inition o! the macro -8A>99 "ith the &arameter #IN8EG, #A>9%8-, #-ECLTJ, #EO-, #$%(LTJ. %ccordin1 to the a/o3e &ro1ram i! #EO- ha any 3alue, then #EO-C[ i et to 1 /y u in1 the directi3e SET, other"i e it retain it de!ault 3alue 0.

F % 49D-40 U&e o2 M"!$o-T +e E"$ "4'e 3 #. EOF 4e n% NOT NULL

F % 49D-!0 U&e o2 M"!$o-T +e !ond # on"' &#"#e+en# 3 #. EOF 4e n% NULL

5C

F % 49D-d0 U&e o2 T +e-/"$ "4'e 3 #. EOF NOT NULL "nd MAALENGTH 4e n% NULL

The a/o3e &ro1ram ho" the e,&an ion o! $acro in3ocation tatement "ith di!!erent 3alue !or the time 3aria/le . In !i1ure =.C)/* the #EO9 3alue i N>LL. 7hen the macro in3ocation i done, I9 tatement i e,ecuted, i! it i true EO-C[ i et to 1, other"i e normal e,ecution o! the other &art o! the &ro1ram i continued. The macro &roce or mu t maintain a ym/ol ta/le that contain the 3alue o! all macro+ time 3aria/le u ed. Entrie in thi ta/le are modi!ied "hen SET tatement are &roce ed. The ta/le i u ed to loo2 u& the current 3alue o! the macro+time 3aria/le "hene3er it i re6uired. 7hen an I9 tatement i encountered durin1 the e,&an ion o! a macro, the &eci!ied Aoolean e,&re ion i e3aluated. I2 #.e /"'(e o2 #. & e*,$e&& on TRUE) The macro &roce or continue to &roce line !rom the 8E9T%A until it encounter the ELSE or EN8I9 tatement. I! an ELSE i !ound, macro &roce or 2i& line in 8E9T%A until the ne,t EN8I9. Once it reache EN8I9, it re ume e,&andin1 the macro in the u ual "ay. I2 #.e /"'(e o2 #.e e*,$e&& on & FALSE) The macro &roce or 2i& ahead in 8E9T%A until it encounter ne,t ELSE or EN8I9 tatement. The macro &roce or then re ume normal macro e,&an ion. The macro-time I9+ELSE+EN8I9 tructure &ro3ide a mechani m !or either 1eneratin1)once* or 2i&&in1 elected tatement in the macro /ody. There i another 60

con truct 7JILE tatement "hich &eci!ie that the !ollo"in1 line until the ne,t EN87 tatement, are to /e 1enerated re&eatedly a lon1 a a &articular condition i true. The te tin1 o! thi condition, and the loo&in1 are done durin1 the macro i under e,&an ion. The e,am&le ho"n /elo" ho" the u a1e o! $acro+Time Loo&in1 tatement. WHILE-EN8W &#$(!#($e 7hen an 7JILE tatement i encountered durin1 the e,&an ion o! a macro, the &eci!ied Aoolean e,&re ion i e3aluated. T->E o The macro &roce or continue to &roce line !rom 8E9T%A until it encounter the ne,t EN87 tatement. o 7hen EN87 i encountered, the macro &roce or return to the &recedin1 7JILE, re+e3aluate the Aoolean e,&re ion, and ta2e action /a ed on the ne" 3alue. 9%LSE o The macro &roce or 2i& ahead in 8E9T%A until it !ind the ne,t EN87 tatement and then re ume normal macro e,&an ion.

61

You might also like