42 lines
1.5 KiB
NASM
42 lines
1.5 KiB
NASM
;clean registers
|
|
;load starting pos and starting pos +1 into memory
|
|
;subtract first value (starting pos) from second value (starting pos +1)
|
|
;if result is negative or zero, write 0 to x4000
|
|
;if positive, loop back and do the same with the next two memory locations
|
|
.ORIG x3000 ;start point
|
|
|
|
AND R6, R6, #0 ;clean R6
|
|
AND R5, R5, #0 ;clean R5
|
|
AND R4, R4, #0 ;clean R4
|
|
AND R3, R3, #0 ;clean R3
|
|
|
|
LOOP LD R6, FIRSTPOS ;block loads first pos into register increments memory value by one and store back
|
|
ADD R6, R6, #1
|
|
ST R6, FIRSTPOS
|
|
|
|
LD R6, SECONDPOS ;block loads second pos into register increments memory value by one and store back
|
|
ADD R6, R6, #1
|
|
ST R6, SECONDPOS
|
|
|
|
LDI R3, FIRSTPOS ;load values into memory and then create negative out of it
|
|
LDI R4, SECONDPOS
|
|
ADD R4, R4, #0 ;see if the array ends
|
|
BRz FINISH
|
|
NOT R3, R3
|
|
ADD R3, R3, #1
|
|
|
|
ADD R5, R3, R4 ;add R3 and R4 into R5
|
|
BRp LOOP
|
|
LD R6, ZERO
|
|
STI R6, RESULT
|
|
HALT
|
|
FINISH LD R6, ONE
|
|
STI R6, RESULT
|
|
DONE HALT
|
|
|
|
FIRSTPOS .fill x4000
|
|
SECONDPOS .fill x4001
|
|
RESULT .fill x4000
|
|
ONE .fill x0001
|
|
ZERO .fill x0000
|
|
.END |