CS137-lecture-20210511

ISA cont. #

Accumulator ISA cont. #

image_2021-05-11-19-04-02 image_2021-05-11-19-09-51 image_2021-05-11-19-17-33 image_2021-05-11-19-26-38

.code               ; start of program code
    LD  0           ; initialize ACC <- 0
    ST  (sum)       ; M[sum] <- ACC
    ST  (i)         ; M[i] <- ACC
L1:
    CMP 7           ; i > 7?
    JGT L2          ; jump to L2 if greater flag is on
    MVX             ; get next index, X <- ACC
    LD  X(array)    ; get next array element, ACC <- M[array + x]
    ADD (sum)       ; add i to running sum, ACC <- ACC + M[sum]
    ST  (sum)       ; store running sum, M[sum] <- ACC
    LD  (i)         ; get i, ACC <- M[i]
    ADD 1           ; i++
    ST  (i)         ; M[i] <- ACC
    JMP L1
L2:

image_2021-05-11-19-35-32 image_2021-05-11-19-57-32