Hello everybody,
I am new to Assembly programming and I would like to learn it.
Could you advise me which (e)books I should start with and the software I can use on my Raspberry Pi B 2.0 running Debian?
Thanks!
Hi krynobosman and welcome to the community!
Though I don't have a RasPi myself and can't recommend any books, I'm programming in assembly language myself on the Cortex-M.
I have a CubieBoard2 running Cubian Linux, which I use for testing Cortex-M code (it can be compiled and run on the Cortex-A), thus my environment would be similar to yours.
What I use is GCC-4.7.2 (the default compiler for Cubian), and I've made a few tests in assembly language. I run these programs on the command-line (via SSH).
First of all, I recommend that you go to the ARM Information Center and download the ARMv7AR Reference Manual.
Because the Cortex-M User Guides are so easy/quick to read, I also suggest that you take a look at the Cortex-M4 instruction set, because it gives you a quick overview of each instruction. Also the Table of Processor Instructions might be interesting. This should give you a quick start.
-But of course, your Cortex-A7 based Raspberry Pi can do much more than the Cortex-M4, so you'll also be interested in GPU and vector programming.
Since I don't know any books myself, I'll let other people recommend books; you may want to follow people like peterharris, daith, jyiu and chrisshore (though Joseph is a Cortex-M expert, he oftens answers questions about or related to assembly language, and his answers gives a good understanding on how the ARM architecture works).
In addition, I'd like to post a small quick-start on how you can compile a minimal assembly language program on the command-line.
This example shows you a few things; including how to build without writing a Makefile, how to call functions written in assembly language from C and how to call C functions from assembly language (including that parameters are passed in registers):
File: 'b'. After saving, issue a 'chmod 755 b' command:
#!/bin/bash DEVICE="cortex-a7" DEV_FLAGS="-mcpu=${DEVICE} -mtune=${DEVICE}" FLAGS="${DEV_FLAGS} -mthumb" ASFLAGS="${FLAGS} -Wa,-mimplicit-it=always -x assembler-with-cpp" GCFLAGS="${FLAGS} -mthumb-interwork -Wall -Wextra -Wimplicit -Wcast-align -Wpointer-arith -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align -Wnested-externs --std=gnu99" LDFLAGS="${FLAGS} -lc -lm -lgcc -lstdc++" gcc ${GCFLAGS} -c main.c -o main.o && \ gcc ${ASFLAGS} -c example.s -o example.o && \ g++ ${LDFLAGS} *.o -o example && \ ./example
File: 'main.c':
#include <stdint.h> #include <stdio.h> void example(void); int main(int argc, const char *argv[]) { example(); return(0); }
File: 'example.s'
.syntax unified /* use modern syntax */ .text /* place our code in the text-section */ .func example /* (for debugging info) */ .global example /* make 'example' symbol global */ .type example,%function /* 'example' is a function */ .thumb_func /* a function, which uses thumb instructions */ example: push {r4-r7,lr} /* save r4-r7 and return address */ ldr r0,=string /* point to format string */ movs r1,#1 /* parameter 1 value */ movw r2,#777 /* parameter 2 value */ bl printf /* call printf */ pop {r4-r7,pc} /* restore saved registers and return */ .pool /* allow the assembler to place a literal pool here */ .size example,.-example /* tell linker how large this function is */ string: .asciz "Value 1:%ld \nValue 2:%ld\n" /* a format-string for printf */ .endfunc /* (for debugging info) */
To build, just type ./b on the command-line. The files should then be compiled and executed.