some renaming

This commit is contained in:
Perry Kivolowitz 2022-06-07 15:42:56 -05:00
parent d99e803796
commit 4693db4ded
3 changed files with 32 additions and 9 deletions

View file

@ -1,3 +1,14 @@
```asm
// Assume value of a is in x0 // 1
// Assume value of b is in x1 // 2
// 3
1: cmp x0, x1 // 4
b 2f // 5
// CODE BLOCK // 6
b 1b // 7
// 8
2: // 9
```
# Assembly Language Programming Made Not So Scary
This text book provides a fairly thorough examination of the ARM V8 ISA (Instruction Set Architecture).
@ -45,7 +56,7 @@ the 64 bit ARM Instruction Set Architecture (ISA).
| 1 | [Hello World](./section_1/hello_world/README.md) |
| 2 | [If Statements](./section_1/if/README.md) |
| 3 | [While Loops](./section_1/while/README.md) |
| 4 | [For Loops](./section_1/for/README.md) |
| 4 | [For Loops, Continue and Break](./section_1/for/README.md) |
| 5 | [Interlude - Registers](./section_1/regs/README.md) |
| 6 | [Interlude - Load and Store](./section_1/regs/ldr.md) |
| 7 | [Calling and Returning From Functions](./section_1/funcs/README.md) |

View file

@ -1,4 +1,4 @@
# Section 1 / Chapter 4 / For Loops
# Section 1 / Chapter 4 / For Loops, Continue and Break
## Overview
@ -78,7 +78,15 @@ Notice this contains one fewer lines of assembly language within the loop itself
## Implementing a `continue`
Now let's add a `continue` to the code block, dividing it in two.
Now let's add a `continue` to the code block, dividing it in two.
```c
for (long i = 0; i < 10; i++) {
// CODE BLOCK "A"
if (i == 5)
continue;
// CODE BLOCK "B"
}
Here is what we would need to write to support a `continue` if the "conventional" ordering were used with the decision evaluation at the top:
@ -90,7 +98,7 @@ Here is what we would need to write to support a `continue` if the "conventional
1: cmp x0, 10 // 5
bge 3f // 6
// 7
// FIRST PART OF CODE BLOCK // 8
// CODE BLOCK "A" // 8
// 9
// if (i == 5) // 10
// continue // 11
@ -98,7 +106,7 @@ Here is what we would need to write to support a `continue` if the "conventional
cmp x0, 5 // 13
beq 2f // 14
// 15
// REMAINDER OF CODE BLOCK // 16
// CODE BLOCK "B" // 16
// 17
2: add x0, x0, 1 // 18
b 1b // 19
@ -118,7 +126,7 @@ Below, is how a `for` loop is **typically** implemented.
// 5
1: // 6
// 7
// FIRST PART OF CODE BLOCK // 8
// CODE BLOCK "A" // 8
// 9
// if (i == 5) // 10
// continue // 11
@ -126,7 +134,7 @@ Below, is how a `for` loop is **typically** implemented.
cmp x0, 5 // 13
beq 2f // 14
// 15
// REMAINDER OF CODE BLOCK // 16
// CODE BLOCK "B" // 16
// 17
2: add x0, x0, 1 // 18
3: cmp x0, 10 // 19
@ -137,6 +145,10 @@ Below, is how a `for` loop is **typically** implemented.
Once again, the code moving the post step and decision evaluation to the bottom is one fewer instruction inside the loop.
## Implementing a `break`
LEFT OFF HERE
## Summary
`for` loops typically contain code ordering different from what one might expect. This is done to save an instruction within the loop. While this doesn't sound like much, consider the case where the loop is executed billions of times. In this case, saving one instruction per loop prevents the execution of a billion instructions. The shorter the code block is, the more important it is to save one instruction from within the loop.

View file

@ -5,7 +5,7 @@
1: cmp x0, 10
bge 3f
// FIRST PART OF CODE BLOCK
// CODE BLOCK "A"
// if (i == 5)
// continue
@ -13,7 +13,7 @@
cmp x0, 5
beq 2f
// REMAINDER OF CODE BLOCK
// CODE BLOCK "B"
2: add x0, x0, 1
b 1b