gpt4 book ai didi

assembly - 编译 MIPS 程序集源时出现初学者错误

转载 作者:行者123 更新时间:2023-12-02 19:17:25 25 4
gpt4 key购买 nike

我正在尝试通过学习MIPS Assembly Language Programming来学习MIPS汇编。在书中我有这个代码(从书的第 37 页提取):

.data
prompt: .asciiz "\n Please Input a Value: "
bye: .asciiz "\n Bye!"
.globl main
.text

main:
li $v0, 4
la $a0, prompt
syscall

li $v0, 5
syscall
beqz $v0, end
move $a0, $v0
li $v0, 1
syscall
b main


end:
li $v0, 4
la $a0, bye
syscall

li $v0, 10
syscall

我有一个cross-compiled binutils目标为 mips-elf,但是当我尝试汇编代码时,出现了一些错误

ubuntu@eeepc:~/Desktop$ mips-elf-as test-mips.asm
test-mips.asm: Assembler messages:
test-mips.asm:8: Error: illegal operands 'li'
test-mips.asm:9: Error: illegal operands 'la'
test-mips.asm:12: Error: illegal operands 'li'
test-mips.asm:14: Error: illegal operands 'beqz'
test-mips.asm:15: Error: illegal operands 'move'
test-mips.asm:16: Error: illegal operands 'li'
test-mips.asm:22: Error: illegal operands 'li'
test-mips.asm:23: Error: illegal operands 'la'
test-mips.asm:26: Error: illegal operands 'li'
ubuntu@eeepc:~/Desktop$

我正在使用 x86 Ubuntu Hardy Herron 交叉编译为 MIPS

出了什么问题?

最佳答案

嗯,lila 指令是伪指令,汇编器应该能够识别它们,但您的环境可能需要执行某些操作定义它们(如果它们是宏,我不会感到惊讶)。

尝试将它们更改为“真实”形式:

li $v0,4   -->   lui $v0,0;       ori $v0,$v0,4
la $a0,bye --> lui $a0,bye>>16; ori $a0,$a0,bye&ffff

或者您的特定 MIPS 汇编器用于 RIGHT-SHIFT-16-BITSAND 的任何内容。

我以前从未见过的ls指令。您确定这不是 la 的拼写错误吗?我认为 beqz 应该是 beq。大多数 CPU 会以不同的方式使用相同的指令,例如,将寄存器递减至零 (z) 将寄存器与某些内容进行比较 (eq) 都会设置零标志。

lsbeqzmove 均未出现在 MIPS assembler Wikipedia page 中。尽管后两者在 Patterson & Hennessy 中被列为伪指令.

所以看起来越来越像是您需要做一些额外的设置才能使伪指令正常工作。

关于assembly - 编译 MIPS 程序集源时出现初学者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2151758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com