Nada
Nada

Reputation: 11

using index in LMC

I have to do this task Given Student ID contains 9 digits. my task is with writing a simple assembly in LMC program that performs the following tasks:

  1. Input a number from the user that will be stored in the Accumulator and will be referred to as R.
  2. Initialize an array in memory that contains the 9 digits of your Student ID.
  3. Define an index that will serve as a pointer to the array of digits.
  4. Start a loop that iterates through each digit of your Student ID:
    a. Add one digit from the array to R.
    b. Output the current value of R.
    c. Increment the index to point to the next digit in the array.
  5. Output the final sum after all digits have been added.

I build this piece of code but still has problems that I have to define the pointer to point to the first element of the array manually the code as following

        INP
        STA result
        OUT
       

loop LDA @index
        ADD result
        STA result 
        OUT
        LDA index
        ADD one
        STA index
        LDA count
        SUB one
        STA count
        
        BRP loop
            

result  DAT     
count   DAT 8
one     DAT 1 
array1  DAT 1
array2  DAT 1
array3  DAT 1
array4  DAT 1
array5  DAT 1
array6  DAT 1
array7  DAT 1
array8  DAT 1
array9  DAT 1
index   DAT 17 

Upvotes: 1

Views: 20

Answers (0)

Related Questions