1

I am working on a raspberry pi at the moment and I am running into an issue with my assembly code. When i try to run it with the following command:

     as button.o button.s

in terminal. An the following errors occur:

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'

I'm not sure if it is a syntax error or or a problem with the code in general. The code follows:

//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}

Followed variable decleration of the following code:

//---------------------------------------
//  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

Any help would be appreciated.

shurburt
  • 93
  • 2
  • 6
  • Can you clear your registers before you use them? Are you sure r7 doesn't already contain a value? Are you aloud to use r7? – Rob Jul 19 '18 at 00:15
  • Could also be a problem with this button.o. – Rob Jul 19 '18 at 00:18
  • When i try to clear the registers r6 and r7 i get: button.s:47: Error: bad instruction `clr r6' button.s:48: Error: bad instruction `clr r7' – shurburt Jul 19 '18 at 00:22
  • My understanding is that is the file the assembler will create. – shurburt Jul 19 '18 at 00:23
  • Where might i find which registers I can use. I am having trouble finding it. – shurburt Jul 19 '18 at 00:24
  • 2
    Although not your problem I think you mean to do `as -o button.o button.s` `-o` is followed by the output file name. – Michael Petch Jul 19 '18 at 00:58
  • You may have missed the part "Although not your problem". What I suggested wouldn't solve the bad instructions it should fix the issue with `Error: can't open button.o for reading: No such file or directory` . Without the `-o` in front of `button.o` the file is also being treated as an input file. – Michael Petch Jul 19 '18 at 01:04
  • 1
    I missed it the first time when I looked at the code, but *most* of your label names aren't terminated with a colon. For example `ErrMsg .asciz "Setup didn't work... Aborting...\n"` should be `ErrMsg: .asciz "Setup didn't work... Aborting...\n"` . You make a similar error on most of your labels. You did get it correct when you defined `Intro` and `i` – Michael Petch Jul 19 '18 at 01:13
  • @Michael Petch I am incredibly embarrassed. Are you experienced in using wiringPi by any chance. – shurburt Jul 19 '18 at 01:15
  • No I'm not - sorry – Michael Petch Jul 19 '18 at 01:16

1 Answers1

1

You forgot the colon after your label names, so the parser was treating them as instruction mnemonics. ErrMsg: instead of ErrMsg.

Also, put read-only data normally goes in .rodata, not .data. You could put it in .data if you want it near something else so you can address them all from one base address, though, instead of using a totally separate ldr for every label. (You could generate addresses in registers with add, instead of loading a separate literal.)

.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.
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Surprisingly, googling on the error message, or that + `label` or `colon` didn't find any duplicates. So I guess this is worth answering in case anyone else in the future has the same error. – Peter Cordes Jul 19 '18 at 11:57