Contents
Chapter 1. 1 Binary Numbers. 13
Chapter 1.1. 1 Values for Binary Numbers. 13
Chapter 1.1. 2 Binary Whole Numbers. 14
Chapter 1. 2 Converting Binary, Decimal, and Hex Numbers. 16
Chapter 1.2. 1 Converting Binary to Decimal 16
Chapter 1.2. 2 Converting Decimal to Binary using Binary Powers. 16
Chapter 1.2. 3 Converting Decimal to Binary using Division. 17
Chapter 1.2. 4 Converting between binary and hexadecimal 18
Chapter 1. 3 Character Representation. 19
Chapter 1. 4 Adding Binary Whole Numbers. 21
Chapter 1. 5 Integer Numbers (2's Complement) 21
Chapter 1.5. 1 What is an Integer 21
Chapter 1.5. 2 2's complement operation and 2's complement format 22
Chapter 1.5. 3 The 2's Complement Operation. 22
Chapter 1.5. 4 The 2's Complement (or Integer) Type. 23
Chapter 1. 6 Integer Arithmetic. 24
Chapter 1.6. 1 Integer Addition. 24
Chapter 1.6. 2 Overflow of Integer Addition. 25
Chapter 1.6. 3 Integer multiplication using bit shift operations. 26
Chapter 1.6. 4 Integer division using bit shift operations. 27
Chapter 1. 7 Boolean Logical and Bitwise Operators. 28
Chapter 1.7. 1 Boolean Operators. 28
Chapter 1.7. 2 Logical and Bitwise Boolean Operators. 29
Chapter 2 First Programs in MIPS assembly. 34
Chapter 2. 1 The MARS IDE.. 34
Chapter 2. 2 MIPS and memory. 35
Chapter 2.2. 1 Types of memory. 36
Chapter 2.2. 2 Overview of a MIPS CPU.. 36
Chapter 2.2. 4 Types of memory. 40
Chapter 2. 3 First program in MIPS assembly. 41
Chapter 2.3. 1 Program 2-1 Commentary. 43
Chapter 2. 4 Program to prompt and read an integer from a user 45
Chapter 2.4. 1 Program 2-2 Commentary. 46
Chapter 2. 5 Program to prompt and read a string from a user 46
Chapter 2.5. 1 Program 2-3 Commentary. 47
Chapter 2. 7 Java program for call by value and reference. 51
Chapter 3 MIPS arithmetic and Logical Operators. 53
Chapter 3. 1 3-Address machines. 53
Chapter 3. 2 Addition in MIPS assembly. 55
Chapter 3.2. 1 Addition operators. 55
Chapter 3.2. 2 Addition Examples. 56
Chapter 3.2. 3 Introduction to pseudo code. 58
Chapter 3.2. 4 Assembly language addition program.. 59
Chapter 3.2. 5 Assembly language addition program commentary. 60
Chapter 3. 3 Subtraction in MIPS assembly. 61
Chapter 3. 4 Multiplication in MIPS assembly. 62
Chapter 3. 5 Division in MIPS Assembly. 64
Chapter 3.5. 1 Remainder operator, even/odd number checker 66
Chapter 3.5. 2 Remainder operator, even/odd number checker 66
Chapter 3. 6 Solving arithmetic expressions in MIPS assembly. 67
Chapter 3. 7 Division and accuracy of an equation. 68
Chapter 3. 8 Logical operators. 69
Chapter 3. 9 Using logical operators. 72
Chapter 3.9. 1 Storing immediate values in registers. 72
Chapter 3.9. 2 Converting a character from upper case to lower case. 72
Chapter 3.9. 3 Reversible operations with XOR.. 73
Chapter 3. 10 Shift Operations. 74
Chapter 3.10. 1 Program illustrating shift operations. 77
Chapter 4 Translating Assembly Language into Machine Code. 82
Chapter 4. 1 Instruction formats. 82
Chapter 4. 2 Machine code for the add instruction. 84
Chapter 4. 3 Machine code for the sub instruction. 85
Chapter 4. 4 Machine code for the addi instruction. 85
Chapter 4. 5 Machine code for the sll instruction. 86
Chapter 5 Simple MIPS subprograms. 89
Chapter 5. 1 Exit Subprogram.. 89
Chapter 5.1. 1 Commentary on Exit subprogram.. 90
Chapter 5. 2 PrintNewLine subprogram.. 91
Chapter 5.2. 1 Commentary on Exit subprogram.. 92
Chapter 5. 3 The Program Counter ($pc) register and calling a subprogram.. 93
Chapter 5. 4 Returning from a subprogram and the $ra register 96
Chapter 5. 5 Input parameter with PrintString subprogram.. 97
Chapter 5. 6 Multiple input parameters with PrintInt subprogram.. 99
Chapter 5. 7 Return values with PromptInt subprogram.. 101
Chapter 5. 8 Create a utils.asm file. 103
Chapter 5. 9 Final program to prompt, read, and print an integer 105
Chapter 6 MIPS memory - the data segment 109
Chapter 6. 1 Flat memory model 109
Chapter 6. 3 Accessing memory. 113
Chapter 6. 4 Methods of accessing memory. 114
Chapter 6.4. 1 Addressing by label 115
Chapter 6.4. 2 Register direct access. 116
Chapter 6.4. 3 Register indirect access. 117
Chapter 6.4. 4 Register offset access. 118
Chapter 7 Assembly language program control structures. 122
Chapter 7. 1 Use of goto statements. 123
Chapter 7. 2 Simple if statements. 124
Chapter 7.2. 1 Simple if statements in pseudo code. 124
Chapter 7.2. 2 Simple if statement translated to assembly. 124
Chapter 7.2. 3 Simple if statement with complex logical conditions. 125
Chapter 7. 3 if-else statements. 126
Chapter 7. 4 if-elseif-else statements. 128
Chapter 7.5. 1 Sentinel control loop. 131
Chapter 7.5. 2 Counter control loop. 132
Chapter 7. 6 Nested code blocks. 134
Chapter 7. 7 A full assembly language program.. 136
Chapter 7. 8 How to calculate branch amounts in machine code. 140
Chapter 7.8. 1 Instruction Addresses. 140
Chapter 7.8. 2 Value in the $pc register 141
Chapter 7.8. 3 How the word boundary effects branching. 142
Chapter 7.8. 4 Translating branch instructions to machine code. 143
Chapter 7.8. 5 PC relative addressing. 145
Chapter 8 Reentrant Subprograms. 149
Chapter 8.1. 1 Stack data structure: definition. 149
Chapter 8.1. 2 Another stack implementation. 151
Chapter 8. 2 The program stack. 152
Chapter 8.2. 1 The non-reentrant subprogram problem.. 152
Chapter 8.2. 2 Making subprograms re-entrant 155
Chapter 8.3. 1 Recursive multiply in a HLL.. 158
Chapter 9. 1 Heap dynamic memory. 161
Chapter 9.1. 1 What is heap memory. 161
Chapter 9.1. 2 Allocating heap memory example – PromptString subprogram.. 162
Chapter 9.1. 3 Commentary on PromptString Subprogram.. 163
Chapter 9. 2 Array Definition and creation in Assembly. 164
Chapter 9.2. 1 Allocating arrays in memory. 166
Chapter 9. 3 Printing an Array. 167
Chapter 9.3. 1 Bubble Sort in MIPS assembly. 170