11
Learn by Examples
Arthur Paulino edited this page 2018-01-07 18:12:35 -03:00
; Displaying the hexadecimal 0x000A

HWID_HOLO         EQU 0x9           ; setup constants
HOLO_DISPLAY_HEX  EQU 1
.data
    DISPLAYED_HEX: DW 0x000A        ; create a word in memory called DISPLAYED_HEX and set its value to 0x000A
.text
    MOV A, HOLO_DISPLAY_HEX         ; MOV the constant HOLO_DISPLAY_HEX into register A
    MOV B, [DISPLAYED_HEX]          ; MOV the value inside the memory spot DISPLAYED_HEX into register B
    HWI HWID_HOLO                   ; create an hardware interrupt which will do the magic of displaying
    BRK                             ; halt execution for the rest of this tick
; Displaying the string "hello!"

HWID_HOLO            EQU 0x9             ; setup constants
HOLO_DISPLAY_STRING  EQU 2
.data
    DISPLAYED_STRING: DW "hello!", 0     ; create a string in memory and point to it by DISPLAYED_STRING
                                         ; the ',0' is a null word. This represents the end of the string
.text
    MOV A, HOLO_DISPLAY_STRING           ; MOV the constant HOLO_DISPLAY_STRING into register A
    MOV X, DISPLAYED_STRING              ; MOV the pointer of DISPLAYED_STRING into register B
    HWI HWID_HOLO                        ; do the magic
    BRK                                  ; halt execution until the next tick
; Displaying the decimal 42

HWID_HOLO         EQU 0x9                ; setup constants
HOLO_DISPLAY_DEC  EQU 3
.data
    DISPLAYED_DECIMAL: DW 42             ; create a word in memory called DISPLAYED_DECIMAL and set its value
                                         ; to 42
.text
    MOV A, HOLO_DISPLAY_DEC              ; MOV the constant HOLO_DISPLAY_DEC into register A
    MOV B, [DISPLAYED_DECIMAL]           ; MOV the value inside the memory spot DISPLAYED_HEX into register B
    HWI HWID_HOLO                        ; more magic
    BRK                                  ; halt execution until next tick
; Displaying the decimal 42 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, HOLO_DISPLAY_COLOR            ; MOV the constant HOLO_DISPLAY_COLOR into register A
    MOV B, 0x00FF                        ; MOV the (immediate) value 0x00FF into register B
    MOV C, 0x0000                        ; clear register C: no green and no blue
    HWI HWID_HOLO                        ; this interrupt will set the color to: #FF0000 [B:C] also know as red
    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                        ; ...
    BRK                                  ; halt execution until next tick
; Count from 42 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, HOLO_DISPLAY_COLOR            ; MOV the constant HOLO_DISPLAY_COLOR into register A
    MOV B, 0x00FF                        ; MOV the (immediate) value 0x00FF into register B
    MOV C, 0x0000                        ; clear register C: no green and no blue
    HWI HWID_HOLO                        ; this interrupt will set the color to: #FF0000 [B:C] also know as red
    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                        ; ...
    INC [DISPLAYED_DECIMAL]              ; adds 1 to the value pointed by DISPLAYED_DECIMAL
    BRK                                  ; halt execution until next tick
; 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                        ; ...
    INC [DISPLAYED_DECIMAL]              ; adds 1 to the value pointed by DISPLAYED_DECIMAL
    BRK                                  ; halt execution until next tick