1

我目前正在研究树莓派,但我的汇编代码遇到了问题。当我尝试使用以下命令运行它时:

     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

任何帮助,将不胜感激。

4

1 回答 1

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.
于 2018-07-19T11:55:21.253 回答