diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-11-02 23:22:31 -0400 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-11-02 23:22:31 -0400 |
commit | 0948e83a85e1a5eed3383b8386ecd0890056010a (patch) | |
tree | a27a05d268cb6bee808fc0435ac957ba0458569d | |
parent | a174adffb01d711e540f664c3edf83c7bb6f750e (diff) |
dec a then AddNTimes
-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 +``` |