Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Sieve of Eratosthenes using LC3

Hi can someone please guide me how to do this problem. I just started this course but I am sooo confused....

The LC-3 Implementation
=======================================================================

- THE ARRAY

You will be using the FILL command to allocate 3001 words of memory
with which you will be storing the list of prime numbers:

PRIMES .BLKW 3001

You MUST ensure that your list of primes is labeled using PRIMES.
Also, you may be wondering why '3001' and not '3000'. Remember, to
determine the actual size needed for a 0-based array you need 'end -
start + 1' spaces, so this comes out to '3000 - 0 + 1', or '3001'.


- THE STEPS

The first step of your algorithm is, of course, to iterate over this
memory setting all of the 'array' indexes to their respective values
as described above.

Then, you simply proceed with the algorithm above. Once you are
finished determining all of the prime numbers between 2 and 3000,
halt your program.

You may be wondering how you can check if your algorithm is correct.
Well, the reason you are storing the actual value of the index rather
than a simple '1' or '0' (for 'prime' or 'not prime' respectively) is
so you can rapidly look through the memory and determine if the
numbers you found to be prime are indeed prime.


- GOTCHAS

When doing this, we recommend you make printouts and label what each
register is doing in each part of the program. You will find
yourself using registers to do three entirely different things with
registers:

- An index, such as a counter.
- A pointer, or a memory address.
- A plain number read from memory.

Restrictions
=======================================================================

1 - Your program must finish before 1,000,000 instructions are
executed. If your program executes more than this, then it will
be halted and your program will be graded at that point.

As long as you follow the algorithm above, you do not have to
worry about the above restriction.

2 - You must start your array of primes by labelling it PRIMES in
your assembly code.

3 - You must store the elements of the array in the format we specify.
Be sure to double-check that the beginning of PRIMES corresponds
to the number 0.

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    "The first step of your algorithm is, of course, to iterate over this
    memory setting all of the 'array' indexes to their respective values
    as described above."

    Sounds like good advice.

    Don't try and tackle the program all at once. Take it one step at a time.
    So first, try and get the array working. It'll also teach you how to use it - which you will need to know later in your program.

    If every you get stuck on a particular point, you can come here for help.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.