=============== LMC Indirection =============== -IAN! Ian! D. Allen - idallen@ncf.ca Write the values 11 through 29 into mailboxes 81 through 99. Sum the mailboxes in reverse order; output the sum. Pseudocode for ( counter = 81; counter <= 99; counter++ ) memory[counter] = counter - 70 endfor sum = 0 for ( counter = 99; 81 <= counter; counter-- ) sum += memory[counter] endfor output sum Revised Pseudocode counter = 81 while ( counter <= 99 ) memory[counter] = counter - 70 counter = counter + 1 endwhile sum = 0 counter = 99 while ( 81 <= counter ) sum += memory[counter] counter = counter - 1 endwhile output sum ;Label Mnem. Operand Comments............. ;----- ----- ------- --------------------- LDA NUM81 STO COUNTER TEST1 LDA NUM99 ; FIRST LOOP while counter <= 99 SUB COUNTER SKP JMP ENDWH1 LDA STORE ; mem[counter] = counter - 70 ADD COUNTER STO DOIT1 LDA COUNTER SUB NUM70 DOIT1 DAT ? ; SELF-MODIFYING CODE HERE LDA COUNTER ; counter++ ADD ONE STO COUNTER JMP TEST1 ENDWH1 LDA ZERO ; two initializations STO SUM LDA NUM99 STO COUNTER TEST2 LDA COUNTER ; SECOND LOOP while 81 <= counter SUB NUM81 SKP JMP ENDWH2 LDA LOAD ; sum += mem[counter] ADD COUNTER STO DOIT2 DOIT2 DAT ? ADD SUM STO SUM LDA COUNTER ; counter-- SUB ONE STO COUNTER JMP TEST2 ENDWH2 LDA SUM ; output sum and stop OUT HLT ; CONSTANTS LOAD DAT 100 ; code for a LOAD STORE DAT 200 ; code for a STORE ONE DAT 001 NUM70 DAT 070 NUM81 DAT 081 NUM99 DAT 099 ; VARIABLES SUM DAT ? ; sum of mailboxes COUNTER DAT ? ; count the mailboxes