# memory.s
# A simple SPIM program to illustrate memory loads and stores,
#  and memory-to-memory copying
#
# Please load this program into SPIM and single-step through it,
#  while watching the register, text and data windows 
#
# Data segment
#
.data
intdec: .word 12345
inthex: .word 0x12345
temp:   .word
newline: .byte '\n'  # A newline character (ASCII 10 = 0x0a)
#
# Text (instruction) segment
#
.text
__start:
lw $v0, intdec  # This loads the value stored at location intdec 
                #  (namely, 12345) into register $v0
sw $v0, temp    # This stores the value in register $v0
                #  to the location labeled temp, which now contains
                #  the decimal integer 12345 
                #  The lw-sw sequence simply copies data from one
                #  memory location to another (memory-to-memory copy)
lw $v0, inthex  # This loads the value stored at location inthex 
                #  (namely, 0x12345) into register $v0
sw $v0, temp    # This stores the value in register $v0
                #  to the location labeled temp, which now contains
                #  the value 0x12345
lb $v0, newline # This loads the byte labeled newline into register $v0
                #  The byte is right-justified and sign-extended
la $a0, intdec  # This loads the address of location intdec 
                #  into register $a0
sw $a0, temp    # This stores the value in register $a0
                #  to the location labeled temp, which now contains
                #  a pointer to intdec
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?

