The hypothetical computer has instructions of the form (using assembly language notation)
op r,d(b)where r and b are registers and d is a nonnegative number. The register r is an operand register, and d(b) represents the memory address (b) + d, where (b) denotes the contents of register b.
The instruction set (op codes) is:
Thus, for example, the instructions
ld r1,4(r2)would copy the word at (r2)+4 to (r2)+16. Assume that there are up to eight general purpose registers (r1 ... r8) to work with.
st r1,16(r2)
Exercise: What code could a compiler generate for the C code
x = y + 5;if the following represents the current environment (at the time the above instructions are executed), where each memory cell represents a word of 4 bytes and each byte has an address?
y = n + m;
___________ | | | | |____________| r1: | -------------->| | |___________| x: | | |____________| | | y: | | |____________| | | | 5 | |____________| | | p: | ------- |____________| \ | | \ | | | | \ |____________| ----->| | n: | | |____________| | | m: | | |____________| | |