# File: hmwk3-1.asm # Written by: Larry Merkle, Dec. 10, 2002 # # Modified by: Archana Chidanandan, Dec. 11, 2003 # a. Name changed from "Move" to "MoveObject" # # Modified by: Archana Chidanandan, Sept. 9, 2004 # a. Upadated descriptions of the procedures. # # Given a current position component and a velocity component, the MIPS procedure # MoveObject 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: The procedure adheres STRICTLY to the MIPS register usage conventions. # ############################################################################### # # # # Register usage in MoveObject: # # $a0 - Position component # $a1 - Velocity component # $v0 - Updated position component # .text # Text section of the program (as opposed to data). main: #------------------------------------------------------------------------------ # Initialize the x and y positions and velocities of the "ball". # Call MoveBall repeatedly (infinite loop) to update the x and y # positions of the "ball". #------------------------------------------------------------------------------ # # Insert your code here. # MoveBall: #------------------------------------------------------------------------------ # Call MoveObject twice. First, to update the x position of the "ball". # Second, to update the y position of the "ball". #------------------------------------------------------------------------------ # # Insert your code here. # MoveObject: # Note: You may not modify this procedure. #--------------------------------------------------------------------------------- # # 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. # #---------------------------------------------------------------------------------- add $t0, $a0, $0 # position component add $t1, $a1, $0 # velocity component add $t0, $t0, $t1 # update component ignoring walls # i.e. add the velocity to the position 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