############################################################# # # mystery.mal # CMPE12C Lab 2 (version 2) # # Richard Hughey 10/4/99 # rph@cse.ucsc.edu # # A program that does something slightly mysterious! # # # Registers: The registers labeled $s0...$s8 are the safest to use! # $t0...$t9 are also safe to use if you don't do any # procedure calls. # The register labeled $0 is always zero! # Don't use any other registers until you know what they mean! # # Instructions: You will find in xspimsal that several of the MAL # instructions expand into more than one TAL instruction # when run in the simulator. For example, the I/O # commands first copy appropriate arguments into a couple # of registers, then execute a syscall to get to the OS, # and then move the return value (if present) to the # appropriate register. .text __start: la $s6, greeting puts $s6 la $s6, prompt la $s7, resultprompt la $s8, andprompt li $s5, 0x30 loop: li $s2, 0x20 puts $s6 getc $s0 blt $s0, $s2, finish getc $s1 blt $s1, $s2, finish add $s2, $s0, $s1 sub $s2, $s2, $s5 puts $s7 putc $s2 sub $s3, $s0, $s1 add $s3, $s3, $s5 # version 1 had: add $s3, $s2, $s5 puts $s8 putc $s3 b loop finish: la $s6, endprompt puts $s6 done # A section of data. You can have as many .data segments as you # would like, intermixed with as many .text segments as you would like. .data greeting: .asciiz "Welcome to the CE12C slightly mysterious program!\n" prompt: .asciiz "\n\nPlease type something: " resultprompt: .asciiz "\nThe results are: " andprompt: .asciiz " and " endprompt: .asciiz "\n\nThank you for using this slightly mysterious program!\n"