Gentle Introduction to ARM V8 Assembly Language

February 25, 2022 · View on GitHub

Attribution

This work is created by Perry Kivolowitz, Professor and Chair of Computer Science at Carthage College. It is copyright © 2021 and may be freely shared for educational purposes.

Overview

These documents are designed for readers who are familiar with C or C++. Each document bridges the reader's understanding of the higher level language to the corresponding assembly language.

The AARCH64 ISA is used. That is, the assembly language used is that of the 64 bit ARM processor.

Assembly language text books typically cover the MIPS ISA because it has been around forever and isn't x86. We consider the MIPS processor as having 1.5 feet in the dustbin of history.

A few texts cover the x86. We consider the x86 an abominable mass of poodles jumping through hoops to allow the modern to coexist with the ancient. Poodles jumping through hoops is best viewed on youtube, not in a text book.

The ARM V8 ISA (AARCH64) is current and reasonable.

Linux calling conventions are used. That is, the assembly language is designed to be run on Linux machines. Even though Macintosh M1 machines are AARCH64, the conventions they use are specific to the Mac - big surprise.

Part 1 - Bridging Common Language Constructs

Some might argue this makes a strange choice of initial chapters. To many, Part 2's material will make more sense to come first. Our choice of putting this material first is born from the desire to bridge the higher level language concepts you already know to the underlying technology. Then we'll go into details hopefully having broken through the common fear of assembly language.

ChapterDescription
Hello WorldDemonstrates how close C is to assembly language
ifDemonstrates implementation of both if and if / else
whileDemonstrates implementation of a while loop
forDemonstrates implementation of a for loop
Function Calls and ReturnsDemonstrates implementation of function calls and returns
structDemonstrates use of struct and by extension, class
BracesFocuses on how braces translate into assembly language
InteropCalling assembly language from C and C++
static and Global VariablesHow static and global variables are defined - also an annotated gdb session
library functionsCalling C library functions from assembly language

Part 2 - Details on Registers and their Usage

All the action happens in the registers. Bottom line is that the variables you are accustomed to using in a higher level language are artificial constructs layered on top of the processor's registers. Understanding this is key to understanding assembly language programming.

ChapterDescription
Concept of RegistersWhat are registers?
Registers Versus VariablesThinking differently about your variables
What Registers Must be Backed Up and WhyConstraints placed on register use
ldr and FriendsReview and amplification of the ldr instructions and by extension, the str instructions - with a number of programming examples
Register WidthsDemonstrated with examples and a gdb session plus a discussion on endianness
Floating Point RegistersNot written
Scratch RegistersNot written
Push and Pop of RegistersNot written

Here is a first start on floating point chapters.

  1. Loading 4 floats from memory.
  2. A NEON (SIMD) operation on all four simultaneously.
  3. Up-conversion from single to double precision.
  4. Passing floats to a "C" function (printf in this case)