MIPS 十六进制数转二进制
我正在尝试将数字 0x20014924 转换为二进制数。我收到意外的二进制读数:
0000 0001 0011 0001 0110 0111 0100 1100
实际输出0010 0000 0000 0001 0100 1001 0010 0100
预期输出。
任何有关调试或我出错的地方的建议将不胜感激!
.data #start to define user data
myStr: .asciiz "the answer = " # define a user string
myNum: .word 20014924 # define a user data word
.text # indicate that user program starts
.globl main
main: # the main routine
li $v0, 4 # system call number 4 is for printing strings
la $a0, myStr # load the starting address of myStr to $a0
syscall # now print the string
lw $t1, myNum
addiu $t0, $zero, 31 # initialized counter
addi $t2, $zero, 1 # adds 1 to the LSB
sll $t2, $t2, 31 # moves 1 to the MSB
li $v0, 1 # system call number 1 is for printing integers
loop:
beq $t0, -1, exit # checks the counter
and $t3, $t2, $t1 # $t2 AND $t1 saves to $t3
beq $t3, $0, post_shift # if the AND results in 0 skip to post shift
srl $t3, $t3, $t0 # if the AND results in 1 srl by counter
post_shift:
move $a0, $t3 # moves value of AND to arg resgister
syscall # now print the integer
sub $t0, $t0, 1 # decrements counter
srl $t2, $t2, 1 # shifts comparer 1 to the right
j loop
exit:
jr $ra # main routine returns through jump register
I am attempting to convert the number 0x20014924 to a binary number. I am getting an unexpected binary readout:
0000 0001 0011 0001 0110 0111 0100 1100
actual output0010 0000 0000 0001 0100 1001 0010 0100
expected output.
Any suggestions on debugging or where I am going wrong would be greatly appreciated!
.data #start to define user data
myStr: .asciiz "the answer = " # define a user string
myNum: .word 20014924 # define a user data word
.text # indicate that user program starts
.globl main
main: # the main routine
li $v0, 4 # system call number 4 is for printing strings
la $a0, myStr # load the starting address of myStr to $a0
syscall # now print the string
lw $t1, myNum
addiu $t0, $zero, 31 # initialized counter
addi $t2, $zero, 1 # adds 1 to the LSB
sll $t2, $t2, 31 # moves 1 to the MSB
li $v0, 1 # system call number 1 is for printing integers
loop:
beq $t0, -1, exit # checks the counter
and $t3, $t2, $t1 # $t2 AND $t1 saves to $t3
beq $t3, $0, post_shift # if the AND results in 0 skip to post shift
srl $t3, $t3, $t0 # if the AND results in 1 srl by counter
post_shift:
move $a0, $t3 # moves value of AND to arg resgister
syscall # now print the integer
sub $t0, $t0, 1 # decrements counter
srl $t2, $t2, 1 # shifts comparer 1 to the right
j loop
exit:
jr $ra # main routine returns through jump register
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现我需要用十六进制表示这个词
Figured out I needed to represent the word in hexadecimal