Question

I recently made the Simpletron assignment from the Deitel and Deitel textbook.

The Simpletron machine language has only one addressing mode which is direct addressing.
(That is, you have to specify the address you want to access in the operand part of the instruction.)

So I think there is no way of computing an address at run time and access it.

So doing something like this:

[pseudo-c]

int a[10];

...  

int i = 0;

while(a[i] > 100)  
{  

i++;

}  

..

would require some self modifying code or expanding the loop, am I correct?
So my question is:

The textbook presents Simpletron as very similar to early computers.

Were indirect addressing modes (such as register addressing) introduced in subsequent architectures to make programming easier?

Was it helpful?

Solution

I believe that's correct. But Simpletron is so trivial that self-modifying code is only three instructions:

// address to load is in accumulator
ADD loadinstruction // construct load instruction
STORE $ + 1         // write instruction to next word of memory
...                 // placeholder filled in by write instruction
// value is in accumulator

loadinstruction: .data 2000

This is only possible because Simpletron's program shares memory with its data. Some computer architectures don't do this; the PIC line of microcontrollers, for example. (Where the RAM is 8 bits wide but the program memory is 14 bits wide!) You also can't modify the program if it's in ROM, obviously enough.

I don't know if this was the specific reason why indirect addressing modes were developed, but it's certainly an important one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top