Are there any books which teach ARM assembly with the GNU toolchain? - Page 1
Forum section: electronics / general

author: XFDDesign
author_rank: Frequent Contributor
timestamp: May 11, 2018, 04:22:47 am
content: My google fu is failing me, but I'm wanting to learn assembly for the Cortex-M series arm devices (Arm v7). I've found example code online for assembly programs, but they dont assemble with the GNU Toolchain. The books I've found on Amazon either don't specify what toolchain, or use a specific one like Keil. Honestly, it feels like the 90s when you got a book that was teaching TASM while you had MASM; technically the content should be the same between the two, but the assemblers did things differently enough that nothing worked the same.Are there any books out there which teach you ARM assembly through the GNU Toolchain?

author: ataradov
author_rank: Super Contributor
timestamp: May 11, 2018, 04:53:16 am
content: It is much easier to separate the two. ARM instructions use unified syntax, which should be supported by most if not all assemblers. And it matches the official ARM documentation for the architecture.The non-instruction parts like function decorations and data declarations are specific to a toolchain, but can be easily looked up in the GNU AS documentation.But if you are just looking to copy-paste the code, then this won't help, of course.

author: XFDDesign
author_rank: Frequent Contributor
timestamp: May 11, 2018, 05:15:29 am
content: Instructions specifically, sure. I guess I'm after a book specifically that covers the latter, since my efforts for online documentation have failed me.

author: abraxa
author_rank: Frequent Contributor
timestamp: May 11, 2018, 09:52:03 am
content: Quote from: XFDDesign on May 11, 2018, 04:22:47 amI attached an example project I created a while ago that uses the code in asm.s to produce a Knight Rider-like LED effect on pins PE0..7. It compiles just fine for me, but you may need to adjust the tool chain path in the makefile (currently set to /opt/arm). It's designed for an STM32F103 (Cortex-M3).Quote from: XFDDesign on May 11, 2018, 04:22:47 amAs ataradov pointed out, the tool chain doesn't really matter once you know how to set it up. My project may help you when it comes to dedicated .s files, using inline assembly is described in plenty other places online, e.g. here:http://www.ethernut.de/en/documents/arm-inline-asm.html

author: XFDDesign
author_rank: Frequent Contributor
timestamp: May 11, 2018, 12:58:55 pm
content: Quote from: wilfred on May 11, 2018, 05:59:52 amThanks, but this appears to be more aimed at teaching the ARM as a whole, is it not? I have (what I believe to be) a firm grasp on the peripherals of the ARM and general development by way of C, but I'm now after getting down to bare metal and writing whole programs in assembly, which I don't seem to find this book really advertising itself as a means towards.I think Ataradov found the root problem pretty well: It isn't a matter of the instructions, it's a matter of the semantics of the assembler itself.

author: langwadt
author_rank: Super Contributor
timestamp: May 11, 2018, 01:40:08 pm
content: Quote from: XFDDesign on May 11, 2018, 12:58:55 pmwhich beg the question why would you want to write whole programs in assembler?

author: rstofer
author_rank: Super Contributor
timestamp: May 11, 2018, 03:14:59 pm
content: I wouldn't bet on the average programmer's ability to write assembly code that is better than what comes out of the C compiler with optimization turned up high. Compiler writers are really good!In the early days of ARM, like the ARM7TDMI chips (LPC2106, LPC2148, etc) the startup file was written in assembly language and had, perhaps, a hundred lines or so. The big deal with the CORTEX chips was the elimination of the .s file; startup code could be written in C.If you turn off optimization, you might get some idea of the assembly language by having the C compiler generate a list file.I would expect the instruction syntax to follow ARM's definition. Everything else will probably be compiler specific.http://vision.gel.ulaval.ca/~jflalonde/cours/1001/h16/docs/arm-instructionset.pdfOf equal interest is the linker file since it lays out memory and defines some very important global constants.

author: josip
author_rank: Regular Contributor
timestamp: May 13, 2018, 09:49:55 am
content: Quote from: XFDDesign on May 11, 2018, 04:22:47 amWhen I switched to Cortex-M0+, I read (some parts of) "The Definitive Guide to ARM Cortex-M0 and Cortex-M0+ Processors" from Joseph Yiu, to get some basic knowledge. There is also "The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors" from the same author. Something about GNU assembler syntax, and how too start with gcc, can be found in this book. Not sure if this can help you somehow.I am coding in assembler (Cortex-M0+), but using free IAR assembler/linker, not GNU. At the begging I have some problems with setup things right, but resolved all of this by IAR documentation and related on-line stuff. Device that I am using is with USB bootloader, so I don't use any extra hardware (except PL2303HXD UART / USB bridge for log) or software, just text editor and IAR assembler/linker.

author: westfw
author_rank: Super Contributor
timestamp: May 14, 2018, 02:19:46 am
content: QuoteHmm. I thought the last time I tried ARM assembler (for CM3), I found some subtle and annoying differences between the gnu assembler and published ARM assembler examples. Although I don't seem to have saved any pithy comments in the relevant place :-(Gnu Assembler wanted "BEQ.N target" to generate a short-range conditional branch, when the ARM documentation implied I should need "BEQ.W" to get a long-range branch (and thus should only have needed "BEQ target")? That's the only thing that stands out.Be aware that while the ARM architecture "per se" has a very regular syntax, individual CPUs (CM3, CM0) add limitations on which forms are allowed, and one the range of values permitted, that are ... really annoying.

author: ataradov
author_rank: Super Contributor
timestamp: May 14, 2018, 02:32:58 am
content: Quote from: westfw on May 14, 2018, 02:19:46 amWorks for me. The codeCode:main:beqmaintranslates intoCode:00000000 <main>:0:d0febeq.n0 <main>using command "arm-none-eabi-as -mcpu=cortex-m7 test.s".Version of the AS: "GNU assembler version 2.24.0 (arm-none-eabi) using BFD version (GNU Tools for ARM Embedded Processors) 2.24.0.20150304".

author: Syntax_Error
author_rank: Regular Contributor
timestamp: June 04, 2018, 12:23:37 am
content: I have this book. I like it a lot.https://www.amazon.com/Embedded-Cortex-M-Microcontrollers-Assembly-Language/dp/0982692668/ref=sr_1_1?ie=UTF8&qid=1528071756&sr=8-1&keywords=programming+arm+c+assembly

author: ehughes
author_rank: Frequent Contributor
timestamp: June 04, 2018, 04:16:26 pm
content: Something that may be helpful as an example. If you install Segger Embedded Studio, It will can a assembly project with gnu syntax. It has some boiler plate that is useful. You can see some of the GNU syntax for section placement, etc.If you create a C project, there will also be some assembly for the startup routines to see you can mix the two.

author: legacy
author_rank: Super Contributor
timestamp: June 04, 2018, 09:50:44 pm
content: RiscOS + DDE, the best ever way

author: rstofer
author_rank: Super Contributor
timestamp: June 06, 2018, 03:50:23 am
content: Quote from: Syntax_Error on June 04, 2018, 12:23:37 amI just got my copy today. It's excellent! I don't do a lot of assembly level programming but I do enjoy it. Perhaps I will work through some of the examples just for giggles.A lot of the examples have a C language main function callling some function written in assembly. This gives a good demonstration of the linkage between the two.Definitely worth the money.

author: obiwanjacobi
author_rank: Super Contributor
timestamp: June 06, 2018, 09:57:51 am
content: Just ran into this:https://azeria-labs.com/writing-arm-assembly-part-1/

author: dizzy
author_rank: Newbie
timestamp: June 06, 2018, 11:32:26 am
content: Check forhttps://www.amazon.com/Modern-Assembly-Language-Programming-Processor/dp/0128036982. They are using GNU assembler for all code samples.

author: ehughes
author_rank: Frequent Contributor
timestamp: June 06, 2018, 01:38:31 pm
content: Quote from: obiwanjacobi on June 06, 2018, 09:57:51 amGreat find!

author: Syntax_Error
author_rank: Regular Contributor
timestamp: June 07, 2018, 01:47:54 am
content: Quote from: rstofer on June 06, 2018, 03:50:23 amIt also has examples of the reverse: assembly programs importing C labels as routines, and also goes over linker output and files, which I found extremely helpful.

author: obiwanjacobi
author_rank: Super Contributor
timestamp: June 13, 2018, 07:37:02 am
content: For the fan-boys.https://teespring.com/arm-32-assembly-cheatsheet#pid=623&cid=102506&sid=front