所以问题是我要取两个数组,并用16位数字和符号以 base 10 和 base 4为单位打印出现在两个数组中的数字。 级联订单。
问题是我不知道如何将其转换为4并以16位数字和一个符号(如果为负,则为-
来打印)。
这是我现在设法做到的:
find_eq:
fori:
ble $t1,0,print4 #branch to print 4 when done printing in decimal
addi $t1,$t1,-1 #i--
add $a1,$a1,-4 #next number in array1
addi $t2,$t2,10 #j=10 again
add $a2,$a2,40 #start of the array 2
forj:
addi $sp,$sp,-64 #add 16 words places in the stack
ble $t2,0,fori #if t2 ==0 branch to fori
lw $t3,($a1) #t3 = array1[i]
lw $t4,($a2) #t4 = array2[j]
addi $t2,$t2,-1 #j--
add $a2,$a2,-4 #next number in array2
bne $t3,$t4,forj #if array1[i] != array2[j] branch to forj
beq $a3,4,base4 #if the wanted base if 4 (wanted base kept in $a3) , branch to base4
li $v0,1 #print number
add $a0,$t3,$zero
syscall
li $v0,4 #print comma
la $a0,comma
syscall
beq $t2,0,fori #if j ==0 return to fori
j forj #return to forj
base4:
ble $sp,0,printem #if the stack is on top , print number
abso: bltz $t3,makeAbs #if the number is negative branch to makeAbs
div $t3,$t3,4 #divide number by 4
mfhi $t8 #store the reminder of the division in t8
sw $t8,($sp) #store the reminder in the stack
add $sp,$sp,4 #add to the stack 4 (in order to go to the next cell in the stack)
j base4 #jump back to base4
printem:
ble $t5,0,forj #if t5 (started at 16) is 0 , go to forj
lw $t3,($sp) #load to t3 the current word in the stack
add $sp,$sp,-4 #go to next cell in stack
addi $t5,$t5,-1 #t5 --
li $v0,1 #print number
add $a0,$t3,$zero
syscall
j printem #back to print the next number
makeAbs:
abs $t3,$t3 #make the number positive
li $v0,4 #printing minus sign
la $a0,minus
syscall
j abso #back to abso label
因此,如果给定的数组为:
1,2,3,4,5,6,7,8,9,10
和
2,4,6,8,10,12,14,16,18,20
输出应为:
10,8,6,4,2,
以十进制表示
和
0000000000000022,0000000000000020,0000000000000012,0000000000000010,0000000000000002
(以4为底)
如果数字为负,则相同,但是16位数字前有-
。
希望有人可以在这里为我提供帮助,我真的不知道该如何解决:(
谢谢!