diff options
-rw-r--r-- | Optimizing-assembly-code.md | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Optimizing-assembly-code.md b/Optimizing-assembly-code.md index 2ff7153..fd5b7b5 100644 --- a/Optimizing-assembly-code.md +++ b/Optimizing-assembly-code.md @@ -67,6 +67,7 @@ WikiTI's advice fully applies here: - [Enable interrupts and return](#enable-interrupts-and-return) - [Jump and lookup tables](#jump-and-lookup-tables) - [Chain comparisons](#chain-comparisons) + - [Off-by-one `AddNTimes`](#off-by-one-addntimes) ## 8-bit registers @@ -2069,3 +2070,23 @@ JumpTable:: pop de jp hl ``` + + +### Off-by-one `AddNTimes` + +Don't do this: + +```asm + ld hl, Foo + ld bc, BAR + dec a + call AddNTimes +``` + +Instead, as long as you don't need to add 255 times when a is 0, then do this: + +```asm + ld hl, Foo - BAR + ld bc, BAR + call AddNTimes +``` |