cat e2 package e2 is body y,z: integer; begin y:=4; z:=1; if z>5 then y:=3; elsif y < 4+z then z:=6; end if; writeln("e2: z = ",z," y = ",y); end; ---------------------------------------------------- cat e2.s # Register usage: # $s0 for global variables # .text .globl main main: la $s0, VARS # # start code # generate assignment statement # li $t0,4 sw $t0,8($s0) # generate assignment statement # li $t0,1 sw $t0,12($s0) # if statement lw $t0,12($s0) li $t1,5 sgt $t0, $t0, $t1 beqz $t0, L0001 # then # generate assignment statement # li $t0,3 sw $t0, 8($s0) b L0000 L0001: # elsif lw $t0, 12($s0) add $t0, $t0, 4 lw $t1, 8($s0) slt $t1, $t1, $t0 beqz $t1, L0002 # then # generate assignment statement # li $t0, 6 sw $t0,12($s0) b L0000 L0002: # end if L0000: # # generate writeln statement # li $v0,4 la $a0,S2 syscall li $v0,1 lw $a0, 12($s0) syscall li $v0,4 la $a0,S1 syscall li $v0,1 lw $a0, 8($s0) syscall la $a0, S0 li $v0, 4 syscall # # halt execution li $v0, 10 syscall # finish up by writing out constants .data .word 0 CONST: # Constant storage area S0: .asciiz "\n" S1: .asciiz " y = " S2: .asciiz "e2: z = " VARS: # space for global variables _y: .word 0 # offset at 8 _z: .word 0 # offset at 12 ; .data Temp_Wr: .word 0 # just for alsignment of write (exprtree) ---------------------------------------------------------- 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 (spim) load "e2.s" (spim) run e2: z = 6 y = 4 (spim) exit