I\'m trying to learn the Assembly language MIPS using the MARS simulator. The pr
ID: 3666383 • Letter: I
Question
I'm trying to learn the Assembly language MIPS using the MARS simulator. The problem I'm currently working through is: Allocate space for an array A[0..15] in the data section of your assembly code. Each array element is a 32-bit word. Write a program that will do the following two things: (1) It will first fill the nth element of the array with the value of 2^n (calculate A[n] using the formula A[n]:=A[n-1]+A[n-l]). (2) It will then ask you to enter any integer value of n between 0 and 15, and out put the value of A[n].Explanation / Answer
Runtime exception at 0x00400034: address out of range 0x00000003 .data fout: .asciiz "testout.txt" # filename for output buffer: .asciiz "The quick brown fox jumps over the lazy dog." .text li $t0, 1 li $t1, 2 add $t3, $t0, $t1 move $t0, $t3 ############################################################### # Open (for writing) a file that does not exist li $v0, 13 # system call for open file la $a0, fout # output file name li $a1, 1 # Open for writing (flags are 0: read, 1: write) li $a2, 0 # mode is ignored syscall # open a file (file descriptor returned in $v0) move $s6, $v0 # save the file descriptor ############################################################### # Write to file just opened li $v0, 15 # system call for write to file move $a0, $s6 # file descriptor lb $a1, ($t0) # address of buffer from which to write li $a2, 44 # hardcoded buffer length syscall # write to file ############################################################### # Close the file li $v0, 16 # system call for close file move $a0, $s6 # file descriptor to close syscall # close file ############################################################### ItoA: ddi $t0, $zero, 10 div $a0, $t0 # $a0/10 mflo $a1 # $a1 = quotient addi $a1, $a1, 0x30 # convert to ASCII mfhi $t0 # $t0 = remainder addi $t0, $t0, 0x30 # convert to ASCII sll $t0, $t0, 8 or $a3, $a1, $t0 jr $ra EndItoA: .data fout: .asciiz "testout.txt" # filename for output buffer: .resb 33 # set aside a space of 32 characters .text li $t0, 1 li $t1, 2 add $t3, $t0, $t1 la $t0, buffer sb $t3, ($t0) ############################################################### # Open (for writing) a file that does not exist li $v0, 13 # system call for open file la $a0, fout # output file name li $a1, 1 # Open for writing (flags are 0: read, 1: write) li $a2, 0 # mode is ignored syscall # open a file (file descriptor returned in $v0) move $s6, $v0 # save the file descriptor ############################################################### # Write to file just opened li $v0, 15 # system call for write to file move $a0, $s6 # file descriptor move $a1, $t0 # address of buffer from which to write li $a2, 44 # hardcoded buffer length syscall # write to file ############################################################### # Close the file li $v0, 16 # system call for close file move $a0, $s6 # file descriptor to close syscall # close file ###############################################################