Skip to content

Use swap in stead of 4 rotations in BCD lesson #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/part2/bcd.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ First we load the score (stored in the wScore memory location) into register A.

The `and %11110000` operation masks the lower nibble (the ones digit) so that only the upper nibble (the tens digit) remains in `A`.

The `rrca` instructions perform a rotate right operation on `A` four times. This effectively shifts the tens digit to the lower nibble, making it ready to map to a digit tile.
The `swap a` instruction swaps the upper nibble with the lower four bits, leaving the tens digit ready for us to display.

We then add the `DIGIT_OFFSET` constant to the tens digit to calculate the tile address for the digit. This address is stored in the `SCORE_TENS` VRAM location, which updates the display to show the tens digit.

Expand Down
5 changes: 1 addition & 4 deletions unbricked/bcd/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,7 @@ IncreaseScorePackedBCD:
UpdateScoreBoard:
ld a, [wScore] ; Get the Packed score
and %11110000 ; Mask the lower nibble
rrca ; Move the upper nibble to the lower nibble (divide by 16)
rrca
rrca
rrca
swap a ; Move the upper nibble to the lower nibble (divide by 16)
add a, DIGIT_OFFSET ; Offset + add to get the digit tile
ld [SCORE_TENS], a ; Show the digit on screen

Expand Down