#--------------------------------- # Lab 5 Exercise 2: Pixel Conversion # # Name: # Onyen: # # -------------------------------- # Below is the expected output. # # Converting pixels to grayscale: # 0 # 1 # 2 # 34 # 5 # 67 # 89 # Finished. # -- program is finished running -- #--------------------------------- .data startString: .asciiz "Converting pixels to grayscale:\n" finishString: .asciiz "Finished." newline: .asciiz "\n" pixels: .word 0x00010000, 0x010101, 0x6, 0x3333, 0x030c, 0x700853, 0x294999, -1 .text main: li $v0, 4 #System call code for print_str la $a0, startString #address of string to print syscall #print the string li $t3, 3 la $t0, pixels loop: lw $t1, 0($t0) bltz $t1, exit andi $t4, $t1, 0x00ff srl $t1, $t1, 8 andi $t5, $t1, 0x00ff srl $t1, $t1, 8 andi $t6, $t1, 0x00ff #unnecessary, but to be safe add $t7, $t4, $t5 add $t7, $t7, $t6 div $t7, $t3 #quotient is in "lo" li $v0, 1 #System call code for print_int mflo $a0 #address of string to print syscall #print the string li $v0, 4 #System call code for print_str la $a0, newline #address of string to print syscall #print the string addi $t0, $t0, 4 j loop exit: li $v0, 4 #System call code for print_str la $a0, finishString #address of string to print syscall #print the string li $v0, 10 #System call code for exit syscall #exit the program