Raspberry Pi Zero W

Raspberry Pi LogoI recently picked up a Raspberry Pi Zero W to gain familiarization with the Arm(R) architecture and instruction set. I could not wait for the Zero 2 W to become available, and the suggested price ($15) and compatibility of accessories for the current and future Zero boards helped me decide on the purchase. It has been more than ten years from my first Raspberry Pi purchase, but aside from different clock speeds, the processors between the Zero W Rev 1.1 and Model B Rev 2 are identical.

One personal goal for the purchase is developing assembly code that uses a vector instruction set, such as vfp or neon, and is called from C code. This represents a typical situation where a software system running on an Arm processor and is implemented in C but needs assembly to take advantage of specific processor features. A simple program implemented with two source files, sum.s and main.c, that uses C and assembly is presented here.

sum.s:

.cpu arm1176jzf-s
.fpu vfp
.syntax unified

.global sum
.type sum, "function"
.p2align 4
sum:
  add r0, r0, r1
  bx lr

main.c:

#include <stdio.h>

int sum(int a, int b);

int main()
{
  int i = 0;
  i = sum(5, 7);
  printf("%d\n", i);
}

The above source is compiled with the following command: gcc main.c sum.s

The sum function simply adds two input integers and returns the result to the caller. The main function calls the sum function with two constant integers and outputs the sum using printf.

Questions, comments, and responses are welcomed and appreciated.

Leave a Reply