| Computer Architecture |
| architecture |
| Computer Architecture |
| A computer is essentially a large collection of finite-state machines. | |
| A common clock is used for all. | |
| The machines intercommunicate by the output of one machine being the input to another. | |
| Combinational logic can be interposed between output and input to affect data transformations. |
| Computer Architecture |
| We will work with a simulated tutorial
architecture: ISC: Incredibly Simple Computer |
| The ISC |
| ISC is an example of a RISC (Reduced Instruction Set Computer), as opposed to a CISC (Complex Instruction Set Computer) |
| ISC Design |
| ISC Processor Components (1) |
| General Registers: Hold operands and results, and addresses for jumps in program. | |
| IR (Instruction Register) holds currently executing instruction. | |
| IP (Instruction Pointer): Holds address of next instruction. | |
| MDR (Memory Data Register) holds data en-route to/from memory. | |
| MAR (Memory Address Register) holds address of memory location for data. |
| ISC Processor Components (2) |
| ALU (Arithmetic-Logic Unit) Combinational unit performing addition, subtraction, logical operations, shifting, etc. | |
| ALU registers: Registers holding operands and results for ALU | |
| Control sequencer: Finite-state machine sequencing register and 3-state strobes, based upon the contents of the IR (Instruction Register) |
| Slide 8 |
| Instruction Dichotomies |
| Instructions that access memory (Òmemory accessÓ instructions) | |
| Instructions that include an operand in the instruction itself (ÒimmediateÓ instructions) | |
| Instructions that change instruction location (ÒjumpÓ instructions) |
| Slide 10 |
| Slide 11 |
| Slide 12 |
| Slide 13 |
| Slide 14 |
| Slide 15 |
| Control Sequencer FSM |
| Inputs are bits from instruction being interpreted | |
| Outputs are strobes to various registers, 3-state devices, etc. |
| Control Sequence |
| There is a sequence common to all
instructions in which the instruction is fetched from memory, followed by |
|
| A sequence particular to the type of instruction being executed. |
| ISC Instruction Fetch |
| Slide 19 |
| Slide 20 |
| Slide 21 |
| Slide 22 |
| Control Subsequence Example: Add Ra Rb Rc |
| Slide 24 |
| Slide 25 |
| Slide 26 |
| Slide 27 |
| Exercise |
| What would the instruction subsequences be for: | ||
| aim (add immediate) | ||
| load | ||
| store | ||
| jeq (jump-if-equal) | ||
| Machine-Level Programming |
| Programming of the bare machine is typically done in Òassembly languageÓ | |
| One line of assembly language is roughly equal to one machine instruction | |
| A program, the ÒassemblerÓ, allows use of symbolic identifiers for addresses. |
| Programming in Assembly Language |
| Programming in assembly language reminds me of the Japanese saying about climbing Mt. Fuji: | ||
| ÒTo never have climbed Mt. Fuji is to be a fool. | ||
| Only a fool would climb Mt. Fuji more than once.Ó | ||
| ISCAL ISC Assembly Language |
| See http://www.cs.hmc.edu/~keller/isc/ | |||
| Free-form input, but generally format line-by-line | |||
| Regular instructions | |||
| Ra, Rb, Rc are register names | |||
| C is a constant | |||
| lim Ra C | |||
| add Ra Rb Rc | |||
| copy Ra Rb | |||
| shl Ra Rb | |||
| load Ra Rb | |||
| etc. | |||
| ISCAL |
| Assembler directives: not instructions to computer, but rather tell assembler what to do: | ||
| define Identifier Value Defines Identifier to have Value. | ||
| use Identifier Defines Identifier to name an unused register. | ||
| origin Value Begin loading
instructions at specified memory location. The location counter is incremented as loading progresses. |
||
| label Identifier Associates current instruction location with Identifier. | ||
| ISCAL code for summing an array |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| Array Summation |
| The ISC Assembler |
| The ISC assembler is actually a combined assembler, loader, and tracer (for debugging). | |
| The executable is: /cs/cs60/bin/isc |
|
| Sample programs are in /cs/cs60/isc/ |
| The ISC Assembler |
| The array summation program is in /cs/cs60/isc/array.isc. It includes additional code to create the array and output the result. |
| isc output |
| Implementing Procedures |
| A procedure is just some fixed code we jump to to perform some computation. | |
| We put the arguments to the procedure into pre-agreed standard registers, and get the result from another register. | |
| The jsub instruction can be used to get the return address. |
| Implementing Recursion |
| Recursion presents a problem: The fixed code would tend to clobber (an inelegant way of saying Òover-writeÓ) the return address when the procedure calls itself. | |
| Also, the arguments in registered would get clobbered. |
| Stacks to the Rescue |
| To deal with the clobbering problem, we can save the return address and any arguments on a stack allocated at a standard place in memory. | |
| The stack is typically an array, with a pointer to the top element. |
| Example: Recursive Factorial |
| Stack trace of factorial(4) |
| Stack trace of factorial(4) |