I'm coding MIPS on MARS 4.0.1 and I'm trying to add letter '1' into an array but it doesn't work. Here is my code. Can somebody help me, please :(

.data
time: .space 12

.text
main:
la $a0, time
li $t0, 49
sb $t0, 0($a0)
addi $a0, $a0, 1
sb $zero, 0($a0)
li $v0, 4
syscall

li $v0, 10
syscall

The problem isn't with how you are loading the character into the array, but where the $a0 register is pointing when you go to print it. Remember how you incremented it by one when you went to insert the zero delimiter? Well, it's still pointing at that delimiter. a better solution might be:

.data
time: .space 12

.text
main:
    la $a0, time
    li $t0, 49
    sb $t0, 0($a0)
    addi $t1, $a0, 1
    sb $zero, 0($t1)
    li $v0, 4
    syscall

    li $v0, 10
    syscall

Doing that preserves the value of $a0 for the system call.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.