I need to print the cells of an array, I have an array which contains the word "HELLO_WORLD", I manage to print an index by its own but I can't manage to print all the cells one by one, here is the code :
loop:
la $t0, hexdigits # address of the first element
lb $a0, 5($t0) # hexdigits[10] (which is 'A')
li $v0, 11 #system call service
syscall
addi $a0, $a0, 2
li $v0, 11 # I will assume syscall 11 is printchar (most simulators support it)
syscall # issue a system call
j end
Is there anyway to use the instruction lb $a0, $s0($t0) with a register that I can increment anytime I want? and not just a number?
To access any individual element of
array
, you can use it as:If array is a byte array, like:
to access the ith element:
because each element is of 1 byte, so to access ith byte, access the address that is
i
offset to address ofarray
.You can also access it as:
If array is a word array, like:
to access the ith element:
because each element if of 4 byte and to access ith element, you will have to move
i*4
byte from the starting address ofarray
.There are also some other ways of accessing it:
Example1:
Example: Prints the byte array: