bit-manipulation - 剩下大多数 mips
问题描述
# 1 - Request a number
# 2 - Read the number
# 3 - Display Binary msg
# 4 - Display the number as binary
# 5 - Find the left-most bit (loop)
# 6 - Display the result msg
# 7 - Display the position
.data
prompt: .asciiz "Enter a 16 bit number: "
binaryMsg: .asciiz "\nBinary: "
results: .asciiz "\nThe left most bit is in position(zero based): "
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
move $a1, $v0
li $v0, 4
la $a0, binaryMsg
syscall
jal prtbin
# New Line
li $v0, 11
li $a0, 10
syscall
jal main
prtbin:
add $t0, $zero, $a1 # put our input ($a1) into $t0
add $t1, $zero, $zero # Zero out $t1
addi $t3, $zero, 1 # load 1 as a mask
sll $t3, $t3, 15 # move the mask to appropriate position
addi $t4, $zero, 16 # loop counter
loop:
and $t1, $t0, $t3 # and the input with the mask
beq $t1, $zero, print # Branch to print if its 0
add $t1, $zero, $zero # Zero out $t1
addi $t1, $zero, 1 # Put a 1 in $t1
j print
print:
li $v0, 1
move $a0, $t1
syscall
srl $t3, $t3, 1
addi $t4, $t4, -1
bne $t4, $zero, loop
li $v0, 4
la $a0, results
syscall
li $v0, 10
syscall
我正在构建一个程序,它需要一个 16 位数字将其转换为二进制并获取最左边的位并输出它的那个位置。我有两个问题,一个是我似乎无法在不循环回主程序的情况下使其工作,并且似乎无法获得最左边的位并将其输出到结果中。任何帮助都感激不尽。
更新我想出了如何从循环中获取它,但现在我似乎仍然无法找到如何获取最左边的位并显示它
解决方案
推荐阅读
- arrays - 如何对哈希进行排序并将变量分配给perl中数组中的密钥对?
- c# - 在类型“ImageFileInfo”上找不到属性“ImagePreview”
- c# - 使用c#屏蔽数据表中的整个单列
- javascript - Inject ID into component: Difference between custom component and "primitive" () component?
- python - 从单词中删除数字
- c# - WorkSheet.DeleteColumn 不删除列,只是清除数据
- vba - 如果它们与使用 vba 的条件匹配,则在列中查找最小值和中值
- ios - 禁用 UIAlertController 框架外的触摸以取消
- python - 是否可以在不使用睡眠条件的情况下使 gRPC 服务器保持活动状态?
- java - 其他东西抛出的异常可以取消异步任务吗?