32 lines
624 B
NASM
32 lines
624 B
NASM
.ORIG x3000 ;start point
|
|
|
|
AND R6, R6, #0 ;clean R6
|
|
AND R5, R5, #0 ;clean R5
|
|
|
|
;load memory addresses into registers
|
|
LDI R3, x00D
|
|
LDI R4, x00D
|
|
;NOT the divident to get negative value and then add one
|
|
NOT R5, R4 ; NOT(R4) => R5
|
|
ADD R5, R5, #1 ; R5+1 => R5;
|
|
BR #1; skip first increment
|
|
ADD R6, R6, #1 ;increment divison count
|
|
|
|
ADD R3, R3, R5 ;subtract
|
|
|
|
BRz #-3 ;if exact division we can skip final loop
|
|
BRp #-4 ;loop back 3 instructions to keep dividing
|
|
ADD R3, R3, R4 ; get the remainder of the division
|
|
|
|
;store values in memory;
|
|
STI R6, x005
|
|
STI R3, x005
|
|
HALT
|
|
|
|
.fill x0000
|
|
.fill x4000
|
|
.fill x4001
|
|
.fill x5000
|
|
.fill x5001
|
|
|
|
.end |