ARM Assembly language tutorial :: Assembly

ARM Assembly language tutorial


Create a file called first.s and write the contents shown above. Save it.

To assemble the file type the following command (write what comes after $ ).

$ as -o first.o first.s

This will create a first.o. Now link this file to get an executable.

If everything goes as expected you will get a first file. This is your program. Run it.

It should do nothing. Yes, it is a bit disappointing, but it actually does something. Get its error code this time.

1 2

$ ./first ; echo $? 2

Great! That error code of 2 is not by chance, it is due to that #2 in the assembler code.

Since running the assembler and the linker soon becomes boring, I’d recommend you using the following Makefile file instead or a similar one.

1 2 3 4 5 6 7 8 9 10 11

# Makefile all: first first: first.o gcc -o $@ $+ first.o : first.s as -o $@ $< clean: rm -vf first *.o

Well, what happened?

We cheated a bit just to make things a bit easier. We wrote a C main function in assembler which only does return 2;. This way our program is easier since the C runtime handled initialization and termination of the program for us. I will use this approach all the time.

Let’s review every line of our minimal assembler file.

/* - first.s */ /* This is a comment */

These are comments. Comments are enclosed in /* and */. Use them to document your assembler as they are ignored. As usually, do not nest /* and */ inside /* because it does not work.

This is a directive for GNU Assembler. A directive tells GNU Assembler to do something special. They start with a dot (.) followed by the name of the directive and some arguments. In this case we are saying that main is a global name. This is needed because the C runtime will call main. If it is not global, it will not be callable by the C runtime and the linking phase will fail.

Another GNU assembler directive. Here we state that main is a function. This is important because an assembler program usually contains instructions (i.e. code) but may also contain data. We need to explicitly state that main actually refers to a function, because it is code.

You might also like

ARM Assembly Programming Tutorial 1 - Delimiter and Label
ARM Assembly Programming Tutorial 1 - Delimiter and Label
ARM Assembly Language Tutorial - Part 1 - Setup ARM Tools
ARM Assembly Language Tutorial - Part 1 - Setup ARM Tools
LWW Computers LWW ipazzport KP-810-19 Germany + English Language Mini Wireless 2.4GHz 84-Keys Keyboard - Black
PC Accessory (LWW Computers)
  • Expedited Shipping Time 6-9 Days .
  • Standard Shipping Time 15-25 days.
  • Ships from HongKong .
  • Ship By Airmail With Online Tracking Information .
  • If you have any questions, please feel free to contact me .
Your Inner Geek, LLC C Programming with The Programmable Box (Orange-Kit)
Software (Your Inner Geek, LLC)
  • This is the first in a series of educational products that teach C Programming using The Programmable Box
  • Ages 10+, home schooling, classroom instruction, self paced instruction, computer clubs, science projects
  • A fun step-by-step approach where students write interesting programs using The Programmable Box which contains LED s, buzzer, range detector, and other input/output...
  • Extensive step-by-step manual (.pdf), Arduna Nano compatible processor, ultra-sonic range detector, buzzer, 6 colored LED s, potentiometer, momentary contact switch...
  • This is the kit version (also available fully assembled). Visit for complete curriculum included in instruction manual. 100% Satisfaction guaranteed...

Copyright © . All Rights Reserved