Simpletron machine and indirect addressing

99封情书 提交于 2020-01-02 09:28:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9278159/simpletron-machine-and-indirect-addressing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!