System Software – SIC program to set 100 elements of array to Zero

Problem Statement

Suppose that ALPHA is an array of 100 words, as defined in Fig. 1.5(a). Write a sequence of instructions for SIC to set all 100 elements of the array to 0.

Solution

Line Number(ac)CodeDescription
1LDA ZERO 
2STA INDEX 
3LOOP LDX INDEX 
4LDA ZERO 
5STA ALPHA, X 
6LDA INDEX 
7ADD THREE 
8STA INDEX 
9COMP K300 
10TIX TWENTY 
11JLT LOOP 
12INDEX RESW 1 
13ALPHA RESW 100 
14ZERO WORD 0 
15K300 WORD 100 
16THREE WORD 3 

1 Comment

  • LDA ZERO ; Load 0 into the accumulator
    STA INDEX ; Store 0 into INDEX

    LOOP LDX INDEX ; Load INDEX into the X register
    LDA ZERO ; Load 0 into the accumulator
    STA ALPHA, X ; Store 0 into ALPHA + X (array element)
    LDA INDEX ; Load the value of INDEX into the accumulator
    ADD THREE ; Add 3 to the accumulator
    STA INDEX ; Store the new value back into INDEX
    COMP K300 ; Compare the value in A with K300 (100)
    JLT LOOP ; If INDEX < 100, jump to LOOP

    END ; End of the program

    INDEX RESW 1 ; Reserve 1 word for INDEX
    ALPHA RESW 100 ; Reserve 100 words for the array ALPHA
    ZERO WORD 0 ; A word initialized to 0
    K300 WORD 300 ; K300 should be 300 (100 * 3) for comparison
    THREE WORD 3 ; A word initialized to 3

Leave Your Comment