嘿朋友们,我是mips的新手,我试图将链接列表中的数字转换为基数4并打印出来,但我真的不知道该怎么做 我听说过一种将数字除以4并将每个数字的剩余部分推入某种堆栈的方法,但是不确定如何执行该操作或应该使用哪个堆栈
我想将列表中的每个数字打印为以4为底的数字
我很想获得一些帮助或指导,以了解如何操作
到目前为止,这是我的代码(即打印数字的总和以及正数字的总和除以4)
.data
num1: .word -1 , num3
num2: .word 17 , 0
num3: .word 32 , num5
num4: .word -6 , num2
num5: .word 1972 , num4
.globl main
.text
main:
la $t1,num1
li $s0,0 # sum of the linked list
li $s1,0 # sum of divided by 4 and postivie in the list
li $t3,0 # temp remainder for the div by 4
li $t4,4
li $t5,0 # counter how many words we enterted the stack
sumloop:
beqz $t1,exit
lw $t0,0($t1)
add $s0,$s0,$t0 # adding to the sum the value in the current node
lw $t1,4($t1)
### need your help here :)
blez $t0,sumloop # if negative or zero dont add to s1
div $t0,$t4
mfhi $t3
bnez $t3,sumloop # if the value isnt divided by 4 without remainder jump to sumloop
add $s1,$s1,$t0
j sumloop
exit:
move $a0,$s0
li $v0,1
syscall
li $a0,'\n'
li $v0,11
syscall
move $a0,$s1
li $v0,1
syscall