1

首先,我很抱歉在这里是一个完整的 n00b。汇编语言对我来说是一个完全不同的领域,但我很想学习。

我正在跟随Baking Pi并刚刚完成第一课。我使用的是 Mac(Mountain Lion),但我确实安装了 Xcode 和 iOS SDK,因为我用它来工作。iOS SDK 已经针对 ARM 进行了交叉编译。

当我尝试组装基本的开放教程时,我立即遇到语法错误,因此显然 OS X 附带的组装器虽然可以组装 armv6,但需要的语法略有不同。谁能指出我正确的地方以了解差异是什么?

我现在遇到的问题是这个非常基本的代码,它只是打开了 Raspberry Pi 上的 LED。

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

用显示组装代码as -arch armv6 source/main.s

source/main.s:17: 段名后的预期逗号

那条线是:

.section .init

我认为它需要一个尾随逗号,但将其更改为:

.section .init,

然后导致它抱怨:

source/main.s:24: 符号 L0 上不支持的重定位

source/main.s:24: 未定义的本地符号 0(0f 或 0b)

那条线是:

ldr r0,=0x20200000

我还没开始就迷路了。不幸的是,从我在其他 StackOverflow 帖子中看到的内容来看,从下载页面 (YAGARTO) 链接到的工具实际上并不能在 OS X 上运行。我似乎也将 GCC 包含在包中,所以我宁愿不安装它,因为它可能会影响我的 Xcode 安装和它附带的 LLVM 东西。

或者,如果我可以安装一个没有整个 GCC 工具链的 armv6 汇编器(我已经有 GCC + LLVM),那也可以。Homebrew有什么东西吗?我可能在谷歌上搜索错误的东西。

编辑 | 我正在使用的特定汇编程序将自己报告为“Apple Inc 版本 cctools-839,GNU 汇编程序版本 1.38”。

编辑 2 | 有一个-q标志,使它使用 LLVM 汇编器。这给出更多有用的错误。

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
         ^
4

0 回答 0