Download Understanding Simple Computers: Instruction Execution and Memory in Comp 101 - Prof. Leona and more Study notes Computer Science in PDF only on Docsity!
A Simple Computer
move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer ... Nerd Chef at work.
The Leap
- We next move from computing with tables (combinational logic and state machines) to a general-purpose computer
- We saw that a Turing Machine is the model of what is “computable,” but simple operations required many steps, and it was tedious to program
- Today, we seek a simple computer model with a unified notion of “data” and “instructions”
- This is the “Von Neumann” architecture model
- The first key idea is a model of “memory”
An Array of Words
- Addresses are organized sequentially in an array
- Addresses are
- Numerical
- Symbolic (Label)
- The numerical address is fixed (governed by the hardware)
- Labels are user defined 1: 2: 3: 4: 5: N: 0: . . .
Words = {Instructions, Data}
- Each word of memory can be interpreted as either binary data (number, character, a bit pattern, etc.) or as an instructions
- Not all bit patterns are valid instructions, however.
- Instructions cause the computer to perform a operation
- A program is a collection of instructions
- In general, instructions are executed sequentially
The Stored-Program Computer
- Instructions and Data are stored together in a common memory
- Sequential semantics: To the programmer all instructions appear to be executed sequentially CPU fetches and executes instructions from memory ...
- The CPU is a H/W interpreter
- Program IS simply data for this interpreter
- Main memory: Single expandable resource pool - constrains both data and program size - don’t need to make separate decisions of how large of a program or data memory to buy Key idea: Memory holds not only data, but coded instructions that make up a program****. Central Processing Unit Main Memory instruction instruction instruction data data data
Anatomy of an Instruction
- Instruction sets have a simple structure
- Broken into fields
- Operation (Opcode) - Verb
- Operands - Noun
- Recipes provide a near perfect analogy move flour,bowl add milk,bowl add egg,bowl mix bowl Operation (^) Operands
UNC-
- The UNC-101 is a simple 16-bit computer that we will use this semester to explore how computers work (http://www.unc.edu/courses/2008spring/comp/101/001/PS2)
- It has
- 65536 memory locations ( 16 )
- Each location has 16-bits
- 15 registers, that are referred to as ($1-$15)
- A special operand, $0, that can be used anywhere that a register is allowed. It provides a value of 0, and writes to it are ignored.
- A simple instruction set
Instructions: Concrete Examples
addi $4, $5, 1 Register[4] ← Register[5] + 1
- All instructions are broken to parts
- Operation codes (Opcodes), usually mnemonic
- Operands usually stylized (e.g. “$” implies the contents of the register, whose number follows)
Immediate Arithmetic Instructions
addi $D, $A, imm Reg[D] ← Reg[A] + imm subi $D, $A, imm Reg[D] ← Reg[A] - imm sgti $D, $A, imm Reg[D] ← 1 if (Reg[A] > imm) 0, otherwise
- Where D, A are one of {1,2, … 15}
- 2 operands come from registers
- Third, “Immediate” operand is a constant, which is encoded as part of the instructions
Multiply? Divide?
- You may have noticed that some math function are missing, such as multiply and divide
- Often, more complicated operations are implemented using a series of instructions called a routine
- Simple operations lead to faster computers, because it is often the case the speed of a computer is limited by the most complex task it has to perform. Thus, simple instructions permit fast computer (KISS principle)
Load/Store
- Certain instructions are reserved for accessing the contents of memory
- The only instructions that access memory
- Move data to registers, operate on it, save it st $D,$A memory[Reg[A]] ← Reg[D] ld $D,$A Reg[D] ← memory[Reg[A]] stx $D,$A,imm memory[Reg[A]+imm] ← Reg[D] ldx $D,$A,imm Reg[D] ← memory[Reg[A]+imm]
Bitwise Logic Instructions
and $D, $A, $B Reg[D] ← Reg[A] & Reg[B] or $D, $A, $B Reg[D] ← Reg[A] | Reg[B] xor $D, $A, $B Reg[D] ← Reg[A] ^ Reg[B]
- Where D, A, B are one of {1,2, … 15}
- All operands come from registers
- Performs a bitwise 2-input Boolean operation on the bits of the A and B operands and saves the result in D
- Assuming Reg[1] = 12 (0x000c) and Reg[2] = 10 (0x000a) and $3,$1,$2 # gives Reg[3] = 8 (0x0008) or $3,$1,$2 # gives Reg[3] = 14 (0x000e) xor $3,$1,$2 # gives Reg[3] = 6 (0x0006)
Closing the Gap
- A computer language closer to one we’d speak
- High-Level construct: total = item1 + item
- Assembly language: ldx $1,$0,item ldx $2,$0,item add $1,$1,$ stx $1,$0,total
- Binary (machine language): 0xf10f, 0x0008, 0xf20f, 0x0009, 0x0112, 0xf10e, 0x
An Assembler
- A symbolic machine language
- One-to-one correspondence between computer instruction = line of assembly
- Translates symbolic code to binary machine code
- Manages tedious details
- Locating the program in memory
- Figures out addresses (e.g. item1 rather than 0x0008)
- Generates a list of numbers