Hello CS 524 Students, The tests for Control Structures 5b - loops involve 6 files, tlp0, tlp1, tlp2, tlp3, tlp4, tlp5 - all are valid code. Your group results are summarized below (and the actual tests and their output follow) Group Score: kris stewart GMCS 535 Office Hours Mon noon-1:30 /Wed 1-1:30 (if ACM meeting) stewart@rohan.sdsu.edu ----------------------------------------------------------- ----------------------------------------------------------- Finger information for POC of group Login name: masc0830 In real life: Stewart as CS524 student Directory: /home/ma/524.01/masc0830 Shell: /bin/csh Last login Mon Apr 21 12:35 on pts/123 from rohan.sdsu.edu New mail received Wed Mar 26 12:00:08 2008; unread since Wed Feb 13 13:19:01 2008 No Plan. Time Stamp on simple in student account -rwxr-x--- 1 masc0830 192284 Apr 21 12:39 /home/ma/524.01/masc0830/simple* Time Stamp on executable for running tests -rwxr-xr-x 1 stewart 192284 May 6 18:43 simple* masc0830 simple test number tlp0 CS 524 - Phase5 Control Structures / Loops-Tests Tue May 6 18:43:38 PDT 2008 package tlp0 is body i : integer; begin writeln(" tlp0 while i = 4"); i:=4; while i = 4 loop writeln(" top of while "); i := i+1; writeln("bottom of while i= ",i); end loop; end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tlp0 while i = 4 Assign i gets Immediate Value 4 While i equal Immediate Value 4 Loop : NULL Writeln parameters top of while Assign i gets i add Immediate Value 1 Writeln parameters bottom of while i= i End Loop : NULL From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tlp0 is body i : integer; begin writeln( tlp0 while i = 4); i:=4; while i = 4 loop writeln( top of while ); i := i+1; writeln(bottom of while i= ,i); end loop; end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,4 sw $t0,0($s0) # # Generate Loop statement Loop_0: lw $t0,0($s0) seq $t0,$t0,4 beq $t0, 0,Loop_1 # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement lw $t0,0($s0) add $t0,$t0,1 sw $t0,0($s0) # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall li $v0, 1 lw $a0,0($s0) syscall la $a0, S0 li $v0, 4 syscall j Loop_0 Loop_1: # # End Loop # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "bottom of while i= " .data S2: .asciiz " top of while " .data S3: .asciiz " tlp0 while i = 4" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tlp0 while i = 4 top of while bottom of while i= 5 masc0830 simple test number tlp1 CS 524 - Phase5 Control Structures / Loops-Tests Tue May 6 18:43:38 PDT 2008 package tlp1 is body x,y: integer; begin writeln(" tlp1 - named looop and exit "); x := 1; y := 1; while x = 1 loop writeln ("loop1 x = ",x); y := y + 1; myloop: loop -- named loop though name never used writeln("loop2"); y := y + 1; if y = 10 then x := x + 1; end if; exit when y = 11; writeln("loop 2: x =",x," y= ",y); end loop; end loop; end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Old lenght = 6 Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tlp1 - named looop and exit Assign x gets Immediate Value 1 Assign y gets Immediate Value 1 While x equal Immediate Value 1 Loop : NULL Writeln parameters loop1 x = x Assign y gets y add Immediate Value 1 While Immediate Value 1 Loop : myloop Writeln parameters loop2 Assign y gets y add Immediate Value 1 If Bool Expr y equal Immediate Value 10 Then Assign x gets x add Immediate Value 1 End If Exit When: y equal Immediate Value 11 Writeln parameters loop 2: x = x y= y End Loop : myloop End Loop : NULL From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: x Offset: 0 Proc. Level: 0 ID: y Offset: 4 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tlp1 is body x,y: integer; begin writeln( tlp1 - named looop and exit ); x := 1; y := 1; while x = 1 loop writeln (loop1 x = ,x); y := y + 1; myloop: loop -- named loop though name never used writeln(loop2); y := y + 1; if y = 10 then x := x + 1; end if; exit when y = 11; writeln(loop 2: x =,x, y= ,y); end loop; end loop; end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S5 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,1 sw $t0,0($s0) # # Generate Assignment Statement li $t0,1 sw $t0,4($s0) # # Generate Loop statement Loop_0: lw $t0,0($s0) seq $t0,$t0,1 beq $t0, 0,Loop_1 # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall li $v0, 1 lw $a0,0($s0) syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate Loop statement Loop_2: # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate If Statment lw $t0,4($s0) seq $t0,$t0,10 beq $t0, 0,IF1 # # Generate Assignment Statement lw $t0,0($s0) add $t0,$t0,1 sw $t0,0($s0) j IF0 IF1: IF0: # # Generate Exit statement lw $t0,4($s0) seq $t0,$t0,11 bne $t0, 0,Loop_3 # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall li $v0, 1 lw $a0,0($s0) syscall la $a0, S1 li $v0, 4 syscall li $v0, 1 lw $a0,4($s0) syscall la $a0, S0 li $v0, 4 syscall j Loop_2 Loop_3: # # End Loop j Loop_0 Loop_1: # # End Loop # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz " y= " .data S2: .asciiz "loop 2: x =" .data S3: .asciiz "loop2" .data S4: .asciiz "loop1 x = " .data S5: .asciiz " tlp1 - named looop and exit " # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _x: .word 0 # Offset at 0 .data _y: .word 0 # Offset at 4 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tlp1 - named looop and exit loop1 x = 1 loop2 loop 2: x =1 y= 3 loop2 loop 2: x =1 y= 4 loop2 loop 2: x =1 y= 5 loop2 loop 2: x =1 y= 6 loop2 loop 2: x =1 y= 7 loop2 loop 2: x =1 y= 8 loop2 loop 2: x =1 y= 9 loop2 loop 2: x =2 y= 10 loop2 masc0830 simple test number tlp2 CS 524 - Phase5 Control Structures / Loops-Tests Tue May 6 18:43:38 PDT 2008 package tlp2 is body i, j: integer; begin writeln("tlp2- one loop, several exits on name"); j := 0; loopit0: loop writeln("loop1 j = ",j); j := j + 1; exit loopit0 when j=6; writeln(" bottom of loop"); end loop; writeln("Thats finishes tlp2 "); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Old lenght = 7 Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tlp2- one loop, several exits on name Assign j gets Immediate Value 0 While Immediate Value 1 Loop : loopit0 Writeln parameters loop1 j = j Assign j gets j add Immediate Value 1 Exit When: j equal Immediate Value 6 Writeln parameters bottom of loop End Loop : loopit0 Writeln parameters Thats finishes tlp2 From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 ID: j Offset: 4 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tlp2 is body i, j: integer; begin writeln(tlp2- one loop, several exits on name); j := 0; loopit0: loop writeln(loop1 j = ,j); j := j + 1; exit loopit0 when j=6; writeln( bottom of loop); end loop; writeln(Thats finishes tlp2 ); end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,0 sw $t0,4($s0) # # Generate Loop statement Loop_0: # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall li $v0, 1 lw $a0,4($s0) syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate Exit statement lw $t0,4($s0) seq $t0,$t0,6 bne $t0, 0,Loop_1 # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j Loop_0 Loop_1: # # End Loop # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "Thats finishes tlp2 " .data S2: .asciiz " bottom of loop" .data S3: .asciiz "loop1 j = " .data S4: .asciiz "tlp2- one loop, several exits on name" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data _j: .word 0 # Offset at 4 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tlp2- one loop, several exits on name loop1 j = 0 bottom of loop loop1 j = 1 bottom of loop loop1 j = 2 bottom of loop loop1 j = 3 bottom of loop loop1 j = 4 bottom of loop loop1 j = 5 Thats finishes tlp2 masc0830 simple test number tlp3 CS 524 - Phase5 Control Structures / Loops-Tests Tue May 6 18:43:38 PDT 2008 package tlp3 is body i :integer; begin writeln(" tlp3 - how many labels for simple if-then-endif?"); i := 6; if i=6 then writeln("simple - ifthen i=6 - correct"); end if; -- can use only one label if codegen checks for lists if i = 7 then writeln("ifthenelsifelse - then part: i = 7"); elsif i = 9 then writeln("ifthenelsifelse - elsif part: i = 9"); else writeln("else case - correct"); end if; writeln(" bye from tlp3"); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tlp3 - how many labels for simple if-then-endif? Assign i gets Immediate Value 6 If Bool Expr i equal Immediate Value 6 Then Writeln parameters simple - ifthen i=6 - correct End If If Bool Expr i equal Immediate Value 7 Then Writeln parameters ifthenelsifelse - then part: i = 7 ElsIf Bool Expr i equal Immediate Value 9 Then Writeln parameters ifthenelsifelse - elsif part: i = 9 ELSE Writeln parameters else case - correct End If Writeln parameters bye from tlp3 From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tlp3 is body i :integer; begin writeln( tlp3 - how many labels for simple if-then-endif?); i := 6; if i=6 then writeln(simple - ifthen i=6 - correct); end if; -- can use only one label if codegen checks for lists if i = 7 then writeln(ifthenelsifelse - then part: i = 7); elsif i = 9 then writeln(ifthenelsifelse - elsif part: i = 9); else writeln(else case - correct); end if; writeln( bye from tlp3); end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S6 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,6 sw $t0,0($s0) # # Generate If Statment lw $t0,0($s0) seq $t0,$t0,6 beq $t0, 0,IF1 # # Generate Writeln statement la $a0, S5 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF0 IF1: IF0: # # Generate If Statment lw $t0,0($s0) seq $t0,$t0,7 beq $t0, 0,IF3 # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF2 IF3: # # Generate Else If Statment lw $t0,0($s0) seq $t0,$t0,9 beq $t0, 0,IF4 # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF2 IF4: # # Generate Else Statment # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall IF2: # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz " bye from tlp3" .data S2: .asciiz "else case - correct" .data S3: .asciiz "ifthenelsifelse - elsif part: i = 9" .data S4: .asciiz "ifthenelsifelse - then part: i = 7" .data S5: .asciiz "simple - ifthen i=6 - correct" .data S6: .asciiz " tlp3 - how many labels for simple if-then-endif?" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tlp3 - how many labels for simple if-then-endif? simple - ifthen i=6 - correct else case - correct bye from tlp3 masc0830 simple test number tlp4 CS 524 - Phase5 Control Structures / Loops-Tests Tue May 6 18:43:38 PDT 2008 package tlp4 is body i,j :integer; begin writeln("tlp4 "); i:=4; j:= i-2; otter: while i=4 loop writeln("loop1/labelled label otter:"); while j=2 loop writeln("loop2"); if j=4 then writeln("if"); elsif j=5 then writeln("elseif"); else writeln("else"); end if; j := j + 1; exit otter when j=5; writeln("bottom loop 2"); end loop; i := i + 1; exit when i=6; writeln("bottom loop 1, i = ", i); end loop; end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Old lenght = 5 Intermediate Representation - the Abstract Syntax Tree Statements Writeln parameters tlp4 Assign i gets Immediate Value 4 Assign j gets i subtract Immediate Value 2 While i equal Immediate Value 4 Loop : otter Writeln parameters loop1/labelled label otter: While j equal Immediate Value 2 Loop : NULL Writeln parameters loop2 If Bool Expr j equal Immediate Value 4 Then Writeln parameters if ElsIf Bool Expr j equal Immediate Value 5 Then Writeln parameters elseif ELSE Writeln parameters else End If Assign j gets j add Immediate Value 1 Exit When: j equal Immediate Value 5 Writeln parameters bottom loop 2 End Loop : NULL Assign i gets i add Immediate Value 1 Exit When: i equal Immediate Value 6 Writeln parameters bottom loop 1, i = i End Loop : otter From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 ID: j Offset: 4 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tlp4 is body i,j :integer; begin writeln(tlp4 ); i:=4; j:= i-2; otter: while i=4 loop writeln(loop1/labelled label otter:); while j=2 loop writeln(loop2); if j=4 then writeln(if); elsif j=5 then writeln(elseif); else writeln(else); end if; j := j + 1; exit otter when j=5; writeln(bottom loop 2); end loop; i := i + 1; exit when i=6; writeln(bottom loop 1, i = , i); end loop; end; ******** And Source Code File *********** # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # Hi Kris Stewart! This is your favorite compiler team!!!!!! # Patricia, Lance, Meng, and David # # Generate Writeln statement la $a0, S8 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Assignment Statement li $t0,4 sw $t0,0($s0) # # Generate Assignment Statement lw $t0,0($s0) li $t1,2 sub $t0,$t0,$t1 sw $t0,4($s0) # # Generate Loop statement Loop_0: lw $t0,0($s0) seq $t0,$t0,4 beq $t0, 0,Loop_1 # # Generate Writeln statement la $a0, S7 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Loop statement Loop_2: lw $t0,4($s0) seq $t0,$t0,2 beq $t0, 0,Loop_3 # # Generate Writeln statement la $a0, S6 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate If Statment lw $t0,4($s0) seq $t0,$t0,4 beq $t0, 0,IF1 # # Generate Writeln statement la $a0, S5 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF0 IF1: # # Generate Else If Statment lw $t0,4($s0) seq $t0,$t0,5 beq $t0, 0,IF2 # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j IF0 IF2: # # Generate Else Statment # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall IF0: # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate Exit statement lw $t0,4($s0) seq $t0,$t0,5 bne $t0, 0,Loop_3 # # Generate Writeln statement la $a0, S2 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall j Loop_2 Loop_3: # # End Loop # # Generate Assignment Statement lw $t0,0($s0) add $t0,$t0,1 sw $t0,0($s0) # # Generate Exit statement lw $t0,0($s0) seq $t0,$t0,6 bne $t0, 0,Loop_1 # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall li $v0, 1 lw $a0,0($s0) syscall la $a0, S0 li $v0, 4 syscall j Loop_0 Loop_1: # # End Loop # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "bottom loop 1, i = " .data S2: .asciiz "bottom loop 2" .data S3: .asciiz "else" .data S4: .asciiz "elseif" .data S5: .asciiz "if" .data S6: .asciiz "loop2" .data S7: .asciiz "loop1/labelled label otter:" .data S8: .asciiz "tlp4 " # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _i: .word 0 # Offset at 0 .data _j: .word 0 # Offset at 4 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tlp4 loop1/labelled label otter: loop2 else bottom loop 2 bottom loop 1, i = 5 masc0830 simple test number tlp5 CS 524 - Phase5 Control Structures / Loops-Tests Tue May 6 18:43:38 PDT 2008 package tlp5 is body i, j: integer; begin j := 0; writeln (" tlp5 - uses bexpr if tests - both loops and ifs"); L1: loop i := 0; loop if i = 4 then exit; end if; exit L1 when j = 2; i := i + 1; writeln ("Hello World i =", i," j=",j); end loop; j := j + 1; end loop; writeln("Thats all folks"); end; ******** Test your compiler on the code above ******** ******** with AST and symbol table after parse ******* in simple.c Old lenght = 2 Intermediate Representation - the Abstract Syntax Tree Statements Assign j gets Immediate Value 0 Writeln parameters tlp5 - uses bexpr if tests - both loops and ifs While Immediate Value 1 Loop : L1 Assign i gets Immediate Value 0 While Immediate Value 1 Loop : NULL If Bool Expr i equal Immediate Value 4 Then Exit When: Immediate Value 1 End If Exit When: j equal Immediate Value 2 Assign i gets i add Immediate Value 1 Writeln parameters Hello World i = i j= j End Loop : NULL Assign j gets j add Immediate Value 1 End Loop : L1 Writeln parameters Thats all folks From codegen.c - DisplayRegs() marks used registers Register: 0 1 2 3 4 5 6 7 8 9 - - - - - - - - - - Used = x: Variable dump from GenStorage ID: i Offset: 0 Proc. Level: 0 ID: j Offset: 4 Proc. Level: 0 COMPILATION COMPLETE out simple.c ******** Your compiler produces a listing ****** package tlp5 is body i, j: integer; begin j := 0; writeln ( tlp5 - uses bexpr if tests - both loops and ifs); L1: loop i := 0; loop if i = 4 then exit; end if; exit L1 when j = 2; i := i + 1; writeln (Hello World i =, i, j=,j); end loop; j := j + 1; end loop; writeln(Thats all folks); end; ******** And Source Code File *********** update: # Register Usage: # $s0 for global variables # .text .globl main main: la $s0, GVARS # # Start Code # # Generate Assignment Statement li $t0,0 sw $t0,8($s0) # # Generate Writeln statement la $a0, S4 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Generate Loop statement LABEL_0: # # Generate Assignment Statement li $t0,0 sw $t0,4($s0) # # Generate Loop statement LABEL_2: # # Generate If-Then statement lw $t0,4($s0) seq $t0,$t0,4 beq $t0, 0,LABEL_4 # # Generate Exit statement j LABEL_3 # # End If LABEL_4: # # Generate Exit statement lw $t0,8($s0) seq $t0,$t0,2 beq $t0, 1, LABEL_1 # # Generate Assignment Statement lw $t0,4($s0) add $t0,$t0,1 sw $t0,4($s0) # # Generate Writeln statement la $a0, S3 li $v0, 4 syscall li $v0, 1 lw $a0,4($s0) syscall la $a0, S2 li $v0, 4 syscall li $v0, 1 lw $a0,8($s0) syscall la $a0, S0 li $v0, 4 syscall j LABEL_2 LABEL_3: # # End Loop # # Generate Assignment Statement lw $t0,8($s0) add $t0,$t0,1 sw $t0,8($s0) j LABEL_0 LABEL_1: # # End Loop # # Generate Writeln statement la $a0, S1 li $v0, 4 syscall la $a0, S0 li $v0, 4 syscall # # Halt execution li $v0 10 syscall # # Finish up by writing out constants .word 0 CONST: #Constant storage area .data S0: .asciiz "\n" .data S1: .asciiz "Thats all folks" .data S2: .asciiz " j=" .data S3: .asciiz "Hello World i =" .data S4: .asciiz " tlp5 - uses bexpr if tests - both loops and ifs" # # Reserve space for global variables .word 0 GVARS: # space for Global Variables .data _LABEL_1: .word 0 # Offset at 0 .data _i: .word 0 # Offset at 4 .data _j: .word 0 # Offset at 8 .data Temp_Wr: .word 0 #just for alignment of write(exprtree) ******** Run through spim ********* SPIM Version 6.2 of January 11, 1999 Copyright 1990-1998 by James R. Larus (larus@cs.wisc.edu). All Rights Reserved. See the file README for a full copyright notice. Loaded: /opt/spim/bin/trap.handler tlp5 - uses bexpr if tests - both loops and ifs Hello World i =1 j=0 Hello World i =2 j=0 Hello World i =3 j=0 Hello World i =4 j=0 Hello World i =1 j=1 Hello World i =2 j=1 Hello World i =3 j=1 Hello World i =4 j=1 Thats all folks