# io.s
# A simple SPIM program to illustrate input-output operations
#  using the console
#
# Please load this program into SPIM and single-step through it,
#  while watching the register, text and data windows, and the console
#
# Data segment
#
.data
intdec: .word 12345
inthex: .word 0x12345
temp:   .word
newline: .byte '\n'
#
# Text (instruction) segment
#
.text
__start:
lw $a0, intdec  # This loads the value stored at location intdec 
                #  (namely, 12345) into register $a0
li $v0, 1       # Put the integer 1 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints the contents of $a0 as an integer,
                #  on the console
lb $a0, newline # Load the byte labeled newline into register $a0
li $v0, 11      # Put the integer 11 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints a newline on the console
#
#
lw $a0, inthex  # This loads the value stored at location inthex 
                #  (namely, 0x12345) into register $a0
li $v0, 1       # Put the integer 1 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints the contents of $a0 as an integer,
                #  on the console
lb $a0, newline # Load the byte labeled newline into register $a0
li $v0, 11      # Put the integer 11 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints a newline on the console
#
#
li $v0, 11      # Put the integer 11 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints a newline on the console
ori $v0, $0, 5  # Put the integer 5 into register $v0
syscall         # This reads an integer from the console into 
                #  register $v0
sw $v0, temp    #  and this stores the integer into the location temp
lw $a0, temp    # This loads the value stored at location temp 
                #  (the value entered from the console) into register $a0
li $v0, 1       # Put the integer 1 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints the contents of $a0 as an integer,
                #  on the console
lb $a0, newline # Load the byte labeled newline into register $a0
li $v0, 11      # Put the integer 11 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints a newline on the console
#
#
la $a0, intdec  # This loads the address of location intdec 
                #  into register $a0, which now contains a pointer to 
                #  intdec
li $v0, 1       # Put the integer 1 into register $v0
                #  (note that we do not have to load anything from
                #  memory)
syscall         # This prints the contents of $a0 as an integer,
                #  on the console
#
#
li $v0, 10      # Put the integer 10 into register $v0
syscall         # Return control to the OS 
                #  Read the system call info at the end of spim.inst.txt
                #  if you don't understand this step!!!!
                # A good exam question:  What is the final value
                # stored in the location labeled temp?

