0

I want to make an array of 6 elements , by for loop the user will enter the value of the element each time , then by for loop add each element with 4 and print it .

This is the code it gives me "Go: execution terminated with errors."

.text #Show the Hello Message :D li $v0 , 4 #4 because it is a string , 1 if it is integer message , V0 is function register la $a0 , Message #add the Hello message in the reserved assembler register a0 syscall #execute the V0 --->4 function with a0 parameter #for loop to take the values add $t0,$zero,$zero For : slti $t1,$t0,24 beq $t1,$zero,Exit #Display Prompt message li $v0,4 la $a0, Prompt syscall #Get the iput li $v0,5 #5 for int input syscall #Move the input from the the function to a register move $t2,$v0 add $s0,$zero,$t2 #save value to the array sw $s0,MyArray($t0) addi $t0,$t0,4 j For Exit: # End for loop add $t0,$zero,$zero addi $t4,$zero,4 While: beq $t0,24,Exit2 lw $t6, MyArray($t0) addi $t0,$t0, 4 add $t6,$t6,$t4 add $t6,$t6,$t4 add $t6,$t6,$t4 add $t6,$t6,$t4 li $v0 , 1 move $a0 , $t6 syscall li $v0 , 4 la $a0 , Space syscall j While Exit2: li $v0 , 4 #4 because it is a string , 1 if it is integer message , V0 is function register la $a0 , Message2 #add the End message in the reserved assembler register a0 syscall .data #This for all the data for the program like variables in c++ Message : .asciiz "Hello world !\n" #Display this message on the simulator MyArray : .space 24 Prompt : .asciiz "Enter the value\n " Message2: .asciiz "End world !\n" Space : .asciiz " , " 

1 Answer 1

1

I'm not sure what you're trying to accomplish here. Your code basically adds 16 to every element of the array.

Error you're getting is caused by bad alignment of memory. When you're loading word from memory which is 4 bytes in MIPS32, the address needs to be divisible by 4. To guarantee this in mips your data section you need to add .align 4 before declaring your array.

.data #This for all the data for the program like variables in c++ Message : .asciiz "Hello world !\n" #Display this message on the simulator .align 4 MyArray : .space 24 Prompt : .asciiz "Enter the value\n " Message2: .asciiz "End world !\n" Space : .asciiz " , " 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.