1. Designing ISAs
Designing ISAs
There are different factors to consider when looking at different ISAs:
- Instruction length: number of bits per instruction Are instructions short, long or variable?
- Memory organisation: is memory byte- or word- addressable
- No. of (explicit) operands per instruction. We could use a stack or one or more registers, we also need to consider how many addressable registers there are.
- Addressing modes: is there direct, indirect or indexed addressing?
- Type, size and location of operands.
- Types of operations available. What can the ISA actually perform?
When choosing an ISA, we care about:
- main memory space occupied by a program
- instruction complexity and bit length
- total number of instructions in set
Link to originalSystem clock
A system clock is used to synchronise all internal components, the clock outputs a steady high-frequency signal.
Link to original
- A fixed number of clock cycles are required to carry each data movement or computational operation.
Clock frequency
The clock frequency, measured in Hertz, determines the speed with which all operations are carried out. Clock cycle time is the reciprocal of frequency.
A clock has a cycle time of .
Link to original- The CPU time required to run a program is given by the general performance equation: We can improve CPU throughput if we reduce:
- Number of instructions per program.
- Number of cycles per instruction.
- Number of seconds per clock cycle.
2. Endianness
Endianness
Byte ordering
Byte ordering, or endianness, is the order in which we store bytes in memory and process them.
Link to originalSay we have a two-byte integer, we can choose where the least and most significant byte is stored:
Big-endian
Big-endian machines are where we store the most signfiicant byte followed by the least significant byte.
It is more natural. The sign of the number can be determined by looking at the byte at address offset . Strings and integers are stored in the same order.
Link to originalLittle-endian
Little-endian machines are where we store the least significant byte followed by the most significant byte.
Makes it easier to place values on non-word boundaries. Conversion from a 16-bit integer address to a 32-bit one does not require any arithmetic.
Link to originalSuppose we have the hex number , the big / small endian arrangements of the bytes are:
Link to original
Address Big Endian Little Endian
3. Register Architectures
Register Architectures
Next consideration for the ISA is how the CPU will store data, there are different trade-offs involved in picking different types of architectures, including but not limited to the simplicity and cost of hardware design, execution speed and ease of use.
We can choose from the following main architectures:
Link to original
Stack architecture
Stack architecture: Instructions and operands are implicitly taken from the stack. A stack cannot be accessed randomly.
Stack machines use one- and zero- operand instructions. All instructions implicitly operate on elements at the top of the stack.
Push XandPop Xinstructions require a single memory address operand.- Binary instructions (such as
Add,Mult) use the top two items in the stack.When working with stack architectures, arithmetic expressions should be structured with postfix notation ( as opposed to infix notation, ).
Parentheses are not needed to find order of operations, can be represented as in postfix notation, and could generate instructions such as:
Push X Push Y Mult Push W Push U Mult Add Pop ZThe result of each binary operation is stored at the top of the stack.
Link to originalAccumulator architecture
Accumulator architecture: one operand of a binary operation is implicitly in the accumulator. (One operand is in memory, causing bus traffic.)
Link to originalGeneral purpose register architecture
General purpose register (GPR) architecture: registers can be used instead of memory. Faster than the accumulator architecture but results in longer instructions. This is how most systems today are designed.
There are three types of GPR system:
- Memory-memory where two or three operands may be in memory.
- Register-memory where at least one operand must be in a register.
- Load-Store where no operands may be in memory.
The number of operands and the number of available registers directly affects instruction length.
Link to original
4. Instruction Types
Link to original
5. Addressing
Addressing
Different addressing modes specify where an operand is located, can be any of: a constant, a register, or a memory location.
Certain addressing modes allow us to dynamically determine this address.Effective address
The effective address is the actual location of an operand.
Link to originalTypes of addressing:
Link to original
- Immediate: the data is part of the instruction.
- Direct: address of the data is given in the instruction.
- Register: data located in register.
- Indirect: address of address of data is given.
- Register indirect: register stores address of the address of data.
- Indexed: uses a register (implictly or explicitly) as an offset, which is added to the address in the operand to determine the effective address of the data.
- Based: similar to indexed, except that a base register is used instead of an index register. A base register holds a base address which is used to displace the given address, think of the given address (in the instruction) as a relative address to the base address. Meanwhile an index register holds the offset relative to the address given in the instruction.
- Stack: the operand is assumed to be on the top of the stack.
6. Pipelining
Pipelining
Instruction-level pipelining
Some CPUs perform instruction-level pipelining where they divide the [[FDE Cycle]] into smaller steps, and then execute these steps in parallel.\
Link to originalConsider an FDE cycle broken down into 6 stages:
- Fetch instruction
- Decode opcode
- Calculate effective address of operands
- Fetch operands
- Execute instruction
- Store result
These can be used in order in a six-stage pipeline. For every clock cycle, one small step is carried out and the stages are overlapped.
Theoretical Speed-up
The theoretical speed-up offered by a pipeline can be found as follows:
- Each instruction represents a task, , in the pipeline.
- Let be the number of tasks (instructions) in the program.
- Let be the time per stage.
- Let be the number of stages in the pipeline.
- The first task requires time to complete.
- The remaining tasks emerge from the pipeline one per cycle.
- So the total time to complete the remaining tasks is .
The time to complete tasks using a -stage pipeline is:
To compute the speed gain, we compare with the time taken to run the same program without pipelining, the time taken to run one task without pipelining is , hence we can find the time to do tasks to be .
The fractional speed up is then given by:
If we take the limit as then . This results in a theoretical speedup of:
These equations assume that:
- the architecture supports fetching instructions and data in parallel
- the pipeline can be kept filled at all times
Pipeline hazards are thongs that can cause a pipeline to stall, or be flushed for any reason such as: Resource conflicts, data dependencies, or conditional branching.
Link to original