List of Listings

Listing 2.1 “Hello World” program in ARM assembly 36

Listing 2.2 “Hello World” program in C 37

Listing 2.3 “Hello World” assembly Listing 39

Listing 2.4 A Listing with mis-aligned data 43

Listing 2.5 A Listing with properly aligned data 45

Listing 2.6 Defining a symbol for the number of elements in an array 47

Listing 5.1 Selection in C 101

Listing 5.2 Selection in ARM assembly using conditional execution 102

Listing 5.3 Selection in ARM assembly using branch instructions 102

Listing 5.4 Complex selection in C 103

Listing 5.5 Complex selection in ARM assembly 104

Listing 5.6 Unconditional loop in ARM assembly 105

Listing 5.7 Pre-test loop in ARM assembly 105

Listing 5.8 Post-test loop in ARM assembly 106

Listing 5.9 for loop in C 106

Listing 5.10 for loop rewritten as a pre-test loop in C 107

Listing 5.11 Pre-test loop in ARM assembly 107

Listing 5.12 for loop rewritten as a post-test loop in C 108

Listing 5.13 Post-test loop in ARM assembly 108

Listing 5.14 Calling scanf and printf in C 111

Listing 5.15 Calling scanf and printf in ARM assembly 111

Listing 5.16 Simple function call in C 114

Listing 5.17 Simple function call in ARM assembly 114

Listing 5.18 A larger function call in C 114

Listing 5.19 A larger function call in ARM assembly 115

Listing 5.20 A function call using the stack in C 115

Listing 5.21 A function call using the stack in ARM assembly 116

Listing 5.22 A function call using stm to push arguments onto the stack 116

Listing 5.23 A small function in C 118

Listing 5.24 A small function in ARM assembly 118

Listing 5.25 A small C function with a register variable 119

Listing 5.26 Automatic variables in ARM assembly 119

Listing 5.27 A C program that uses recursion to reverse a string 120

Listing 5.28 ARM assembly implementation of the reverse function 121

Listing 5.29 Better implementation of the reverse function 122

Listing 5.30 Even better implementation of the reverse function 122

Listing 5.31 String reversing in C using pointers 123

Listing 5.32 String reversing in assembly using pointers 123

Listing 5.33 Initializing an array of integers in C 124

Listing 5.34 Initializing an array of integers in assembly 125

Listing 5.35 Initializing a structured data type in C 125

Listing 5.36 Initializing a structured data type in ARM assembly 126

Listing 5.37 Initializing an array of structured data in C 127

Listing 5.38 Initializing an array of structured data in assembly 128

Listing 5.39 Improved initialization in assembly 129

Listing 5.40 Very efficient initialization in assembly 130

Listing 6.1 Definition of an Abstract Data Type in a C header file 138

Listing 6.2 Definition of the image structure may be hidden in a separate header file 139

Listing 6.3 Definition of an ADT in Assembly 140

Listing 6.4 C program to compute word frequencies 140

Listing 6.5 C header for the wordlist ADT 142

Listing 6.6 C implementation of the wordlist ADT 143

Listing 6.7 Makefile for the wordfreq program 146

Listing 6.8 ARM assembly implementation of wl_print_numerical() 148

Listing 6.9 Revised makefile for the wordfreq program 149

Listing 6.10 C implementation of the wordlist ADT using a tree 151

Listing 6.11 ARM assembly implementation of wl_print_numerical() with a tree 158

Listing 7.1 ARM assembly code for adding two 64 bit numbers 176

Listing 7.2 ARM assembly code for multiplication with a 64 bit result 176

Listing 7.3 ARM assembly code for multiplication with a 32 bit result 177

Listing 7.4 ARM assembly implementation of signed and unsigned 32-bit and 64-bit division functions 187

Listing 7.5 ARM assembly code for division by constant 193 192

Listing 7.6 ARM assembly code for division of a variable by a constant without using a multiply instruction 193

Listing 7.7 Header file for a big integer abstract data type 195

Listing 7.8 C source code file for a big integer abstract data type 196

Listing 7.9 Program using the bigint ADT to calculate the factorial function 211

Listing 7.10 ARM assembly implementation if the bigint_adc function 213

Listing 8.1 Examples of fixed-point multiplication in ARM assembly 233

Listing 8.2 Dividing x by 23 239

Listing 8.3 Dividing x by 23 Using Only Shift and Add 240

Listing 8.4 Dividing x by − 50 242

Listing 8.5 Inefficient representation of a binimal 242

Listing 8.6 Efficient representation of a binimal 243

Listing 8.7 ARM assembly implementation of sin x and cos x using fixed-point calculations 252

Listing 8.8 Example showing how the sin x and cos x functions can be used to print a table 257

Listing 9.1 Simple scalar implementation of the sin x function using IEEE single precision 285

Listing 9.2 Simple scalar implementation of the sin x function using IEEE double precision 286

Listing 9.3 Vector implementation of the sin x function using IEEE single precision 288

Listing 9.4 Vector implementation of the sin x function using IEEE double precision 289

Listing 10.1 NEON implementation of the sin x function using single precision 354

Listing 10.2 NEON implementation of the sin x function using double precision 355

Listing 11.1 Function to map devices into the user program memory on a Raspberry Pi 367

Listing 11.2 Function to map devices into the user program memory space on a pcDuino 372

Listing 11.3 ARM assembly code to set GPIO pin 26 to alternate function 1 381

Listing 11.4 ARM assembly code to configure PA10 for output 388

Listing 11.5 ARM assembly code to set PA10 to output a high state 389

Listing 11.6 ARM assembly code to read the state of PI14 and set or clear the Z flag 389

Listing 13.1 Assembly functions for using the Raspberry Pi UART 418

Listing 14.1 Definitions for ARM CPU modes 435

Listing 14.2 Function to set up the ARM exception table 439

Listing 14.3 Stubs for the exception handlers 440

Listing 14.4 Skeleton for an exception handler 441

Listing 14.5 ARM startup code 443

Listing 14.6 A simple main program 446

Listing 14.7 A sample Gnu linker script 448

Listing 14.8 A sample make file 450

Listing 14.9 Running make to build the image 451

Listing 14.10 An improved main program 452

Listing 14.11 ARM startup code with timer interrupt 453

Listing 14.12 Functions to manage the pdDuino interrupt controller 454

Listing 14.13 Functions to manage the Raspberry Pi interrupt controller 457

Listing 14.14 Functions to manage the pdDuino timer0 device 459

Listing 14.15 Functions to manage the Raspberry Pi timer0 device 460

Listing 14.16 IRQ handler to clear the timer interrupt 462

Listing 14.17 A sample make file 463

Listing 14.18 Running make to build the image 464