38 lines
1.7 KiB
NASM
38 lines
1.7 KiB
NASM
;first, clean registers
|
|
;second, load x4002 into a register
|
|
;third, determine if negative or positive
|
|
;fourth depending on what it is, add it to memory location
|
|
;stop when reaching a memory location of zero
|
|
.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
|
|
STI R3, NEGATIVEPOS ;clean memory at location
|
|
STI R3, POSITIVEPOS ;clean memory at location
|
|
|
|
|
|
LOOP LD R6, POSITION ;load position into register
|
|
ADD R6, R6, #1 ;Add one to register
|
|
ST R6, POSITION ;Store new value in memory
|
|
LDI R3, POSITION ;Load from new value
|
|
ADD R3, R3, #0 ;test for negative
|
|
BRz DONE ;Halt if result is zero
|
|
BRn NEGATIVE ;Branch if negative
|
|
BRp POSITIVE ;branch if positive
|
|
|
|
NEGATIVE LDI R4, NEGATIVEPOS ;load negatve total into r4
|
|
ADD R4, R4, R3 ;add stored value together with new value
|
|
STI R4, NEGATIVEPOS ;store the new total back to negative total
|
|
BR LOOP ;loop back
|
|
|
|
POSITIVE LDI R5, POSITIVEPOS ;load positive total into r5
|
|
ADD R5, R5, R3 ;add stored value together with nuew value
|
|
STI R5, POSITIVEPOS ;store the new total back into positive total
|
|
BR LOOP ;loop back
|
|
DONE HALT ;kill program
|
|
POSITIVEPOS .fill x4000
|
|
NEGATIVEPOS .fill x4001
|
|
POSITION .fill x4001
|
|
.END |