# 2d.s - Practice with a 2-D array # In the data segment, we have a 6x8 array of integers. # The user will specify which cell to view, by selecting # the desired row and column numbers. .data a: .word 440 498 496 200 502 11 491 501 .word 493 500 535 488 536 492 274 275 .word 316 311 537 403 503 317 171 312 .word 170 522 32 540 143 379 313 533 .word 120 156 144 155 121 186 544 145 .word 51 99 314 419 547 58 107 389 b: .word -5 prompt_row: .asciiz "Enter desired row number (0-5): " prompt_col: .asciiz "Enter desired column number (0-7): " intro_output: .asciiz "Your cell's value is " newline: .asciiz "\n" # Register use # $s0 = base address of array a # $s1 = desired row number (0-5) # $s2 = desired col number (0-7) # $s3 = address of desired cell # $s4 = value in desired cell .text main: la $s0, a # Load the base address. # ------------------------------------------------------------------- # Input # ------------------------------------------------------------------- li $v0, 4 la $a0, prompt_row syscall li $v0, 5 syscall move $s1, $v0 li $v0, 4 la $a0, prompt_col syscall li $v0, 5 syscall move $s2, $v0 # ------------------------------------------------------------------- # Calculate the address of the desired cell, and load its value. # ------------------------------------------------------------------- # ------------------------------------------------------------------- # Output # ------------------------------------------------------------------- li $v0, 4 la $a0, intro_output syscall li $v0, 1 move $a0, $s4 syscall li $v0, 4 la $a0, newline syscall # ------------------------------------------------------------------- # The end # ------------------------------------------------------------------- li $v0, 10 syscall