drive/solve/solve.s
2022-07-13 07:13:58 -04:00

141 lines
2.7 KiB
ArmAsm

; vim: ft=nasm
%macro i_nop 0
db 0x00
%endmacro
%define np i_nop
%macro i_halt 1
db 0x01
db %1
%endmacro
%define ht i_halt
; load <mem> <value>
%macro i_load 2
db 0x10
db %1
db %2
%endmacro
%define ld i_load
; send <device> <mem>
%macro i_send 2
db 0x20
db %1
db %2
%endmacro
%define sd i_send
; get <mem> <device>
%macro i_get 2
db 0x21
db %1
db %2
%endmacro
%define gt i_get
; jlt <a>, <b>, <loc>
; a < b
%macro i_less 3
db 0x50
db %1
db %2
db %3
%endmacro
%define jl i_less
; jle <a>, <b>, <loc>
; a <= b
%macro i_leq 3
db 0x51
db %1
db %2
db %3
%endmacro
%define le i_leq
%define inp 0
%define disp 1
%define arith 2
%define tape 3
gt 0x00, inp
gt 0x01, inp
gt 0x02, inp
gt 0x03, inp
; [a, b, c, d] -> mem
sd tape, 0x00
sd tape, 0x01
sd tape, 0x02
sd tape, 0x03
; {a, b, c, d}
; [i[0], i[1], i[2], i[3] + i[0]]
; - add i[3] and i[0]
; [i[0], i[1], i[2], (i[3] + i[0]) ^ i[1]]
; - xor i[1] with i[3] + i[0], pop from arith
; [i[0] + i[1], i[1], i[2], (i[3] + i[0]) ^ i[1]]
; - add i[0] and i[1], pop from arith
; [i[0] + i[1], i[1], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - xor i[0] + i[1] with i[2], pop from arith
; [i[2], i[1], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - xor (i[0] + i[1]) ^ i[2] with i[0] + i[1], pop from arith
; [i[2], i[2] + i[1], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - add i[2] + i[1], pop from arith | store i[2] + i[1] in arith
; [i[2], i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - pop i[3] from tape use previous i[1] + i[2] from arith to xor
; [i[2], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - use previous i[1] + i[2] from arith to xor and pop
; [i[1], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - put i[2] in arith, pop i[1] from tape
; [i[2] + i[1], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - put i[1] in arith, add, pop
; [i[3], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - xor i[2] + i[1] with (i[2] + i[1]) ^ i[3]
; [i[2], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - put i[3] in arith, pop i[2] from tape
; [i[2] + i[3], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - put i[2] in arith, add to i[3]
; [i[0], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - put i[2] + i[3] in arith, pop i[0] from tape
; [(i[2] + i[3]) ^ i[0], (i[2] + i[1]) ^ i[3], (i[0] + i[1]) ^ i[2], (i[3] + i[0]) ^ i[1]]
; - xor in arith
; push all to tape
; pop all back into mem in correct spot
; routine for doing overflowing add
; [a, b]
; [255 - a, b]
; 255 - a < b
; a = b - [255 - a]
; 255 - a >= b
; a = a + b
;
le 0x00, 0x01, label
sd disp, 0x00
label:
sd disp, 0x01