Header Value Looping 6

Flowchart a procedure to read a header value k. Compute and print the sum of the following data values. Then print the average of those data values. (Remember that the header value itself should not be part of the sum.)

Flowchart      RAMM Machine Language Program     RAMM Assembly Language Program
    

Flowchart:



RAMM Machine Language Program:

0000 00 Integer constant 0, I0
0001 01 Integer constant 1, I1
0000 02 Storage for I
0000 03 Storage for K
0000 04 Storage for S
0000 05 Storage for Y
0000 06 Storage for AVG
5000 07 STRT  No operation
1200 08       (A-reg) <- (I0)
2002 09       (I) <- (A-reg)
2004 10       (S) <- (A-reg)
6503 11       Read K
1202 12 LOOP  (A-reg) <- (I)
1503 13       (A-reg) <- (A-reg) - (K)
3721 14       If (A-reg) < 0, then jump to READ
1204 15       (A-reg) <- (S)
2503 16       (A-reg) <- (A-reg) / (K)
2006 17       (AVG) <- (A-reg)
6604 18       Print S
6606 19       Print AVG
0000 20       Halt
6505 21 READ  Read Y
1204 22       (A-reg) <- (S)
1405 23       (A-reg) <- (A-reg) + (Y)
2004 24       (S) <- (A-reg)
1202 25       (A-reg) <- (I)
1401 26       (A-reg) <- (A-reg) + (I1)
2002 27       (I) <- (A-reg)
7512 28       Unconditionally jump to LOOP
9907 29       End; begin program execution at STRT


RAMM Assembly Language Program:

I0    DEC 0000
I1    DEC 0001
I     BSS 0001
K     BSS 0001
S     BSS 0001
Y     BSS 0001
AVG   BSS 0001
STRT  NOP
      LDA I0
      STA I
      STA S
      RDI K
LOOP  LDA I
      ISB K
      AMJ READ
      LDA S
      IDV K
      STA AVG
      PRI S
      PRI AVG
      HLT
READ  RDI Y
      LDA S
      IAD Y
      STA S
      LDA I
      IAD I1
      STA I
      UNJ LOOP
      END STRT