MIPS 十六进制数转二进制

发布于 2025-01-13 01:17:30 字数 1368 浏览 2 评论 0原文

我正在尝试将数字 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 output
0010 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷又爱笑 2025-01-20 01:17:30

发现我需要用十六进制表示这个词

myNum: .word 0x20014924   # define a user data word

Figured out I needed to represent the word in hexadecimal

myNum: .word 0x20014924   # define a user data word
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文