给出的具体说明:
在 base-32 中打印来自 Prgm1 的答案。不要使用 div/mul/rem 或类似的。尽可能只使用 t 寄存器。
笔记:
基数 32 我的意思是像十六进制(基数 16),但有 5 位组而不是 4 位,所以我们使用最多 V 的字母。首先考虑如何执行系统调用 1、35 或 34。
我能够完成这项工作的第一部分,但我不知道如何以 32 为基数或 5 个为一组获得我的输出。任何帮助将不胜感激。
.data
prompt: .asciiz "Enter a number: "
prompt2: .asciiz "Enter another number: "
.text
# Prompt the user to enter number.
li $v0, 4
la $a0, prompt # Print prompt
syscall
# Get the user's number
li $v0, 5
syscall
# Store the result in $t2
move $s0, $v0 # Move users number from $v0 to $t2
# Prompt the user to enter number.
li $v0, 4
la $a0, prompt2 # Print prompt
syscall
# Get the user's number
li $v0, 5
syscall
# Store the result in $t3
move $s1, $v0 # Move users number from $v0 to $t3
# Store the result in $s0
li $s2, 0
li $s3, 1 # Mask for extracting bit
li $t1, 0 # Counter
Loop:
# If $t1 equals 31, branch the number of instructions by the offset
beq $t1, 31, exit
and $t0, $s1, $s3 # ands $s1 and $s3 and stores in $t0
sll $s3, $s3, 1 # Multiplies value in $s3 by 2^1 and stores in $s3
# If $t0 equals 0, branch the number of instructions by the offset
beq $t0, 0, Loop2
add $s2, $s2, $s0 # Stores the sum of $s0 and $s2 in $s2
Loop2:
# Multiplies value in $s0 by 2^1 and stores in $s0
sll $s0, $s0, 1
addi $t1, $t1, 1 #adds 1 to $t1 and stores in $t1
j Loop
exit:
# Print or show the number
li $v0, 1
add $a0, $s2, $zero # Move the number to the argument
syscall
#Exit
li $v0, 10
syscall