Skip to content

Commit 2c7250c

Browse files
committed
Revert "Document the jr instruction and use it in hello-world.asm (#151)"
This reverts commit 566c5ca.
1 parent 02b2a2d commit 2c7250c

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/assets/hello-world.asm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ EntryPoint:
1919
WaitVBlank:
2020
ld a, [rLY]
2121
cp 144
22-
jr c, WaitVBlank
22+
jp c, WaitVBlank
2323

2424
; Turn the LCD off
2525
ld a, 0
@@ -39,7 +39,7 @@ CopyTiles:
3939
dec bc
4040
ld a, b
4141
or a, c
42-
jr nz, CopyTiles
42+
jp nz, CopyTiles
4343
; ANCHOR_END: memcpy
4444

4545
; Copy the tilemap
@@ -53,7 +53,7 @@ CopyTilemap:
5353
dec bc
5454
ld a, b
5555
or a, c
56-
jr nz, CopyTilemap
56+
jp nz, CopyTilemap
5757

5858
; Turn the LCD on
5959
ld a, LCDC_ON | LCDC_BG_ON
@@ -66,7 +66,7 @@ CopyTilemap:
6666
; ANCHOR_END: bgp_write
6767

6868
Done:
69-
jr Done
69+
jp Done
7070

7171

7272
SECTION "Tile data", ROM0

src/part1/jumps.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ There are four of them:
2727
| Call | `call` | Call a subroutine |
2828
| Return | `ret` | Return from a subroutine |
2929

30-
We will focus on the first two, `jp` and `jr`, for now.
31-
32-
`jp`, such as the one on line {{#line_no_of "^\s*jp" ../assets/hello-world.asm}}, simply sets PC to its argument, jumping execution there.
30+
We will focus on `jp` for now.
31+
`jp`, such as the one line {{#line_no_of "^\s*jp" ../assets/hello-world.asm}}, simply sets PC to its argument, jumping execution there.
3332
In other words, after executing `jp EntryPoint` (line {{#line_no_of "^\s*jp EntryPoint" ../assets/hello-world.asm}}), the next instruction executed is the one below `EntryPoint` (line <!-- should be {{#line_no_of "^\s*EntryPoint:" ../assets/hello-world.asm}} + 1 --> 11).
3433

3534
:::tip:🤔
@@ -39,8 +38,6 @@ Don't worry, we will see later why it's required.
3938

4039
:::
4140

42-
`jr`, such as the one on line {{#line_no_of "^\s*jr" ../assets/hello-world.asm}}, is functionally the same as `jp`. However, it sets PC *relative* to the current PC value, and can only jump execution forward or backward by 128 bytes---a short distance given that each instruction takes one to three bytes. The advantage of `jr` is that it takes up two bytes instead of three like `jp` (since it encodes a one-byte relative distance instead of a two-byte absolute address), and also takes one CPU cycle less than `jp` to execute, so it's commonly used when you know that a jump will be short.
43-
4441
## Conditional jumps
4542

4643
Now to the _really_ interesting part.
@@ -97,7 +94,7 @@ There are four "conditions":
9794
| Carry | `c` | C is set (last operation overflowed) |
9895
| No carry | `nc` | C is not set (last operation did not overflow) |
9996

100-
Thus, `jr nz, CopyTiles` can be read as "if the Z flag is not set, then jump to `CopyTiles`".
97+
Thus, `jp nz, CopyTiles` can be read as "if the Z flag is not set, then jump to `CopyTiles`".
10198
Since we're jumping _backwards_, we will repeat the instructions again: we have just created a **loop**!
10299

103100
Okay, we've been talking about the code a lot, and we have seen it run, but we haven't really seen _how_ it runs.

0 commit comments

Comments
 (0)