Computer Internals ECE2036 Lecture 2 ECE2036 Computer Internals Spring 2016 1 / 12
Components of a Computer 1 Central Processing Unit (CPU) 2 Memory 3 Input/Output Devices The computer actually has a number of other components, such as a power supply, case, cables, PCI bus, AGP bus, and many more. For the purposes of this class, we can safely ignore all of these and focus on the three components listed above. ECE2036 Computer Internals Spring 2016 2 / 12
Central Processing Unit 1 The CPU is the brains of the computer. 2 Step by step execution (think steps in an Algorithm) 3 Very simple operations (called Instructions) 1 Add, Subtract, Multiply, Divide two numbers 2 Compare two numbers 3 Advance to the next instruction 4 Conditionally Branch to a different instruction 5 Read or write a memory location 6 Read or write an input/output device 4 Instructions are stored in memory 5 After executing an instruction, the CPU automatically advances to the next instruction and executes that, unless the previous instruction was a Branch. ECE2036 Computer Internals Spring 2016 3 / 12
Memory Memory has two conceptually different attributes 1 Address 1 The Address identifies a particular memory location. 2 Similar to a page number identifying a particular page in a book, but does not identify what is written on that page. 3 Addresses are numbered sequentially from zero to N 1, where N is the size of the memory installed in the computer. For example, if you have 1GB (Giga-Byte) of memory, the locations are numbered from zero to 1,073,741,823. 2 Contents 1 The contents of a memory location is the number stored (Remembered) in a given address. 2 Each memory location has only a limited range of values that can be stored. For example, a typical integer value can only store values in the range of zero to 4,294,967,295. There is quite a bit more to the story about memory addresses and the range of values mentioned above that we will discuss later in class. For now, the above discussion is sufficient. ECE2036 Computer Internals Spring 2016 4 / 12
Input/Output Devices 1 Keyboard 2 Mouse 3 Monitor 4 Disk Drives 5 CD/DVD Drives 6 Network interface (Internet) 7 Audio Output (speakers, headphones) 8 Audio Input (microphone) 9 Universial Serial Bus (USB) devices In general, it is not possible for programs that you write to access any of these devices directly. Rather, the operating system (Windows, Linux, Mac OSX) is responsible for doing this on behalf or your program. ECE2036 Computer Internals Spring 2016 5 / 12
Computer Conceptual Model ECE2036 Computer Internals Spring 2016 6 / 12
Computer Conceptual Model (More Realistic) ECE2036 Computer Internals Spring 2016 7 / 12
CPU Registers All modern CPU s have built-in Registers. Usually just a small number (our sample CPU in the previous slide had 8). The registers are just memory locations, conceptually identical the to the main memory discussed earlier. The difference is that the CPU can read and write registers much much faster than reading and writing main memory. For example, register access usually takes a few nano-seconds, as opposed to a few tens of nano-seconds to access main memory. All arithmetic and comparision operations are register to register All memory read operations are memory to register All memory write operations are register to memory ECE2036 Computer Internals Spring 2016 8 / 12
CPU Instruction Set, Loads and Stores LDM R d, C Load Memory Read memory location C and store contents in register R d. LDM R d, R i, C Load Memory Read memory location C + R i and store contents in register R d. LDI R d, C Load Immediate Store the value C in register R d. LD R d, R s Load Copy the value of register R s into register R d. STM R s, C Store Memory Store the contents of register R s into memory location C. STM R s, R i, C Store Memory Store the contents of register R s into memory location C + R i. ECE2036 Computer Internals Spring 2016 9 / 12
CPU Instruction Set, Arithmetic Operations ADD R d, R s, R t Add Compute R s + R t, store results in R d ADDI R d, R s, C Add Immediate Compute R s + C, store results in R d SUB R d, R s, R t Subtract Compute R s R t, store results in R d SUBI R d, R s, C Subtract Immediate Compute R s C, store results in register R d MUL R d, R s, R t Multiply Compute R s R t, store results in R d DIV R d, R s, R t Divide Compute R s /R t, store results in R d (Integer quotient) MOD R d, R s, R t Modulus Compute R s MODULO R t, store results in R d (Integer remainder) ECE2036 Computer Internals Spring 2016 10 / 12
CPU Instruction Set, Branching Operations BLT R s, R t, I Branch if Less Than Branch to instruction at address I if R s < R t. BLE R s, R t, I Branch if Less Than or Equal Branch to instruction at address I if R s R t. BGT R s, R t, I Branch if Greater Than Branch to instruction at address I if R s > R t. BGE R s, R t, I Branch if Greater Than or Equal Branch to instruction at address I if R s R t. BEQ R s, R t, I Branch if Equal To Branch to instruction at address I if R s = R t. BNE R s, R t, I Branch if Not Equal To Branch to instruction at address I if R s R t. HLT Halt Stop Processing. Note No real processor has a HLT instruction ECE2036 Computer Internals Spring 2016 11 / 12
Averaging Algorithm, Assembly Code # Program t o compute average o f an a r r a y o f numbers LDI, R0,0 # Index i n t o d LDM, R1, Length # Get value of l ength LDI, R2,0 # I n i t a l i z e Sum to zero Loop : LDM, R4, R0, d # Read next element ADD, R2, R2, R4 # Add to sum STM, R2,Sum # Store r e s u l t i n Sum ADDI, R0, R0,1 # Increment index BLT, R0, R1, Loop # Repeat while index < length DIV, R0, R2, R1 # Sum / n STM, R0, Avg # Store r e s u l t i n Avg HLT # Done ECE2036 Computer Internals Spring 2016 12 / 12