An introduction to assembly programming with RISC-V

دانلود کتاب An introduction to assembly programming with RISC-V

55000 تومان موجود

کتاب مقدمه ای بر برنامه نویسی اسمبلی با RISC-V نسخه زبان اصلی

دانلود کتاب مقدمه ای بر برنامه نویسی اسمبلی با RISC-V بعد از پرداخت مقدور خواهد بود
توضیحات کتاب در بخش جزئیات آمده است و می توانید موارد را مشاهده فرمایید


این کتاب نسخه اصلی می باشد و به زبان فارسی نیست.


امتیاز شما به این کتاب (حداقل 1 و حداکثر 5):

امتیاز کاربران به این کتاب:        تعداد رای دهنده ها: 13


توضیحاتی در مورد کتاب An introduction to assembly programming with RISC-V

نام کتاب : An introduction to assembly programming with RISC-V
عنوان ترجمه شده به فارسی : مقدمه ای بر برنامه نویسی اسمبلی با RISC-V
سری :
نویسندگان :
ناشر :
سال نشر :
تعداد صفحات : 151
ISBN (شابک) : 9786500158113
زبان کتاب : English
فرمت کتاب : pdf
حجم کتاب : 5 مگابایت



بعد از تکمیل فرایند پرداخت لینک دانلود کتاب ارائه خواهد شد. درصورت ثبت نام و ورود به حساب کاربری خود قادر خواهید بود لیست کتاب های خریداری شده را مشاهده فرمایید.


فهرست مطالب :


Contents
Foreword 4
Glossary 11
Acronyms 14
I Introduction to computer systems and assembly language
1
1 Execution of programs: a 10,000 ft overview 2
1.1 Main components of computers . . . . . . . . . . . . . . . . . . . . . . 2
1.1.1 The main memory . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 The CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Executing program instructions . . . . . . . . . . . . . . . . . . . . . . 4
1.3 The boot process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Data representation on modern computers 6
2.1 Numeral Systems and the Positional Notation . . . . . . . . . . . . . . 6
2.1.1 Converting numbers between bases . . . . . . . . . . . . . . . . 8
2.2 Representing numbers on computers . . . . . . . . . . . . . . . . . . . 11
2.2.1 Unsigned numbers . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.2 Signed numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.3 Binary arithmetic and Overflow . . . . . . . . . . . . . . . . . . 14
2.2.4 Integer Overflow . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 Representing text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 Organizing data on the memory . . . . . . . . . . . . . . . . . . . . . . 18
2.4.1 Texts on the main memory . . . . . . . . . . . . . . . . . . . . 18
2.4.2 Numbers on the main memory . . . . . . . . . . . . . . . . . . 19
2.4.3 Arrays on the main memory . . . . . . . . . . . . . . . . . . . . 19
2.4.4 Structs on the main memory . . . . . . . . . . . . . . . . . . . 21
2.5 Encoding instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3 Assembly, object, and executable files 24
3.1 Generating native programs . . . . . . . . . . . . . . . . . . . . . . . . 24
3.1.1 Inspecting the contents of object and executable files . . . . . . 26
3.2 Labels, symbols, references, and relocation . . . . . . . . . . . . . . . . 27
3.2.1 Labels and symbols . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2.2 References to labels and relocation . . . . . . . . . . . . . . . . 28
3.2.3 Undefined references . . . . . . . . . . . . . . . . . . . . . . . . 30
3.2.4 Global vs local symbols . . . . . . . . . . . . . . . . . . . . . . 31
3.2.5 The program entry point . . . . . . . . . . . . . . . . . . . . . 32
3.3 Program sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.4 Executable vs object files . . . . . . . . . . . . . . . . . . . . . . . . . 36
6
4 Assembly language 37
4.1 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2 Assembly instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.3 Immediate values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.4 Symbol names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.5 Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.6 The location counter and the assembling process . . . . . . . . . . . . 42
4.7 Assembly directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.7.1 Adding values to the program . . . . . . . . . . . . . . . . . . . 44
4.7.2 The .section directive . . . . . . . . . . . . . . . . . . . . . . 46
4.7.3 Allocating variables on the .bss section . . . . . . . . . . . . . 47
4.7.4 The .set and .equ directives . . . . . . . . . . . . . . . . . . . 48
4.7.5 The .globl directive . . . . . . . . . . . . . . . . . . . . . . . . 49
4.7.6 The .align directive . . . . . . . . . . . . . . . . . . . . . . . . 49
II User-level programming 51
5 Introduction 52
6 The RV32I ISA 53
6.1 Datatypes and memory organization . . . . . . . . . . . . . . . . . . . 54
6.2 RV32I registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.3 Load/Store architecture . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.4 Pseudo-instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
6.5 Logic, shift, and arithmetic instructions . . . . . . . . . . . . . . . . . 56
6.5.1 Instructions syntax and operands . . . . . . . . . . . . . . . . . 57
6.5.2 Dealing with large immediate values . . . . . . . . . . . . . . . 57
6.5.3 Logic instructions . . . . . . . . . . . . . . . . . . . . . . . . . 58
6.5.4 Shift instructions . . . . . . . . . . . . . . . . . . . . . . . . . . 59
6.5.5 Arithmetic instructions . . . . . . . . . . . . . . . . . . . . . . 61
6.6 Data movement instructions . . . . . . . . . . . . . . . . . . . . . . . . 63
6.6.1 Load instructions . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.6.2 Store instructions . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.6.3 Data movement pseudo-instructions . . . . . . . . . . . . . . . 68
6.7 Control-flow instructions . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.7.1 Conditional control-flow instructions . . . . . . . . . . . . . . . 69
6.7.2 Direct vs indirect control-flow instructions . . . . . . . . . . . 71
6.7.3 Unconditional control-flow instructions . . . . . . . . . . . . . . 72
6.7.4 System Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.8 Conditional set instructions . . . . . . . . . . . . . . . . . . . . . . . . 74
6.9 Detecting overflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
6.10 Arithmetic on multi-word variables . . . . . . . . . . . . . . . . . . . . 75
7 Controlling the execution flow 77
7.1 Conditional statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.1.1 if-then statements . . . . . . . . . . . . . . . . . . . . . . . . 77
7.1.2 Comparing signed vs unsigned variables . . . . . . . . . . . . . 77
7.1.3 if-then-else statements . . . . . . . . . . . . . . . . . . . . . 78
7.1.4 Handling non-trivial boolean expressions . . . . . . . . . . . . . 79
7.1.5 Nested if statements . . . . . . . . . . . . . . . . . . . . . . . . 80
7.2 Repetition statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.2.1 while loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.2.2 do-while loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.2.3 for loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
7.2.4 Hoisting loop-invariant code . . . . . . . . . . . . . . . . . . . . 83
7.3 Invoking and returning from routines . . . . . . . . . . . . . . . . . . . 83
7.3.1 Returning values from functions . . . . . . . . . . . . . . . . . 84
7.4 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
7
7.4.1 Searching for the maximum value on an array . . . . . . . . . . 85
8 Implementing routines 87
8.1 The program memory layout . . . . . . . . . . . . . . . . . . . . . . . 87
8.2 The program stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8.2.1 Types of stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.3 The ABI and software composition . . . . . . . . . . . . . . . . . . . . 91
8.4 Passing parameters to and returning values from routines . . . . . . . 91
8.4.1 Passing parameters to routines . . . . . . . . . . . . . . . . . . 91
8.4.2 Returning values from routines . . . . . . . . . . . . . . . . . . 93
8.5 Value and reference parameters . . . . . . . . . . . . . . . . . . . . . . 93
8.6 Global vs local variables . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.6.1 Allocating local variables on memory . . . . . . . . . . . . . . . 96
8.7 Register usage policies . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
8.7.1 Caller-saved vs Callee-saved registers . . . . . . . . . . . . . . . 99
8.7.2 Saving and restoring the return address . . . . . . . . . . . . . 100
8.8 Stack Frames and the Frame Pointer . . . . . . . . . . . . . . . . . . . 100
8.8.1 Stack Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
8.8.2 The Frame Pointer . . . . . . . . . . . . . . . . . . . . . . . . . 101
8.8.3 Keeping the stack pointer aligned . . . . . . . . . . . . . . . . . 102
8.9 Implementing RISC-V ilp32 compatible routines . . . . . . . . . . . . 102
8.10 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
8.10.1 Recursive routines . . . . . . . . . . . . . . . . . . . . . . . . . 103
8.10.2 The standard “C” library syscall routines . . . . . . . . . . . . 104
III System-level programming 106
9 Accessing peripherals 107
9.1 Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
9.2 Interacting with peripherals . . . . . . . . . . . . . . . . . . . . . . . . 108
9.2.1 Port-mapped I/O . . . . . . . . . . . . . . . . . . . . . . . . . . 109
9.2.2 Memory-mapped I/O . . . . . . . . . . . . . . . . . . . . . . . 110
9.3 I/O operations on RISC-V . . . . . . . . . . . . . . . . . . . . . . . . . 111
9.4 Busy waiting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
10 External Interrupts 114
10.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
10.1.1 Polling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
10.2 External Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
10.2.1 Detecting external interrupts . . . . . . . . . . . . . . . . . . . 117
10.2.2 Invoking the proper interrupt service routine . . . . . . . . . . 118
10.3 Interrupts on RV32I . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
10.3.1 Control and Status Registers . . . . . . . . . . . . . . . . . . . 120
10.3.2 Interrupt related Control and Status Registers . . . . . . . . . 121
10.3.3 Interrupt Handling Flow . . . . . . . . . . . . . . . . . . . . . . 122
10.3.4 Implementing an interrupt service routine . . . . . . . . . . . . 123
10.3.5 Setting up the Interrupt Handling Mechanism . . . . . . . . . . 124
11 Software Interrupts and Exceptions 127
11.1 Privilege Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
11.2 Protecting the system . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
11.3 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
11.4 Software Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
11.5 Protecting RISC-V systems . . . . . . . . . . . . . . . . . . . . . . . . 130
11.5.1 Changing the privilege mode . . . . . . . . . . . . . . . . . . . 130
11.5.2 Configuring the exception and software interrupt mechanisms . 131
11.5.3 Handling illegal operations . . . . . . . . . . . . . . . . . . . . 131
11.5.4 Handling system calls . . . . . . . . . . . . . . . . . . . . . . . 132
8
A RV32IM ISA reference card 134




پست ها تصادفی