2

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?

GionJh
  • 2,742
  • 2
  • 29
  • 68
  • did you have 100 units of ram in an "early computer"? I would agree you need self modifying code or an unrolled loop. Define what you mean by "early computer" and go find what you can about the instruction set" The early programmable computers didnt operate on an instruction set like we think of today so you have to clarify what is meant, look at 4004, 8008, 8080, 6502, etc to find early stuff that resembles modern stuff (transistors, instruction sets, etc). – old_timer Feb 14 '12 at 14:36
  • probably that was the reason, but it's also a necessity if your code "segment" is read-only.. – Karoly Horvath Feb 14 '12 at 14:36

1 Answers1

0

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.

David Given
  • 13,277
  • 9
  • 76
  • 123