# MIPS Procedures
# CSC 211
# Original main (and stubs) and macros written by Jerod Weinman

# Because MARS does not heed the .ent directive to specify the entry point,
# we must put the "main" routine first. Otherwise, we'd include main in the
# .globl symbols below and uncomment the following line:
#.ent main

# Ensure the following procedure labels are globally visible
.globl swap, byteflip, extremes, product

.data                             # Global values stored in memory

ramanujan: .word 1729
simerka:   .word  561

.text                             # Start generating instructions

        
# main
# Run the assignment procedure(s).
# (main is not a special name in MARS, but we label it anyway for familiarity.)
# You may edit anything within main for testing, as it will not be autograded
main:
  # Problem 1 (Swap)
  la   $a0, ramanujan             # Load arguments (addresses) into registers
  la   $a1, simerka      
  jal  swap                       # Call the procedure
  la   $t0, ramanujan             # (Re)load addresses into registers, because
  la   $t1, simerka               # argument registers are not preserved
  lw   $s0, 0($t0)                # Dereference pointers into saved registers
  lw   $s1, 0($t1)
        
  # Problem 3 (Extremes)
  li   $a0, 4                     # Load arguments into registers
  li   $a1, 1               
  li   $a2, 3
  li   $a3, 2
  jal  extremes                   # Call the procedure
  move $s2, $v0                   # Copy results into saved registers
  move $s3, $v1
        
  # Exit/Terminate       
  li   $v0, 10                    # Load SYSCALL service number for exit
  syscall                         # Make system call (terminating program)
# END MAIN


# Problem 1
# DOCUMENT YOUR PROCEDURE HERE (and delete this line)
swap:
# ADD YOUR CODE HERE (and delete this line)
  jr   $ra                        # Return to caller
#END swap


# Problem 2
# DOCUMENT YOUR PROCEDURE HERE (and delete this line)
byteflip:
# ADD YOUR CODE HERE (and delete this line)
  jr   $ra                        # Return to caller
#END byteflip


# Problem 3
# DOCUMENT YOUR PROCEDURE HERE (and delete this line)
extremes:
# ADD YOUR CODE HERE (and delete this line)
  jr   $ra                        # Return to caller
#END extremes

        
# Problem 4
# DOCUMENT YOUR PROCEDURE HERE (and delete this line)
product:
# ADD YOUR CODE HERE (and delete this line)
  jr   $ra                        # Return to caller
#END product
