Memory Filler in LMC

The aim of this challenge is to write a program in LMC that will fill in the memory/RAM with the value 999, from memory location 50 onwards (up to memory location 99).

Note that even though such a program may seem pointless, a memory/RAM filler can serve a purpose in some contexts e.g.:

  • A memory filler program can be used for testing purposes for instance to investigate how a system behaves when the available RAM memory is running low or reaching its full capacity. (Will the system crash? will the system make use of virtual memory?)
  • A memory filler program can be used for benchmarking purposes to evaluate/compare memory writes efficiency/speed.

First Attempt

So let’s start the code with a very basic program to fill up the next 5 memory locations:

You can try this code using the online LMC simulator:
LMC SimulatorOpen in New Window

Using a loop?

The above code would be unsustainable if we planned to over-write million of memory locations. It would seem that using a loop/branching instruction would be recommended here.

The idea would be to use a label to store the memory address to write on. We would initialise this label to 50 and increment this value by 1 for each iteration of the code:

The above code shows how the loop can be implemented. However there is an issue with line 1 of this code. The aim is to store the value currently held in the accumulator at the memory location stored in memory location “address”.
This cannot be achieved with direct addressing!

Solution 1: Using Indirect Addressing

For the above code to work, we need to rely on indirect addressing.
With the online LMC simulator, this can be achieved using the @ symbol.
To find out more about memory address modes, you can read the following blog post.

You can try this code using the online LMC simulator:
LMC SimulatorOpen in New Window

Solution 2: Using Self-Modifying code

Not all processors support indirect addressing. (Especially in the early days of “computing history”). In this case an alternative approach consists of using self-modifying code that can be implemented without the need to use indirect addressing.

You can investigate this approach further by reading through this challenge/post.

Share Button
Tagged with: