目前,我正在研究树莓派,而我的汇编代码遇到了问题。当我尝试使用以下命令运行它时:
as button.o button.s
在终端中。发生以下错误:
Assembler messages:
Error: can't open button.o for reading: No such file or directory
button.s:6: Error: bad instruction `errmsg .asciz "Setup didn't work...
Aborting...\n"'
button.s:7: Error: bad instruction `pinup .int 3'
button.s:8: Error: bad instruction `pinleft .int 14'
button.s:9: Error: bad instruction `pindown .int 0'
button.s:10: Error: bad size 0 in type specifier
button.s:10: Error: bad instruction `pinright.int 7'
button.s:11: Error: bad instruction `pinpau .int 15'
button.s:12: Error: bad instruction `pinqu .int 2'
button.s:32: Error: bad instruction `blwiringpisetup'
button.s:48: Error: bad arguments to instruction -- `mov r7#1'
button.s:50: Error: bad instruction `be done'
我不确定这是语法错误还是一般的代码问题。 代码如下:
//data Section
.data
.balign 4
Intro: .asciz "Raspberry Pi - Blinking led test inassembly\n"
ErrMsg .asciz "Setup didn't work... Aborting...\n"
pinUp .int 3
pinLeft .int 14
pinDown .int 0
pinRight.int 7
pinPau .int 15
pinQu .int 2
i: .int 0
//Code section
.text
.global main
.extern printf
.extern wiringPiSetup
.extern delay
.extern digitalRead
.extern pinMode
main: push {ip, lr}
// printf message
ldr r0, =Intro
bl printf
//Check for setup error
blwiringPiSetup
mov r1,#-1
cmp r0, r1
bne init
ldr r0, =ErrMsg
bl printf
b done
init:
ldr r0, =pinUp
ldr r1, =pinLeft
ldr r2, =pinDown
ldr r3, =pinRight
ldr r4, =pinPau
ldr r5, =pinQu
mov r6, #1
mov r7 #1
cmp r6, r7
be done
done:
pop {ip,pc}
以下代码的变量脱位:
//---------------------------------------
// Data Section
// ---------------------------------------
.data
.balign 4
Intro: .asciz "Raspberry Pi - Blinking led test in assembly\n"
ErrMsg: .asciz "Setup didn't work... Aborting...\n"
pin: .int 0
i: .int 0
delayMs: .int 1000
OUTPUT = 1
任何帮助将不胜感激。
答案 0 :(得分:1)
您在标签名称后忘记了冒号,因此解析器将它们视为指令助记符。 ErrMsg:
代替ErrMsg
。
此外,放置只读数据通常位于.rodata
中,而不是.data
中。如果您希望将其放在其他位置,可以将其放在.data
中,这样就可以从一个基址对它们全部进行寻址,而不是对每个标签使用完全独立的ldr
。 (您可以使用add
在寄存器中生成地址,而不是加载单独的文字。)
.section .rodata
@ .balign 4 @ why align before strings? Normally you'd pad for alignment *after*, unless the total string length is a multiple of 4 bytes or something.
Intro: .asciz "Raspberry Pi - Blinking led test inassembly\n"
ErrMsg: .asciz "Setup didn't work... Aborting...\n"
.data
.balign 4
pinUp: .int 3
pinLeft: .int 14
pinDown: .int 0 @ zero-int vars could be placed in the .bss
pinRight: .int 7
pinPau: .int 15
pinQu: .int 2
i: .int 0 @ do you really need / want static int i in your program?
@ Use a register for a loop counter.