# This file is: testmain.s # It is a simple infinite loop that adds up a list of numbers, # over and over again. # # Assumption: # File "lab5.trap.handler.s" contains your modified # Exception/Interrupt handler, which includes at a minimum: # # 1. A .ktext 0x80000080 segment # 2. A label "__start", defined in the usual way: # .text # .globl __start # 3. A call to global label "main", in the usual way. # # Run with: # spim -file testmain.s # or # cat lab5.trap.handler.s testmain.s > lab5.trap.s # spim -mapped_io -notrap -file lab5.trap.s .text # Added Nov. 22/01 (user space) .globl main main: li $v0, 4 # syscall 4 (print_str) la $a0, greeting syscall startSum: li $t0,0 # Array Index li $t1,0 # Sum sumTop: lw $t2,numbers($t0) add $t1,$t1,$t2 beq $t2,$0,printSum # Stop at zero number addi $t0,$t0,4 # Next ## Delay loop move $t3,$t1 mul $t3,$t3,1000 delayTop: sub $t3,$t3,1 bgtz $t3,delayTop b sumTop # Add next number printSum: li $v0,1 # syscall 1 (print_int) move $a0,$t1 syscall li $v0, 4 # syscall 4 (print_str) la $a0, sumLabel syscall b startSum # Infinite loop #--------------------- # Data Segment #--------------------- .data .align 2 numbers: .word 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 .word 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40 .word 0 greeting: .asciiz "Hello, I like to add up numbers.\n" sumLabel: .asciiz " is the sum I get.\n"