.ORIG x3000
    AND R1, R1, #0  ; clear R1 to set R1=0
    ADD R1, R1, #3  ; add 3 to R1
    ADD R2, R1, #-10 ; R2 = R1 -8 = -2
    BRn next        ; branch if result negative to NEXT
    HALT
NEXT LD R3, PLACE   ; load contents at address PLACE into register R3
     LDI R4, PLACE   ; load indirect from PLACE into R4
     LDR R5, R3, #0   ; load from address in R3 into register R5
     AND R0, R0, #0 ;clear R2
loop ADD R0, R5, R0 ; add R1 to current value of R0  
     ADD R1, R1, #-1 ; subtract 1 from R1 (decrement R1 by 1)
     BRp loop   ; if positive, i.e., R1>0, then loop else exit
     ST R0, RESULT  ; store R0 into memory location RESULT
     HALT
     
PLACE .FILL x3020       ; PLACE has value x3020 - memory address
RESULT .BLKW #1         ; RESULT is a memory location not initialized
    .END

    .ORIG x3020
    .FILL x5
    .END
    
    .ORIG x3030
    .FILL x0005
    
    .END
