mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 10:36:43 +00:00
added colorful counting example
parent
47995c9580
commit
f1bf1cbb5a
@ -1,5 +1,6 @@
|
|||||||
```assembly
|
```assembly
|
||||||
; Displaying the hexadecimal 0x000A
|
; Displaying the hexadecimal 0x000A
|
||||||
|
|
||||||
HWID_HOLO EQU 0x9 ; setup constants
|
HWID_HOLO EQU 0x9 ; setup constants
|
||||||
HOLO_DISPLAY_HEX EQU 1
|
HOLO_DISPLAY_HEX EQU 1
|
||||||
.data
|
.data
|
||||||
@ -12,6 +13,7 @@ HOLO_DISPLAY_HEX EQU 1
|
|||||||
```
|
```
|
||||||
```assembly
|
```assembly
|
||||||
; Displaying the string "hello!"
|
; Displaying the string "hello!"
|
||||||
|
|
||||||
HWID_HOLO EQU 0x9 ; setup constants
|
HWID_HOLO EQU 0x9 ; setup constants
|
||||||
HOLO_DISPLAY_STRING EQU 2
|
HOLO_DISPLAY_STRING EQU 2
|
||||||
.data
|
.data
|
||||||
@ -25,6 +27,7 @@ HOLO_DISPLAY_STRING EQU 2
|
|||||||
```
|
```
|
||||||
```assembly
|
```assembly
|
||||||
; Displaying the decimal 42
|
; Displaying the decimal 42
|
||||||
|
|
||||||
HWID_HOLO EQU 0x9 ; setup constants
|
HWID_HOLO EQU 0x9 ; setup constants
|
||||||
HOLO_DISPLAY_DEC EQU 3
|
HOLO_DISPLAY_DEC EQU 3
|
||||||
.data
|
.data
|
||||||
@ -38,6 +41,7 @@ HOLO_DISPLAY_DEC EQU 3
|
|||||||
```
|
```
|
||||||
```assembly
|
```assembly
|
||||||
; Displaying the decimal 42 in red
|
; Displaying the decimal 42 in red
|
||||||
|
|
||||||
HWID_HOLO EQU 0x9 ; setup constants
|
HWID_HOLO EQU 0x9 ; setup constants
|
||||||
HOLO_DISPLAY_DEC EQU 3
|
HOLO_DISPLAY_DEC EQU 3
|
||||||
HOLO_DISPLAY_COLOR EQU 4
|
HOLO_DISPLAY_COLOR EQU 4
|
||||||
@ -56,6 +60,7 @@ HOLO_DISPLAY_COLOR EQU 4
|
|||||||
```
|
```
|
||||||
```assembly
|
```assembly
|
||||||
; Count from 42 in red
|
; Count from 42 in red
|
||||||
|
|
||||||
HWID_HOLO EQU 0x9 ; setup constants
|
HWID_HOLO EQU 0x9 ; setup constants
|
||||||
HOLO_DISPLAY_DEC EQU 3
|
HOLO_DISPLAY_DEC EQU 3
|
||||||
HOLO_DISPLAY_COLOR EQU 4
|
HOLO_DISPLAY_COLOR EQU 4
|
||||||
@ -73,3 +78,39 @@ HOLO_DISPLAY_COLOR EQU 4
|
|||||||
ADD [DISPLAYED_DECIMAL], 1 ; adds 1 to the value pointed by DISPLAYED_DECIMAL
|
ADD [DISPLAYED_DECIMAL], 1 ; adds 1 to the value pointed by DISPLAYED_DECIMAL
|
||||||
BRK ; halt execution until next tick
|
BRK ; halt execution until next tick
|
||||||
```
|
```
|
||||||
|
```assembly
|
||||||
|
; Count from 42. Even numbers are displayed in blue and odd numbers, in red
|
||||||
|
|
||||||
|
HWID_HOLO EQU 0x9 ; setup constants
|
||||||
|
HOLO_DISPLAY_DEC EQU 3
|
||||||
|
HOLO_DISPLAY_COLOR EQU 4
|
||||||
|
.data
|
||||||
|
DISPLAYED_DECIMAL: DW 42 ; create a word in memory called DISPLAYED_DECIMAL and set its value
|
||||||
|
; to 42
|
||||||
|
.text
|
||||||
|
MOV A, [DISPLAYED_DECIMAL] ; preparing to divide [DISPLAYED_DECIMAL] by 2
|
||||||
|
DIV 2 ; divide the value at A by 2: the result goes to A and the remainder goes to Y
|
||||||
|
|
||||||
|
MOV A, HOLO_DISPLAY_COLOR ; MOV the constant HOLO_DISPLAY_COLOR into register A
|
||||||
|
; the result of the division doesn't matter
|
||||||
|
|
||||||
|
CMP Y, 0 ; checks if the remainder is 0
|
||||||
|
JZ set_blue ; if the remainder is 0, set the color blue
|
||||||
|
JMP set_red ; this line is executed only if the the remainder was NOT 0
|
||||||
|
|
||||||
|
set_blue:
|
||||||
|
MOV B, 0x0000 ; clear register B: no red
|
||||||
|
MOV C, 0x00FF ; MOV the (immediate) value 0x00FF into register C
|
||||||
|
JMP color_set ; skip the set_red segment
|
||||||
|
set_red:
|
||||||
|
MOV B, 0x00FF ; MOV the (immediate) value 0x00FF into register B
|
||||||
|
MOV C, 0x0000 ; clear register C: no green and no blue
|
||||||
|
color_set:
|
||||||
|
HWI HWID_HOLO ; send the interrupt to the holograp projector to set its display color
|
||||||
|
|
||||||
|
MOV A, HOLO_DISPLAY_DEC ; MOV the constant HOLO_DISPLAY_DEC into register A
|
||||||
|
MOV B, [DISPLAYED_DECIMAL] ; MOV the value that DISPLAYED_DECIMAL is pointing at into register B
|
||||||
|
HWI HWID_HOLO ; ...
|
||||||
|
ADD [DISPLAYED_DECIMAL], 1 ; adds 1 to the value pointed by DISPLAYED_DECIMAL
|
||||||
|
BRK ; halt execution until next tick
|
||||||
|
```
|
Loading…
x
Reference in New Issue
Block a user