Raspberry Pi Assembler

Raspberry Pi Assembler

RASPBERRY PI ASSEMBLER Roger Ferrer Ib´a~nez Cambridge, Cambridgeshire, U.K. William J. Pervin Dallas, Texas, U.S.A. December 18, 2018 i Contents 1 Raspberry Pi Assembler 1 1.1 Writing Assembler . 1 1.2 Our first program . 2 1.3 First program results . 3 2 ARM Registers 7 2.1 Basic arithmetic . 7 3 Memory 9 3.1 Memory . 9 3.2 Addresses . 9 3.3 Data . 10 3.4 Sections . 11 3.5 Load . 11 3.6 Store . 14 3.7 Programming style . 15 4 Debugging 19 4.1 gdb . 19 5 Branching 25 5.1 A special register . 25 5.2 Unconditional branches . 26 5.3 Conditional branches . 26 6 Control structures 31 6.1 If, then, else . 31 6.2 Loops . 32 6.3 1 + 2 + 3 + 4 + ··· +22 .......................... 32 6.4 3n + 1 . 35 7 Addressing modes 39 7.1 Indexing modes . 39 7.2 Shifted operand . 40 ii Contents 8 Arrays and structures 43 8.1 Arrays and structures . 43 8.2 Defining arrays and structs . 44 8.3 Naive approach without indexing modes . 44 8.4 Indexing modes . 45 8.4.1 Non-updating indexing modes . 45 8.4.2 Updating indexing modes . 46 8.4.3 Post-indexing modes . 47 8.4.4 Pre-indexing modes . 48 8.5 Back to structures . 49 8.6 Strings . 49 9 Functions 51 9.1 Do's and don'ts of a function . 51 9.1.1 New specially named registers . 51 9.1.2 Passing parameters . 52 9.1.3 Well behaved functions . 52 9.1.4 Calling a function . 52 9.1.5 Leaving a function . 52 9.1.6 Returning data from functions . 53 9.2 Hello world . 53 9.3 Real interaction! . 55 9.4 Our first function . 56 9.5 Unified Assembler Language . 59 10 Searching and Sorting 61 10.1 Binary Search . 61 10.2 Insertion Sort . 64 10.3 Random Numbers . 67 10.4 More Debugging . 69 11 Recursion and the Stack 71 11.1 Dynamic activation . 71 11.2 The stack . 72 11.3 Factorial . 74 11.4 Load and Store Multiple . 77 11.5 Factorial again . 78 11.6 Tail-recursion . 80 11.7 Dynamic Programming . 82 12 Conditional Execution 87 12.1 Predication . 87 12.2 The pipe line of instructions . 88 12.3 Predication in ARM . 90 iii Contents 12.4 Collatz conjecture revisited . 90 12.5 Adding predication . 92 12.6 Does it make any difference in performance? . 92 12.7 The s suffix . 93 13 Floating-point Numbers 97 13.1 IEEE-754 Standard . 97 13.2 Examples . 99 13.3 Extremes . 100 13.4 Exceptions . 101 13.5 Accuracy . 101 13.6 *Fixed-point Numbers . 103 14 Real Computations 105 14.1 VFPv2 Registers . 105 14.2 Arithmetic operations . 106 14.3 Load and Store . 108 14.4 Movements between registers . 109 14.5 Conversions . 110 14.6 Modifying the fpscr . 111 14.7 Function call convention and floating-point registers . 111 14.8 Printing Floating-point Numbers . 112 15 Pointers 113 15.1 Passing data to functions . 113 15.2 What is a pointer? . 113 15.3 Passing large amounts of data . 116 15.4 Passing a big array by value . 117 15.5 Passing a big array by reference . 121 15.6 Modifying data through pointers . 123 15.7 Returning more than one piece of data . 126 16 System Calls 127 16.1 File I/O . 128 16.2 lseek . 131 17 Local data 133 17.1 The frame pointer . 133 17.2 Dynamic link of the activation record . 134 17.3 What about parameters passed in the stack? . 137 17.4 Indexing through the frame pointer . 137 18 Inline Assembler in C Code 143 18.1 The asm Statement . 143 18.2 Simple Example . 144 iv Contents 19 Thumb 147 19.1 The Thumb instruction set . 147 19.2 Support of Thumb in Raspbian . 147 19.3 Instructions . 147 19.4 From ARM to Thumb . 148 19.5 Calling functions in Thumb . 149 19.6 From Thumb to ARM . 151 19.7 To know more . 152 20 Additional Topics 153 20.1 ARM Instruction Set . 153 20.2 Interrupt Handling . 154 20.3 To know more . 155 A ASCII Standard Character Set 157 B Integers 159 B.1 Unsigned Integers . 159 B.2 Signed-Magnitude Integers . 159 B.3 One's Complement . 160 B.4 Two's Complement . 161 B.5.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    207 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us