#********************************************************************** # CS 232: Computer Architecture I # # Written: 3/9/97, Rimli Sengupta # Modified: 8/12/00, JP Mellor # # This file contains procedure: # -- main # # The program prompts the user for an integer i and prints # out the i-th element of an array in memory # #********************************************************************** .globl main .globl V .data V: .word 20, 56, -90, 37, -2, 30, 10, -66, -4, 18 prompt: .asciiz "Enter an integer (0-9) -> " newline: .asciiz "\n" #********************************************************************** .text main: #---------------------------------------------------------------------- # Prompt for input #---------------------------------------------------------------------- li $v0, 4 # use system call for printing a string la $a0, prompt # load address of string to print in $a0 syscall #---------------------------------------------------------------------- # Read input i #---------------------------------------------------------------------- li $v0, 5 # use system call for reading syscall # an integer i. move $t0, $v0 # Copy integer i into $t0. #---------------------------------------------------------------------- # Access and print V(i) #---------------------------------------------------------------------- sll $t0, $t0, 2 # $t0 := 4 * $t0 lw $a0, V($t0) # read V(i) into $a0 li $v0, 1 # use system call to syscall # print the integer V(i) la $a0, newline # print a new line li $v0, 4 syscall # --------------------------------------------------------------------- # Exit # --------------------------------------------------------------------- li $v0, 10 syscall