Updated Snippet: Manhattan distance (markdown)

Arthur Paulino 2018-01-03 16:05:19 -03:00
parent ff7b76fee0
commit a1cf5139e4

@ -1,8 +1,11 @@
This simple program calculates the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) between the current position of the Cubot and another tile. This simple program calculates the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) between the current position of the Cubot and another tile.
```assembly ```assembly
; Define constants ; Define constants
LIDAR_HW equ 0x0003 ; HWID of the LiDAR HWID_LIDAR equ 0x3
HOLO_HW equ 0x0009 ; HWID of the Hologram projector HWID_HOLO equ 0x9
HOLO_DISPLAY_HEX equ 0x1
LIDAR_GET_POS equ 0x1
; Data segment ; Data segment
.data .data
@ -25,21 +28,21 @@ HOLO_HW equ 0x0009 ; HWID of the Hologram projector
MOV A, 0xABCD MOV A, 0xABCD
counter_is_odd: counter_is_odd:
ADD [counter], 1 ; Increment counter ADD [counter], 1 ; Increment counter
MOV B, A MOV B, A
MOV A, 1 MOV A, HOLO_DISPLAY_HEX
HWI HOLO_HW ; Display the contents of A HWI HWID_HOLO ; Display the contents of A
BRK ; Exit program BRK ; Exit program
;************************************** ;**************************************
;* getPos() ;* getPos()
;* X = X pos ;* X = X pos
;* Y = Y pos ;* Y = Y pos
getPos: getPos:
PUSH A ; Save A PUSH A ; Save A
MOV A, 0x0001 ; GET_POS MOV A, LIDAR_GET_POS
HWI LIDAR_HW ; Send hardware interrupt to the LiDAR HWI HWID_LIDAR ; Send hardware interrupt to the LiDAR
POP A ; Restore A POP A ; Restore A
RET RET