sd:part_ii_writing_games_in_assembly_language
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sd:part_ii_writing_games_in_assembly_language [2026/04/02 20:00] – appledog | sd:part_ii_writing_games_in_assembly_language [2026/04/03 05:30] (current) – appledog | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| == Introduction | == Introduction | ||
| - | At the end of [[SD-8516 Stellar BASIC]] we wrote a game called [[sdb: | + | At the end of [[SD-8516 Stellar BASIC]] we wrote a game called [[sdb: |
| == Part 1: Assembling and Running a Program | == Part 1: Assembling and Running a Program | ||
| - | An assembly language program should start with an .address | + | Just like BASIC programs have line numbers, or C programs have #include statements, an assembly language program should start with an '' |
| <codify armasm> | <codify armasm> | ||
| Line 280: | Line 280: | ||
| The second compare has a protective function. | The second compare has a protective function. | ||
| - | CMP AL, #123 | + | CMP AL, #123 ; if AL >= 123, set carry. |
| + | |||
| ; If it's ' | ; If it's ' | ||
| JC @gi_check_keys | JC @gi_check_keys | ||
| Line 294: | Line 294: | ||
| | >= 123 | after ' | | >= 123 | after ' | ||
| + | === Processing player input | ||
| + | We will use the HJKL convention: | ||
| + | |||
| + | <codify armasm> | ||
| + | gi_check_keys: | ||
| + | CMP AL, #' | ||
| + | JZ @move_left | ||
| + | |||
| + | CMP AL, #' | ||
| + | JZ @move_down | ||
| + | |||
| + | CMP AL, #' | ||
| + | JZ @move_up | ||
| + | |||
| + | CMP AL, #' | ||
| + | JZ @move_right | ||
| + | |||
| + | CMP AL, #' | ||
| + | JZ @quit_game | ||
| + | |||
| + | RET | ||
| + | </ | ||
| + | |||
| + | This is easy enough; after a CMP, if the values are equal then the zero flag is set. We will use JZ (jump if zero flag is set) to go to the correct routine. | ||
| + | |||
| + | === processing each command | ||
| + | <codify armasm> | ||
| + | move_left: | ||
| + | LDAL [@PX] ; load variable PX into register AL. | ||
| + | DEC AL ; X = X - 1 (move to the left!) | ||
| + | | ||
| + | CMP AL, #1 ; bounds check. Is the player on the border? | ||
| + | JC @ml_ok | ||
| + | | ||
| + | LDAL #1 ; If we reach here the player was on the border; set position to 1. | ||
| + | | ||
| + | ml_ok: | ||
| + | STAL [@PX] ; pass! Save the player' | ||
| + | RET | ||
| + | </ | ||
| + | |||
| + | This is the move_left command. We begin by loading the player' | ||
sd/part_ii_writing_games_in_assembly_language.1775160048.txt.gz · Last modified: by appledog
