# File: hmwk2_2.asm # Written by: Larry Merkle, Dec. 10, 2002 # # Modified by: Archana Chidanandan, Dec. 11, 2003 # a. Name changed from "Move" to "MoveObject" # # Given a current position component and a velocity component, this MIPS procedure # calculates a new position component. It assumes periodic boundaries at positions # zero and eleven in both directions, so a ball that goes off of one edge comes back # at the opposite edge. # ############################################################################### # # NOTE: This procedure adheres STRICTLY to the MIPS register usage conventions. # ############################################################################### # # # # Register usage # # $a0 - Position component # $a1 - Velocity component # $v0 - Updated position component # .text # Text section of the program (as opposed to data). MoveObject: add $t0, $a0, $0 # position component add $t1, $a1, $0 # velocity component add $t0, $t0, $t1 # update component ignoring walls cklb: slt $t2, $t0, $0 # set flag if component is less than zero beq $t2, $0, ckub # if flag is clear, ball didn't "cross" wall at zero addi $t0, $t0, 11 # bring ball back in the other side j cklb # a fast ball could "cross" more than once ckub: slti $t2, $t0, 11 # set flag if component is not at least eleven bne $t2, $0, exit # if flag is set, ball didn't "cross" wall at eleven addi $t0, $t0, -11 # bring ball back in the other side j ckub # a fast ball could "cross" more than once exit: move $v0, $t0 # set return value # Wipe out other non-preserved registers for the fun of it li $t0, -1 li $t1, -1 li $t2, -1 li $t3, -1 li $t4, -1 li $t5, -1 li $t6, -1 li $t7, -1 li $t8, -1 li $t9, -1 li $a0, -1 li $a1, -1 li $a2, -1 li $a3, -1 li $v1, -1 jr $ra # return to the calling procedure