How can I print an array in Mips64? I've succeeded in printing the array in QtSPIM (MIPS32), with this code:
.data
array: .word 10 20 30 40 50
.text
#load base address of array
la $t1,array
#load number of elements
ld $t2,num
loop:
#load word
lw $a0, ($t1)
#print element
li $v0,1
syscall
#print space
la $a0, space
li $v0,4
syscall
addi $t1,4
#increase counter
addi $t0, 1
bne $t0,$t2,loop
#end
li $v0,10
syscall
I know that MIPS64 has daddi
instead of addi
but I am still missing something.
WinMips64 doesn't appear to use syscall
for terminal output like SPIM / MARS, but rather implements it using memory-mapped I/O (see this example code).
The CONTROL
port is located at address 0x10000
, and the DATA
port at address 0x10008
.
Since you're printing integers you'll be interested mainly in these two output modes:
; Set CONTROL = 1, Set DATA to Unsigned Integer to be output
; Set CONTROL = 2, Set DATA to Signed Integer to be output
For example:
ori $a1,$0,0
lui $a1,1 ; $a1 = 0x10000 (CONTROL)
ori $a2,$a1,8 ; $a2 = 0x10008 (DATA)
lwu $a0,($t1) ; load an unsigned 32-bit value
ori $v0,$0,1 ; 1 == print unsigned integer
sd $a0, ($a2) ; set value to print
sd $v0, ($a1) ; ..and write the command to print it