1

Firstly, I apologize for being a complete n00b here. Assembly language is a whole different field for me, but I'm keen to learn.

I'm following along with Baking Pi and just working through the first lesson. I'm using a Mac (Mountain Lion), but I do have Xcode installed, with the iOS SDK, since I use this for work. The iOS SDK already cross-compiles for ARM.

When I try to assemble the basic opening tutorial, I immediately get syntax errors, so obviously the assembler that ships with OS X, while it can assemble armv6, requires slightly different syntax. Can anyone point me to the right place to know what the differences are?

The issues I'm running into right now are with this really basic code, which just turns on the LED on the Raspberry Pi.

/* -*- Baking Pi tutorial from cam.ac.uk -*-

   This is just the code that is written during the
   'Baking Pi' course from the University of Cambridge,
   likely with some adjustments as I've played around with
   the code for exploratory purposes.

   The addresses of the various hardware components are
   only known from reading the manufacturers' manuals.

   Author:       Chris Corbyn <chris@w3style.co.uk>
   Architecture: armv6
   Hardware:     Raspberry Pi Model B
*/

  /* the initial section appears first in the output */
  .section .init
  /* declare a label for code placement */
  .globl _start

  /* begin main program instructions */
_start:
  /* load address of GPIO controller to register r0 */
  ldr r0,=0x20200000
  /* Explanation: The GPIO controller allocates 4 bytes for
     each 10 pins. There are 54 pins, ~ 6 x 4 = 24 bytes of
     space. Each 4 btes is sub-divided to 3 bits per pin.
     Since we need the 16th pin, we want 3 x 6 bits within
     the correct set of pins. That's 6 x 3 = 18 bits, hence
     the left-shift 18 bits. We then store the bit for the
     address of the pin to the memory location of the GPIO
     controller (from r0), offset by 4 bytes, so that we're
     operating on the second set of 10 pins (10-19).

     This doesn't do anything yet; we're simply 'marking'
     the pin, before we send an instruction to a different
     memory location to turn the pin 'off' (it's backwards)
     thus turning the LED 'on'.
  */

  /* put the number 1 to register r1 */
  mov r1,#1
  /* left-shift the value in r1 by 18 bits */
  lsl r1,#18
  /* store value at r1 to mem r0, offset 4 bytes (pin 16) */
  str r1,[r0,#4]

  /* Explanation: The instruction to turn 'off' a GPIO pin
     involves writing to the memory address 40 bytes into
     the GPIO controller. We write the bit for the pin that
     needs to be turned off. Conversely, offset 28 is used
     to turn a pin 'on' instead of off.
  */

  mov r1,#1
  /* left-shift to just the 16th bit, for the 16th pin */
  lsl r1,#16
  /* store value to r0, offset 40 bytes (turn off) */
  str r1,[r0,#40]

  /* declare a label for a loop (which does nothing) */
loop$:
  /* branch to loop$ label, thus loop forever */
  b loop$

/* -*- end of file -*- */

Assembling the code with as -arch armv6 source/main.s shows:

source/main.s:17:Expected comma after segment-name

That line is:

.section .init

I assume it wants a trailing comma, but changing it to:

.section .init,

Then causes it to complain:

source/main.s:24:unsupported relocation on symbol L0

source/main.s:24:Undefined local symbol 0 (0f or 0b)

That line is:

ldr r0,=0x20200000

I'm lost before I even get started. Unfortunately, the tool linked to from the Downloads page (YAGARTO) doesn't actually work on OS X, from what I've read on other StackOverflow posts. I also seems to include GCC in the bundle, so I'd rather not install it, since it may impact on my Xcode installation and the LLVM stuff that ships with it.

Alternatively, if I can install an armv6 assembler without a whole GCC toolchain accompanying it (I already have GCC + LLVM), that would work just as well. Is there something in Homebrew? I'm probably googling for the wrong things.

EDIT | The specific assembler I'm using reports itself as "Apple Inc version cctools-839, GNU assembler version 1.38".

EDIT 2 | There's a -q flag, that makes it use the LLVM assembler. This gives much more useful errors.

source/main.s:17:17: error: unexpected token in '.section' directive
  .section .init
                ^
source/main.s:24:10: error: unexpected token in operand
  ldr r0,=0x20200000
         ^
Community
  • 1
  • 1
d11wtq
  • 34,788
  • 19
  • 120
  • 195
  • See http://stackoverflow.com/questions/9735169/iphone-assembly-compilation-error-with-ldr-parameters – Michael Jun 16 '13 at 09:49
  • @Michael, thanks, I *think* I understand that now. So I left my trailing comma after `.section` and added a new `gpio_ctrl:` label containing `.word 0x20200000`, then used that label to do the `ldr`. It compiles now, so I assume that's right. The trailing comma confuses me, however. I guess if it works, it works :) – d11wtq Jun 16 '13 at 10:22

0 Answers0