Von Neumann and MIPS
Side Note
• Really need to get into MIPS !
• Getting waylaid by floating point • Will come back to it later
The Computer in a Nutshell
Control Unit
Data given to computer
Programmer’s Instructions
Result of Execution of Instruction
ALU,etc
(the tools needed to process the data)
Repeat this process for each individual instruction from user till you finish executing the whole program!
The Stored Program Concept
Program: A sequence of individual instructions aimed at collectively executing a specific task, e.g. Find the largest number in a set, Find out how many times the word “happy” appears in a text, etc…
The stored program concept says that the program is stored with data in the computer’s memory. The computer is able to manipulate it as data— for example, to load it from disk, move it in memory, and store it back on disk.
It is the basic operating principle for every computer.
It is so common that it is taken for granted.
Without it, every instruction would have to be initiated manually.
4
About the instructions
• Each instruction is a sequence of 1s and 0s (remember a computer cant understand except for logic High or Low)
• In MIPS, the length of this sequence is fixed. It is 32 bits
■ For example,
addi $t1, $0, 548 – 0x20090224
Literal meaning: “ Add the value contained in register $0 with 548, then put the
addition result in register $t1”
Registers are temporary placeholders for data which is operated on by
ALU(Arithmetic Logic Unit)
The actual 32 bit instruction: 0010 0000 0000 1001 0000 0010 0010 0100
Please do not get intimidated by this sequence of 1s and 0s! The decoding of it back into a human understandable instruction is the focus of CSE120
How to store the instructions?
• In stored program machine, we need to keep track of where we place the instructions in main memory.
• Main memory is where all your computer’s data and instructions ultimately reside
• Main memory is not the only memory component in the computer.
• We also have the registers (faster and smaller memory units as well)
How to store the instructions?
• •
Main Memory – Your Home Neighborhood analogy
Imagine each instruction is located in a specific address in a neighborhood
I1 I2
I3
1156 High St, Santa Cruz
700 Front St, Santa Cruz
■ If you want to fetch and execute instructions I1, I2, I3 in sequence, then you will need to sequentially travel to the addresses : 1156 High St -> 700 Front St -> 220 Sylvania Ave
■ The same exact principle lies in storing program instructions in main memory as well We assign each of them addresses.
■ Since data (which we will need to operate on) is also contained in main memory, they are referred to by their address in main memory as well
220 Sylvania Ave, Santa Cruz
The von Neumann Model
■ Memory: holds both data and instructions
■ Processing Unit: carries out the instructions
■ Control Unit: sequences and interprets instructions
■ Input: external information into the memory
■ Output: produces results for the user
von Neumann Model – Memory
■ Each location has an address and contents
◆ Address:bitpatternthatuniquelyidentifiesamemorylocation ◆ Contents:bitpatternstoredatagivenaddress.
◆ Analogy:P.O.boxeshavefixednumbers,butchangingcontents.
von Neumann Model – Memory (2)
◆ a word is the basic unit of data used by the processing unit of MIPS
■ Addressability (Byte vs. Word):
◆ 1 byte = 8bits ; 1 B= 8b
◆ 1 word = 4 bytes ; 1 word = 4B= 32b
◆ 1 halfword=2 bytes=16b
◆ Frequently, an instruction must store or retrieve an entire word with a single memory access.
◆ Addressability refers to the number of bytes of memory referenced by a given address.
◆ MIPS machine is Byte Addressable
Byte addressability
• The memory is said to be byte addressable if the smallest unit of memory that can be addressed is 1 byte of memory
• Consider a toy example: Main memory capacity is 6 bytes and it is byte addressable
• Assume in example, that all the data (both instructions and operable data) are only 1 byte
long. (More complex cases later!)
Address 5 4
3 2
1 0
Main Memory content
0xAB
0x00
0x20
0x03
0xFF
0x14
• Mem[0]=0x14 , i.e. 1416 = 0001 0100 in binary
• Mem[1]=0xFF , i.e. FF16 = 1111 1111 in binary
• Mem[2]=0x03 , i.e. 316 = 0000 0011 in binary
Memory alignment
Keep in mind that MIPS memory is byte-addressable, so an actual MIPS instruction(32-bit= 1 word long) actually occupies four contiguous locations (bytes) of main memory.
Address 0 1 2 3 4 5 6 7 8 9 10 11 8-bit data
Word 1 Word 2 Word 3
The MIPS architecture requires words to be aligned in memory; 32-bit words must start at an address that is divisible by 4.
– 0, 4, 8 and 12 are valid word addresses.
– 1, 2, 3, 5, 6, 7, 9, 10 and 11 are not valid word addresses. – Unaligned memory accesses result in a bus error
This restriction has relatively little effect on high-level languages and compilers, but it makes things easier and faster for the processor harware.
12
von Neumann Model – Processing Unit
◆ Can consist of many sub-units, each specializing in one complex function.
■ Does the actual work!
◆ At a minimum, has Arithmetic & Logic Unit (ALU) and General Purpose Registers (GPRs)
4 – 13
von Neumann Model – Processing Unit (2)
■ ALU
◆ Performsbasicoperations:add,subtract,and,not,etc. ◆ Generallyoperatesonwholewordsofdata.
◆ Somecanalsooperateonsubsetsofwords
■ Registers
◆ Fast“on-board”memoryforasmallnumberofwords.
◆ Invaluableforintermediatedatastoragewhileprocessing ◆ ClosetotheALU(muchfasteraccessthanRAM).
4 – 14
■
■ ■
The control unit coordinates all actions needed to execute the instruction
von Neumann Model – Control Unit
◆ Itfetches&decodeseachinstruction,andsetsuptheappropriateinputsforthe Memory, Processing, and I/O units as required.
◆ ItcommunicateswithmemoryviatheProgramCounter(PC)andInstructionRegister (IR)
PC (aka Instruction Pointer)
◆ Holdstheaddressofthenextinstructiontobefetched.
IR (Instruction Register)
◆ Holdstheinstructioncurrentlybeingexecuted. ◆ Thiscanbeasingleword,ormultiplewords.
von Neumann Model – Input/Output
■ Generically known as peripherals – not in the sense that they matter less, but because they are external to the CPU.
■ This means we will have to develop mechanisms for autonomous devices to communicate with each other – more on this later.
4 – 16
Notations
■ Sets of Bits
◆ A[3:0]denotesasetof4bits:A ,A ,A ,A
3210
◆ The content of an n-bit register Rx is referred to as Rx[n-1:0]
★ RXn-1 is the most significant bit (MSB), or leftmost bit
★ RX0 is the least significant bit (LSB), or rightmost bit
★ Given RX[31:0], RX[7:4] refers to the four bits from RX7 down to RX4
■ Bit Assignment
◆ R2[5:0] ⇐ R1[13:8]
★ Means that bits 5 to 0 of register R2 get assigned the values of bits 13 to 8 of register R1. ■ Contents
★ (Reg1) means “content of Reg1”
★ Mem[loc] means “content of memory location loc” (i.e., loc is the address)
★ [Reg1] means the “contents of memory at address in Reg1”