Skip to content

Instantly share code, notes, and snippets.

@marktyers
Last active April 3, 2016 20:47
Show Gist options
  • Save marktyers/97aa228b55b9c773199b4743af46fd2f to your computer and use it in GitHub Desktop.
Save marktyers/97aa228b55b9c773199b4743af46fd2f to your computer and use it in GitHub Desktop.

http://www.microdigitaled.com/ARM/ASM_ARM/Software/ARM_Assembly_Programming_Using_Raspberry_Pi_GUI.pdf

Install tools on the Raspberry Pi.

sudo apt-get install -y gcc gdb

Configure Editor, install colour syntax highlighting.

Using GDB

as -g -o test.o test.s
ld -o test test.o
gdb test

Useful GDB commands

q       quit
l       list source code
b 6     set breakpoint on line 6
r       run the program
i r     view (get information) registers
stepi   single step.
step 3  step through 3 instructions
c       continue execution
disass  disassemble the program
x/8xw   display 8 words in hex format starting at address specified (number of items, format(x: hex), size (w: word))

Purpose of Registers

Placing 1 in register 7 terminates the program Placing a value in register 0 makes it available in the shell variable echo $? after program exits.

Sample Programs

  .global _start
_start: 
  MOV     R1, #0x25
  MOV     R2, #0x34
  ADD     R3, R2, R1
  MOV     R0, R3          @ placing a value in R0 makes it available after program exits
  MOV     R7, #1          @ placing 1 in register 7 tells OS to terminal program
  SVC     0               @ transfers execution to the OS

Countdown Loop

        .global _start
_start:
        MOV     r1, #10
loop:
        SUBS    r1, r1, #1
        BNE     loop
        MOV     R7, #1
        SVC     0

GPIO Pins: https://www.raspberrypi.org/forums/viewtopic.php?&t=48770

Good Tutorial: http://www.peter-cockerell.net/aalp/html/frames.html

http://www.davespace.co.uk/arm/introduction-to-arm/conditional.html

Cross-Compiler: https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html#note3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment