Here are some more examples to guide you through understanding the three architectures we have explored so far.
A
Quick ExampleSuppose you wanted to compute the sum of two operands stored in memory locations A and B, and then store the result in C.
The following code fragments give an example of what commands would be needed for each machine type.
Good Points: Very high code density: only Push and Pop instructions need addresses so every other instruction requires only one or two bytes of code. Machine code uses Reverse Polish Notation which is very easy to compile. No save/restore code needed for procedure calls and returns.
Bad Points: Only operands at the top of the stack are accessible: to access an item buried deep in the stack all items above it must be popped. Stack manipulations (such as swaps) require extra instructions.
Good Points: Minimal internal state. Short fixed-length instructions.
Bad Points: The CPU holds only one variable at a time: extra memory traffic is required to manipulate several variables and/or addresses.
Good Points: Arithmetic doesn't overwrite source operands. Simple fixed-length encoding. Simple code generation model. Similar number of clock pulses per instruction.
Bad Points: Higher instruction count: extra load/store instructions required. Wasted space in arithmetic instructions.