I'm converting C code to Mips code
The C code is
int main(void) {
int i;
int data [10] = { 10, -2, 5, 22, 99, 0, -5, 8, 30, 7};
for(i=0; i<10; i++){
printf("%d\n", data[i]);
}
return 0;
}
my Mips code is
.data
data: .space 10
enter: .asciiz "\n"
.text
.globl main
main:
addi $s0, $zero, 10
add $t0, $zero, $zero
sw $s0, data($t0)
addi $s0, $zero, -2
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 5
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 22
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 99
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 0
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, -5
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 8
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 30
addi $t0, $t0, 4
sw $s0, data($t0)
addi $s0, $zero, 7
addi $t0, $t0, 4
sw $s0, data($t0)
addi $t0, $zero, 0
Loop: slti $t1, $t0, 10
beq $t1, $zero, Exit
mul $t2, $t0, 4
li $v0, 1
lw $a0, data($t2)
syscall
li $v0, 4
la $a0, enter
syscall
addi $t0, $t0, 1
j Loop
Exit:
end:
li $v0, 10
syscall
s1 is for saving a value. t0 is for index t1 is a flag for slt t1 multiply 4 is t2
you should just focus on
li $v0, 4
la $a0, enter
syscall
it prints 10-2522990-58307
dddddddddddddddddddddddddddddddddddasdfasdfasdfasdfasdfasdfasdf
plz help me dddddddddddddddddddddddddddddddddddddd
You haven't reserved enough memory for your data
array. .space 10
reserves 10 bytes of memory, but you're trying to store 10 words (40 bytes). So you end up overwriting the newline character.
If you change the declaration to data: .space 40
you should get the expected output.