# echo.s: # This file is the skeleton of Problem #2. # It contains three pieces of code: a "main program", starting at "__start", # a procedure "getchar", and a procedure "print". The main program is # already written. It sets up the stack, calls "getchar" to read a # character from the terminal, calls "print" to print the character, # then repeats the whole process over and over again. # Add code from (fixed) buggy.print.s, then run by typing # spim -mapped_io -noexception echo.s .ktext 0x80000180 .globl __start __start: mtc0 $0, $12 # interrupts off lui $29, 0x8000 lui $28, 0x1000 ori $28, 0x8000 addiu $29, $29, -4 loop: jal getchar # Read a character from terminal. sb $2,string # Make a string containing the one character. sb $0,string+1 la $4,string jal print # Print out the input line. j loop .kdata string: .space 20 # Space to create a string containing # the input character. .ktext getchar: # Your mission: fill in the body of this procedure with code # to read a character from the terminal and return it as the # result. jr $31 print: # Copy the code you wrote for problem #1 of the assignment. jr $31