ENGLISH

ARM 64-Bit Assembly Language

Book information

Publisher
Newnes
Year
2020
ISBN
9780128192214
Language
english
Format
PDF
Filesize
4 MB (4130603 bytes)
Pages
\498
Time added
2022-07-20 17:45:06

Description

Contents List of tables List of figures Preface Choice of processor family General approach 1 Introduction 1.1 Reasons to learn assembly 1.2 The ARM processor 1.3 Computer data 1.3.1 Representing natural numbers 1.3.2 Base conversion 1.3.2.1 Base b to decimal 1.3.2.2 Decimal to base b 1.3.2.3 Bases that are powers-of-two 1.3.2.4 Conversion between arbitrary bases 1.3.3 Representing integers 1.3.3.1 Sign-magnitude representation 1.3.3.2 Excess-(2n-1-1) representation 1.3.3.3 Complement representation Finding the complement Subtraction using complements 1.3.4 Representing characters 1.3.4.1 Non-printing characters 1.3.4.2 Converting character strings to ASCII codes 1.3.4.3 Interpreting data as ASCII strings 1.3.4.4 ISO extensions to ASCII 1.3.4.5 Unicode and UTF-8 1.4 Memory layout of an executing program 1.5 Chapter summary Exercises 2 GNU assembly syntax 2.1 Structure of an assembly program 2.1.1 Labels 2.1.2 Comments 2.1.3 Directives 2.1.4 Assembly instructions 2.2 What the assembler does 2.3 GNU assembly directives 2.3.1 Selecting the current section 2.3.2 Allocating space for variables and constants 2.3.3 Filling and aligning 2.3.4 Setting and manipulating symbols 2.3.5 Functions and objects 2.3.6 Conditional assembly 2.3.7 Including other source files 2.3.8 Macros 2.3.8.1 Macro example 2.3.8.2 Recursive macro example 2.4 Chapter summary Exercises 3 Load/store and branch instructions 3.1 CPU components and data paths 3.2 AArch64 user registers 3.2.1 General purpose registers 3.2.2 Frame pointer 3.2.3 PSTATE register 3.2.4 Link register 3.2.5 Stack pointer 3.2.6 Zero register 3.2.7 Program counter 3.3 Instruction components 3.3.1 Setting and using condition flags 3.3.2 Immediate values 3.3.3 Addressing modes 3.4 Load and store instructions 3.4.1 Load/store single register 3.4.1.1 Syntax 3.4.1.2 Operations 3.4.1.3 Examples 3.4.2 Load/store single register (unscaled) 3.4.2.1 Syntax 3.4.2.2 Operations 3.4.2.3 Examples 3.4.3 Load/store pair 3.4.3.1 Syntax 3.4.3.2 Operations 3.4.3.3 Examples 3.5 Branch instructions 3.5.1 Branch 3.5.1.1 Syntax 3.5.1.2 Operations 3.5.1.3 Examples 3.5.2 Branch register 3.5.2.1 Syntax 3.5.2.2 Operations 3.5.2.3 Examples 3.5.3 Branch and link 3.5.3.1 Syntax 3.5.3.2 Operations 3.5.3.3 Examples 3.5.4 Compare and branch 3.5.4.1 Syntax 3.5.4.2 Operations 3.5.4.3 Examples 3.5.5 Form PC-relative address 3.5.5.1 Syntax 3.5.5.2 Operations 3.5.5.3 Examples 3.6 Chapter summary Exercises 4 Data processing and other instructions 4.1 Operand2 4.1.1 Shift and rotate operations 4.1.2 Extend operations 4.1.3 Immediate data 4.2 Data processing instructions 4.2.1 Arithmetic operations 4.2.1.1 Syntax 4.2.1.2 Operations 4.2.1.3 Examples 4.2.2 Logical operations 4.2.2.1 Syntax 4.2.2.2 Operations 4.2.2.3 4.2.3 Data movement operations 4.2.3.1 Syntax 4.2.3.2 Operations 4.2.3.3 Examples 4.2.4 Shift operations 4.2.4.1 Syntax 4.2.4.2 Operations 4.2.4.3 Examples 4.2.5 Multiply operations with overflow 4.2.5.1 Syntax 4.2.5.2 Operations 4.2.5.3 Examples 4.2.6 Multiply operations with 64-bit results 4.2.6.1 Syntax 4.2.6.2 Operations 4.2.6.3 Examples 4.2.7 Multiply operations with 128-bit results 4.2.7.1 Syntax 4.2.7.2 Operations 4.2.7.3 Examples 4.2.8 Division operations 4.2.8.1 Syntax 4.2.8.2 Operations 4.2.8.3 Examples 4.2.9 Comparison operations 4.2.9.1 Syntax 4.2.9.2 Operations 4.2.9.3 Examples 4.2.10 Conditional operations 4.2.10.1 Syntax 4.2.10.2 Operations 4.2.10.3 Examples 4.3 Special instructions 4.3.1 Count leading zeros 4.3.1.1 Syntax 4.3.1.2 Operations 4.3.1.3 Example 4.3.2 Accessing the PSTATE register 4.3.2.1 Syntax 4.3.2.2 Operations 4.3.2.3 Examples 4.3.3 Supervisor call 4.3.3.1 Syntax 4.3.3.2 Operations 4.3.3.3 Example 4.3.4 No operation 4.3.4.1 Syntax 4.3.4.2 Operations 4.3.4.3 Examples 4.4 Alphabetized list of AArch64 instructions 4.5 Chapter summary Exercises 5 Structured programming 5.1 Sequencing 5.2 Selection 5.2.1 If-then statement 5.2.2 If-then-else statement 5.2.2.1 Using branch instructions 5.2.2.2 Using conditional selection 5.2.3 Complex selection 5.3 Iteration 5.3.1 Pre-test loop 5.3.2 Post-test loop 5.3.3 For loop 5.3.3.1 Pre-test conversion 5.3.3.2 Post-test conversion 5.4 Subroutines 5.4.1 Advantages of subroutines 5.4.2 Disadvantages of subroutines 5.4.3 Standard C library functions 5.4.4 Passing parameters 5.4.5 Calling subroutines 5.4.5.1 Passing arguments in registers 5.4.5.2 Passing arguments on the stack 5.4.6 Writing subroutines 5.4.7 Automatic variables 5.4.8 Recursive functions 5.5 Aggregate data types 5.5.1 Arrays 5.5.2 Structured data 5.5.3 Arrays of structured data 5.6 Chapter summary Exercises 6 Abstract data types 6.1 ADTs in assembly language 6.2 Word frequency counts 6.2.1 Sorting by word frequency 6.2.2 Better performance 6.2.3 Indexing and sorting by frequency 6.3 Ethics case study: Therac-25 6.3.1 History of the Therac-25 6.3.2 Overview of design flaws 6.4 Chapter summary Exercises 7 Integer mathematics 7.1 Subtraction by addition 7.2 Binary multiplication 7.2.1 Multiplication by a power of two 7.2.2 Multiplication of two variables 7.2.3 Signed multiplication 7.2.4 Multiplication of a variable by a constant 7.2.5 Multiplying large numbers 7.3 Binary division 7.3.1 Division by a power of two 7.3.2 Division by a variable 7.3.3 Division by a constant 7.3.4 Dividing large numbers 7.4 Big integer ADT 7.5 Chapter summary Exercises 8 Non-integral mathematics 8.1 Base conversion of fractional numbers 8.1.1 Arbitrary base to decimal 8.1.2 Decimal to arbitrary base 8.1.2.1 Bases that are powers-of-two 8.2 Fractions and bases 8.2.1 Rounding errors 8.2.2 Implications 8.3 Fixed point numbers 8.3.1 Interpreting fixed point numbers 8.3.2 Q notation 8.3.3 Properties of fixed point numbers 8.4 Fixed point operations 8.4.1 Fixed point addition and subtraction 8.4.2 Fixed point multiplication 8.4.3 Fixed point division 8.4.3.1 Results of fixed point division 8.4.3.2 Maintaining precision 8.4.4 Division by a constant 8.4.4.1 Division by constant 23 8.4.4.2 Division by constant -50 8.5 Fixed point input and output 8.6 Computing sine and cosine 8.6.1 Formats for the powers of x 8.6.2 Formats and constants for the factorial terms 8.6.3 Putting it all together 8.6.4 Performance comparison 8.7 Floating point numbers 8.7.1 IEEE 754 half-precision 8.7.1.1 Examples 8.7.2 IEEE 754 single-precision 8.7.3 IEEE 754 double-precision 8.7.4 IEEE 754 quad-precision 8.8 Floating point operations 8.8.1 Floating point addition and subtraction 8.8.2 Floating point multiplication and division 8.9 Ethics case study: patriot missile failure 8.10 Chapter summary Exercises 9 Floating point 9.1 Floating point overview 9.2 Register usage rules 9.3 Floating point control and status registers 9.4 Load/store instructions 9.4.1 Load/store single register 9.4.1.1 Syntax 9.4.1.2 Operations 9.4.1.3 Examples 9.4.2 Load/store single register with unscaled offset 9.4.2.1 Syntax 9.4.2.2 Operations 9.4.2.3 Examples 9.4.3 Load/store pair 9.4.3.1 Syntax 9.4.3.2 Operations 9.4.4 Load/store non-temporal pair 9.4.4.1 Syntax 9.4.4.2 Operations 9.5 Data movement instructions 9.5.1 Moving between data registers 9.5.1.1 Syntax 9.5.1.2 Operations 9.5.1.3 Examples 9.5.2 Floating point move immediate 9.5.2.1 Syntax 9.5.2.2 Operations 9.5.2.3 Examples 9.6 Data conversion instructions 9.6.1 Convert between double, single, and half precision 9.6.1.1 Syntax 9.6.1.2 Operations 9.6.1.3 Examples 9.6.2 Convert between floating point and integer 9.6.2.1 Syntax 9.6.2.2 Operation 9.6.2.3 Examples 9.6.3 Convert between fixed point and floating point 9.6.3.1 Syntax 9.6.3.2 Operations 9.6.3.3 Examples 9.7 Data processing instructions 9.7.1 Round to integral 9.7.1.1 Syntax 9.7.1.2 Operations 9.7.1.3 Examples 9.7.2 Absolute value, negate, square root 9.7.2.1 Syntax 9.7.2.2 Operations 9.7.2.3 Examples 9.7.3 Add, subtract, multiply, and divide 9.7.3.1 Syntax 9.7.3.2 Operations 9.7.3.3 Examples 9.7.4 Multiply and accumulate 9.7.4.1 Syntax 9.7.4.2 Operations 9.7.4.3 Examples 9.7.5 Min and max 9.7.5.1 Syntax 9.7.5.2 Operations 9.7.5.3 Examples 9.7.6 Compare 9.7.6.1 Syntax 9.7.6.2 Operations 9.7.6.3 Examples 9.7.7 Conditional select 9.7.7.1 Syntax 9.7.7.2 Operations 9.7.7.3 Examples 9.8 Floating point sine function 9.8.1 Performance comparison 9.9 Alphabetized list of FP/NEON instructions 9.10 Chapter summary Exercises 10 Advanced SIMD instructions 10.1 Instruction syntax 10.2 Load and store instructions 10.2.1 Load or store single structure using one lane 10.2.1.1 Syntax 10.2.1.2 Operations 10.2.1.3 Examples 10.2.2 Load or store multiple structures 10.2.2.1 Syntax 10.2.2.2 Operations 10.2.2.3 Examples 10.2.3 Load copies of a structure to all lanes 10.2.3.1 Syntax 10.2.3.2 Operations 10.2.3.3 Examples 10.3 Data movement instructions 10.3.1 Duplicate scalar 10.3.1.1 Syntax 10.3.1.2 Operations 10.3.1.3 Examples 10.3.2 Move vector element 10.3.2.1 Syntax 10.3.2.2 Operations 10.3.2.3 Examples 10.3.3 Move immediate 10.3.3.1 Syntax 10.3.3.2 Operations 10.3.3.3 Examples 10.3.4 Transpose matrix 10.3.4.1 Syntax 10.3.4.2 Operation 10.3.4.3 Examples 10.3.5 Vector permute 10.3.5.1 Syntax 10.3.5.2 Operations 10.3.5.3 Examples 10.3.6 Table lookup 10.3.6.1 Syntax 10.3.6.2 Operations 10.3.6.3 Examples 10.4 Data conversion 10.4.1 Convert between integer or fixed point and floating point 10.4.1.1 Syntax 10.4.1.2 Operations 10.4.1.3 Examples 10.4.2 Convert between half, single, and double precision 10.4.2.1 Syntax 10.4.2.2 Operations 10.4.2.3 Examples 10.4.3 Round floating point to integer 10.4.3.1 Syntax 10.4.3.2 Operations 10.4.3.3 Examples 10.5 Bitwise logical operations 10.5.1 Vector logical operations 10.5.1.1 Syntax 10.5.1.2 Operations 10.5.1.3 Examples 10.5.2 Bitwise logical operations with immediate data 10.5.2.1 Syntax 10.5.2.2 Operations 10.5.2.3 Examples 10.6 Basic arithmetic instructions 10.6.1 Vector add and subtract 10.6.1.1 Syntax 10.6.1.2 Operations 10.6.1.3 Examples 10.6.2 Vector add and subtract with narrowing 10.6.2.1 Syntax 10.6.2.2 Operations 10.6.2.3 Examples 10.6.3 Add or subtract and divide by two 10.6.3.1 Syntax 10.6.3.2 Operations 10.6.3.3 Examples 10.6.4 Add elements pairwise 10.6.4.1 Syntax 10.6.4.2 Operations 10.6.4.3 Examples 10.6.5 Absolute difference 10.6.5.1 Syntax 10.6.5.2 Operations 10.6.5.3 Examples 10.6.6 Absolute value and negate 10.6.6.1 Syntax 10.6.6.2 Operations 10.6.6.3 Examples 10.6.7 Get maximum or minimum elements 10.6.7.1 Syntax 10.6.7.2 Operations 10.6.7.3 Examples 10.6.8 Count bits 10.6.8.1 Syntax 10.6.8.2 Operations 10.6.8.3 Examples 10.6.9 Scalar saturating operations 10.6.9.1 Syntax 10.6.9.2 Operations 10.6.9.3 Examples 10.7 Multiplication and division 10.7.1 Vector multiply and divide 10.7.1.1 Syntax 10.7.1.2 Operations 10.7.1.3 Examples 10.7.2 Multiply vector by element 10.7.2.1 Syntax 10.7.2.2 Operations 10.7.2.3 Examples 10.7.3 Saturating vector multiply and double 10.7.3.1 Syntax 10.7.3.2 Operations 10.7.3.3 Examples 10.7.4 Saturating multiply and double (high) 10.7.4.1 Syntax 10.7.4.2 Operations 10.7.4.3 Examples 10.7.5 Estimate reciprocals 10.7.5.1 Syntax 10.7.5.2 Operations 10.7.5.3 Examples 10.7.6 Reciprocal step 10.7.6.1 Syntax 10.7.6.2 Operations 10.7.6.3 Examples 10.7.7 Multiply scalar by element 10.7.7.1 Syntax 10.7.7.2 Operations 10.7.7.3 Examples 10.7.8 Saturating multiply scalar by element and double 10.7.8.1 Syntax 10.7.8.2 Operations 10.7.8.3 Examples 10.8 Shift instructions 10.8.1 Vector shift left by immediate 10.8.1.1 Syntax 10.8.1.2 Operations 10.8.1.3 Examples 10.8.2 Vector shift right by immediate 10.8.2.1 Syntax 10.8.2.2 Operations 10.8.2.3 Examples 10.8.3 Vector saturating shift right by immediate 10.8.3.1 Syntax 10.8.3.2 Operations 10.8.3.3 Examples 10.8.4 Shift left or right by variable 10.8.4.1 Syntax 10.8.4.2 Operations 10.8.4.3 Examples 10.8.5 Shift and insert 10.8.5.1 Syntax 10.8.5.2 Operations 10.8.5.3 Examples 10.8.6 Scalar shift left by immediate 10.8.6.1 Syntax 10.8.6.2 Operations 10.8.6.3 Examples 10.8.7 Scalar shift right by immediate 10.8.7.1 Syntax 10.8.7.2 Operations 10.8.7.3 Examples 10.8.8 Scalar saturating shift right by immediate 10.8.8.1 Syntax 10.8.8.2 Operations 10.8.8.3 Examples 10.9 Unary arithmetic 10.9.1 Vector unary arithmetic 10.9.1.1 Syntax 10.9.1.2 Operations 10.9.1.3 Examples 10.9.2 Scalar unary arithmetic 10.9.2.1 Syntax 10.9.2.2 Operations 10.9.2.3 Examples 10.10 Vector reduce instructions 10.10.1 Reduce across lanes 10.10.1.1 Syntax 10.10.1.2 Operations 10.10.1.3 Examples 10.10.2 Reduce pairwise 10.10.2.1 Syntax 10.10.2.2 Operations 10.10.2.3 Examples 10.11 Comparison operations 10.11.1 Vector compare mask 10.11.1.1 Syntax 10.11.1.2 Operations 10.11.1.3 Examples 10.11.2 Vector absolute compare mask 10.11.2.1 Syntax 10.11.2.2 Operations 10.11.2.3 Examples 10.11.3 Vector test bits mask 10.11.3.1 Syntax 10.11.3.2 Operations 10.11.3.3 Examples 10.11.4 Scalar compare mask 10.11.4.1 Syntax 10.11.4.2 Operations 10.11.4.3 Examples 10.11.5 Scalar absolute compare mask 10.11.5.1 Syntax 10.11.5.2 Operations 10.11.5.3 Examples 10.11.6 Scalar test bits mask 10.11.6.1 Syntax 10.11.6.2 Operations 10.11.6.3 Examples 10.12 Performance mathematics: a final look at sine 10.12.1 Single precision 10.12.2 Double precision 10.12.3 Performance comparison 10.13 Alphabetized list of advanced SIMD instructions 10.14 Advanced SIMD intrinsics 10.15 Chapter summary Exercises 11 Devices 11.1 Accessing devices directly under Linux 11.2 General purpose digital input/output 11.2.1 Typical GPIO device 11.2.2 Raspberry Pi GPIO 11.2.2.1 Setting the GPIO pin function 11.2.2.2 Setting GPIO output pins 11.2.2.3 Reading GPIO input pins 11.2.2.4 Enabling internal pull-up or pull-down 11.2.2.5 Detecting GPIO events 11.2.2.6 GPIO pins available on the Raspberry Pi 11.3 Pulse modulation 11.3.1 Pulse density modulation 11.3.2 Pulse width modulation 11.3.3 Raspberry Pi PWM device 11.4 Common system devices 11.4.1 Clock management device 11.4.2 Raspberry Pi clock manager 11.5 Serial communications 11.5.1 UART 11.5.2 Raspberry Pi UART0 11.5.3 Basic programming for the Raspberry Pi UART 11.6 Chapter summary Exercises 12 Running without an operating system 12.1 Exception processing 12.2 AArch64 execution and exception states 12.2.1 AArch64 exception levels 12.2.2 System control and status registers 12.3 AArch64 vector table 12.3.1 Creating the vector tables 12.3.2 Using the vector tables 12.3.3 Configuring asynchronous exceptions 12.4 The boot process 12.5 Writing a bare metal program 12.5.1 Startup code 12.5.2 Main program 12.5.3 The linker script 12.5.4 Putting it all together 12.6 Using an interrupt 12.6.1 Startup code with interrupt enabling 12.6.2 Interrupt controllers 12.6.3 Timers 12.6.4 Exception handling 12.6.5 Building the interrupt-driven program 12.7 ARM processor profiles 12.8 Chapter summary Exercises Index

Similar books