13.07.2015 Views

The PowerPC 604 RISC Microprocessor - eisber.net

The PowerPC 604 RISC Microprocessor - eisber.net

The PowerPC 604 RISC Microprocessor - eisber.net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

70 Pascal Implementation: Compiler and Assemble' iterpreter Assembler/Interpreter Listing 71185 if odd(curr) then begin q2;186 q2:- labelvoluo187 end188 else begin euccliu (11,189 ql:• labalvalue190 end;191 If succ--1 then endllst:• true192 else curr: ■ succ193 end;194 end;195 labeltab(xl.at :- defined;196 laboltab(x).val:.. labelvalue;197 end198 end,("update 4 )199200 procedure assemble; forward;201202 procedure generate;("generato segment of code")203 var x: integer; (" label number 4 )2U4again. boolean;/05 begin206 again 1- true;207 while again do208 begin read(prd,ch),(" first character of line")209 case ch of210 'i's readln(prd),211 '1', begin read(prd,x);212 it not eoln(prd) then read(prd,ch);213 if ch-'-' then rcad(prd,labelvalue)214 else labelvaluec- pc;215 update(x); readln(prd);216 end;217'q'l begin again 1- false; readln(prd) end;218 ' 'I begin read(prd,ch); assemble end219 end;220 end221 end; ("generate")21222) procedure assemble; (*translate symbolic code into machine code and store)224 label 1; (*goto 1 for instructions without code generation*)225 var name lalfal b sboolean; r 'real; a 'set of 0..58;226 cl 'char; i,sl,lb,ub :integer;127228 procedure lookup(xc labelrg); ( 4 search in label table*)229 begin case labeltab(x).st of230 entered: begin q labeltab(x).val;2)1 laboltablx1.val pc232 end;233 defined! q: ■ labeltablx1.val234 end("caoe235 end,(*lookup*)236237 procedure lobclaesrch; rt238 var x: labelrg;239 begin whilo (ch0'1') and not eoln(prd) do read(prd,ch);240 read(prd,x); lookup(x)241 ond,("labelaoarch")242243 procedure getname;244 begin word(!) s• ch;245 road(prd,word(2),word(3));246 if not eoln(prd) than read(prd,ch) (*next character*);247 pack(word,l,name)248 end; (*getname")249250 procedure typesymbol;251 var I: integer;252 begin253 if ch 'i' then254 begin255 case ch of256 'a': i 0;257 'r's I 1;258 's's I 2;259 'b's 3;260 'c't 1 1 - 4;261 end;262 op c• coplop1+1;263 end;264 e7.d ("typesymbol 4 )265266 bagin p ;• 0; q U; op 0;267 getname;268 i<strong>net</strong>r(duminst) name;269 while i<strong>net</strong>r(op)Oname do op op+11270 if op duminat then errorl(' illegal instruction ');271272 case op of (* get parameters p,q *)273274 (*equ,neq,geq,grt,leq,les*)275 17,18,19,276 20,21,221 begin case ch of277 'a'l , (*p - 0*)278 'i's p :- 1;279 'r's p :- 2;280 'b's p 3;201 's'i p ;- 4;202 'c's p 6;283 'm's begin p 5;284 read(prd,q)285 and286 end287 end;288289 (*lod,atr*)290 0,21 begin typeeymbol; read(prd,p,q)291 end;292293 4 (*Ida*): read(prd,p,q);294295 12 (*cup*); begin read(prd,p); labelsearch end;296297 11 ("met"): read(prd,p);298299 14 (*ret*): case ch of300 'p'; p;•0;301 'i's p1 ■ 1;302 p:.62;303 'c's304 'b's p1•4;305 'a't p:-5306 end;307308 ("lao,Ixa,mov")309 5,16,551 road(prd,q),310311 ( 4 1do,sro,ind,inc,dec*)312 1,3,9,10,57i begin typesymboll read(prd,q)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!