Printing string array in MIPS

Printing string array in MIPS

You need to load the address of the String that you need to print and not the string itself

Printing string array in MIPS

la $t0, names
lw $a0, 0($t0)

instead of this write the below

la  $a0,names

This would print MIPS IS CRAZY

The problem is that syscall 4 requires $a0 to be the address of the string to be displayed, but you are loading garbage to $a0 (either 0 or the contents of the first characters of the string to be displayed).

Dont know why you are aligning the strings either.

Id modify the code to look like this:

.globl main
.data
    hello: .asciiz Hello, the string is:n
    names1:
        .asciiz MIPS
    names2:
        .asciiz IS
    names3:
        .asciiz CRAZY

.text
main:
    la $a0, hello
    li $v0, 4
    syscall

    #print the first member of the names array
    la $a0, names1
    syscall

    #print the second member of the names array
    la $a0, names2
    syscall

    #exit
    li $v0, 10
    syscall

Printing string array in MIPS

li $t0,0

addi $t0,$t0,16 #->porque al usar aling va de 8 en 8 (0,8,16...)

la $a0,names($t0)

Leave a Reply

Your email address will not be published.