mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-20 19:16:43 +00:00
Updated Snippet: Manhattan distance (markdown)
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.
|
||||
```assembly
|
||||
; Define constants
|
||||
LIDAR_HW equ 0x0003 ; HWID of the LiDAR
|
||||
HOLO_HW equ 0x0009 ; HWID of the Hologram projector
|
||||
HWID_LIDAR equ 0x3
|
||||
HWID_HOLO equ 0x9
|
||||
|
||||
HOLO_DISPLAY_HEX equ 0x1
|
||||
LIDAR_GET_POS equ 0x1
|
||||
|
||||
; Data segment
|
||||
.data
|
||||
@ -25,21 +28,21 @@ HOLO_HW equ 0x0009 ; HWID of the Hologram projector
|
||||
MOV A, 0xABCD
|
||||
|
||||
counter_is_odd:
|
||||
ADD [counter], 1 ; Increment counter
|
||||
ADD [counter], 1 ; Increment counter
|
||||
MOV B, A
|
||||
MOV A, 1
|
||||
HWI HOLO_HW ; Display the contents of A
|
||||
BRK ; Exit program
|
||||
MOV A, HOLO_DISPLAY_HEX
|
||||
HWI HWID_HOLO ; Display the contents of A
|
||||
BRK ; Exit program
|
||||
|
||||
;**************************************
|
||||
;* getPos()
|
||||
;* X = X pos
|
||||
;* Y = Y pos
|
||||
getPos:
|
||||
PUSH A ; Save A
|
||||
MOV A, 0x0001 ; GET_POS
|
||||
HWI LIDAR_HW ; Send hardware interrupt to the LiDAR
|
||||
POP A ; Restore A
|
||||
PUSH A ; Save A
|
||||
MOV A, LIDAR_GET_POS
|
||||
HWI HWID_LIDAR ; Send hardware interrupt to the LiDAR
|
||||
POP A ; Restore A
|
||||
RET
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user