added colorful counting example

Arthur Paulino 2018-01-07 15:51:10 -03:00
parent 47995c9580
commit f1bf1cbb5a

@ -1,5 +1,6 @@
```assembly
; Displaying the hexadecimal 0x000A
HWID_HOLO EQU 0x9 ; setup constants
HOLO_DISPLAY_HEX EQU 1
.data
@ -12,6 +13,7 @@ HOLO_DISPLAY_HEX EQU 1
```
```assembly
; Displaying the string "hello!"
HWID_HOLO EQU 0x9 ; setup constants
HOLO_DISPLAY_STRING EQU 2
.data
@ -25,6 +27,7 @@ HOLO_DISPLAY_STRING EQU 2
```
```assembly
; Displaying the decimal 42
HWID_HOLO EQU 0x9 ; setup constants
HOLO_DISPLAY_DEC EQU 3
.data
@ -38,6 +41,7 @@ HOLO_DISPLAY_DEC EQU 3
```
```assembly
; Displaying the decimal 42 in red
HWID_HOLO EQU 0x9 ; setup constants
HOLO_DISPLAY_DEC EQU 3
HOLO_DISPLAY_COLOR EQU 4
@ -56,6 +60,7 @@ HOLO_DISPLAY_COLOR EQU 4
```
```assembly
; Count from 42 in red
HWID_HOLO EQU 0x9 ; setup constants
HOLO_DISPLAY_DEC EQU 3
HOLO_DISPLAY_COLOR EQU 4
@ -72,4 +77,40 @@ HOLO_DISPLAY_COLOR EQU 4
HWI HWID_HOLO ; ...
ADD [DISPLAYED_DECIMAL], 1 ; adds 1 to the value pointed by DISPLAYED_DECIMAL
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
```