I'm writing a program that takes input for an an array. It then uses a loop to replace the values in another array that has preset values with the values from the array that received input.

When I try to move the values though...well let's say arrayA is the one with the preset values and arrayB is the one that has the inputted values. lw $t3, arrayB($t0) - yields an error, but lw $t3, arrayA($0) works. Is there another command that needs to be used when getting the value from an array that doesn't have preset content?

strOutput: .asciiz "Input: "
arrayA: .word 1,2,3,4
arrayB: .space 16
	.globl main

        li	$v0, 4
	la	$a0, strOutput

        la 	$t1,arrayB
	li	$v0, 8
	la	$a0, 0($t1)

	li	$v0, 8
	la	$a0, 4($t1)

	li	$v0, 8
	la	$a0, 8($t1)

	li	$v0, 8
	la	$a0, 12($t1)

        li 	$t0, 0
	lw 	$t3, arrayB($t0)

I know it's very basic, but I don't know if I'm missing a command or something. Using PCSpim.

And also the number replacement will be done with a loop hence why I'm using arrayB($t0) instead of something else...if that makes any sense at all.

I think you misunderstand the syscall function. It doesn't return a four byte integer. It returns a string!
You also aren't setting $a1 to maximum number of characters to read - 1. The function returns the string with a NULL terminaton.

$a0 = buffer
$a1 = sizeof buffer - 1
$v0 = 8 Function read string.

think you meant $v0 = 5 ? Upon return $v0 contains integer read!

Thank you~

Ahh...I was copy pasting that part from a previous program. We just started assembly. Staring at the code feels kind of like mind screw compared to other stuff like C++.

I see what you're talking about though, I got it to work now. Thanks. :)

This article has been dead for over six months. Start a new discussion instead.