#----------------------------------------------------------------------------# # example8.a # # Joe Schmoe # Purpose: check out shifts # Input: none # Output: result of left and right shifts #----------------------------------------------------------------------------# .data outstr: .asciiz "Values are: " hello: .asciiz "Here we go a'shifting\n" endl: .asciiz "\n" #----------------------------------------------------------------------------# .text .globl main main: li $t0, 1 # val li $t1, 5 # num li $t2, 1 # const 1 li $v0, 4 la $a0, hello syscall sll $t3, $t1, 2 # shift left by 2 bits (= multiplying by 4) li $v0, 1 move $a0, $t3 syscall # prints out 20 move $t3, $a0 # move value back li $v0, 4 la $a0, endl syscall srl $t3, $t3, 1 # shift right by 1 bit (= division by 2) li $v0, 1 move $a0, $t3 syscall # prints out 10 li $v0, 4 la $a0, endl syscall done: li $v0, 10 syscall #----------------------------------------------------------------------------#