1.02k likes | 1.18k Views
Look what I found in the attic…. Programming Fundamentals 4 Feliks Klu ź niak. Executive summary : We look at the principles of operation of a very simple computer. An A1 computer!. I/O devices. CPU. MEMORY. An A1 computer!. I/O devices. CPU.
E N D
Look what I found in the attic… Programming Fundamentals 4 Feliks Kluźniak Found in the attic
Executive summary: We look at the principles of operation of a very simple computer. Found in the attic
An A1 computer! I/O devices CPU MEMORY Found in the attic
An A1 computer! I/O devices CPU This sort of architecture is obsolete now, but it is simple! MEMORY Found in the attic
An A1 computer! I/O devices CPU CAVEAT: This presentation is somewhat simplified, don’t show it to electrical engineers. This sort of architecture is obsolete now, but it is simple! MEMORY Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: . . . Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: An address has 16 bits, so there are at most how many words? . . . Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: An address has 16 bits, so there are at most 2**16 = 65536 words. . . . Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: An address has 16 bits, so there are at most 2**16 = 65536 words. It’s easier to count it in terms of “kilos”, where 1 K = 2**10 = 1024. So we may have upto how many kilo words? . . . Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: An address has 16 bits, so there are at most 2**16 = 65536 words. It’s easier to count it in terms of “kilos”, where 1 K = 2**10 = 1024. So we may have upto 64kilo words. . . . Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: An address has 16 bits, so there are at most 2**16 = 65536 words. It’s easier to count it in terms of “kilos”, where 1 K = 2**10 = 1024. So we may have upto 64kilo words. Or 160KB(kilo bytes). . . . Found in the attic
Memory: Each word has 20 bits Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … at most 1111111111111111: An address has 16 bits, so there are at most 2**16 = 65536 words. It’s easier to count it in terms of “kilos”, where 1 K = 2**10 = 1024. So we may have upto 64kilo words. Or 160 KB (kilo bytes). This is the size of the address space. But our actual machine has only 8 K words (40 KB). . . . Found in the attic
Memory: Each word has 20 bits This is random access memory. Each word has an address, and each particular word can be accessed in essentially constant time. Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … . . . Found in the attic
Memory: Each word has 20 bits This is random access memory. Each word has an address, and each particular word can be accessed in essentially constant time. “Random access” does not mean we access words randomly, but that accessing them in random order is as efficient as accessing them in sequence. Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … . . . Found in the attic
Memory: Each word has 20 bits This is random access memory. Each word has an address, and each particular word can be accessed in essentially constant time. This main memory is often called core memory. Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … . . . Found in the attic
Core memory: 1 ferrite core = 1 bit Found in the attic
Times have changed… Found in the attic
Memory: Each word has 20 bits The core memory holds data and programs. Programs are encoded as binary integers. Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … . . . Found in the attic
Memory: Each word has 20 bits The core memory holds data and programs. Programs are encoded as binary integers. In order to execute a program we must place it in core memory. “execute” = “run” Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … . . . Found in the attic
Memory: Each word has 20 bits The core memory holds data and programs. Programs are encoded as binary integers. In order to execute a program we must place it in core memory. (We will soon see how.) Addresses: 0000000000000000: 0000000000000001: 0000000000000010: 0000000000000011: … . . . Found in the attic
The CPU has access to three registers which are its interface to the memory: Found in the attic
The CPU has access to three registers which are its interface to the memory: A register is a short sequence of bits (about one word) which is held in fast electronic circuits and often can be manipulated in various ways. Found in the attic
The CPU has access to three registers which are its interface to the memory: Roughly speaking: that which allows two entities to interact. Found in the attic
The CPU has access to three registers which are its interface to the memory: • The Memory Address: MA (16 bits) Found in the attic
The CPU has access to three registers which are its interface to the memory: • The Memory Address: MA (16 bits) • The Memory Register: MR (20 bits, i.e., one word) Found in the attic
The CPU has access to three registers which are its interface to the memory: • The Memory Address: MA (16 bits) • The Memory Register: MR (20 bits, i.e., one word) • The Write flag: W (1 bit) Found in the attic
The CPU has access to three registers which are its interface to the memory: • The Memory Address: MA (16 bits) • The Memory Register: MR (20 bits, i.e., one word) • The Write flag: W (1 bit) CPU MR MMRR W MA Memory Found in the attic
To read from memory, the processor (CPU) sets W to zero, and MA to an address. The memory will place the contents of the addressed word in MR. CPU MR MMRR 0 MA Memory Found in the attic
To read from memory, the processor (CPU) sets W to zero, and MA to an address. The memory will place the contents of the addressed word in MR. MR := m[ MA ] CPU MR MMRR 0 MA Memory Found in the attic
To write to memory, the CPU fills MR with some contents, sets W to 1 and MA to an address. The memory will place the contents of MR at that address. CPU MR MMRR 1 MA Memory Found in the attic
To write to memory, the CPU fills MR with some contents, sets W to 1 and MA to an address. The memory will place the contents of MR at that address (the old contents of the word at that address will disappear!). m [ MA ] := MR CPU MR MMRR 1 MA Memory Found in the attic
The CPU has access to three registers which are its interface to the memory: • The Memory Address: MA (16 bits) • The Memory Register: MR (20 bits, i.e., one word) • The Write flag: W (1 bit) These three registers are ``hidden’’ from the programmer: she cannot manipulate them directly. CPU MR MMRR W MA Memory Found in the attic
Inside the CPU there are three registers: Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • On less ancient machines there are more registers. • But the IR and IC are always there. Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • On less ancient machines there are more registers. • But the IR and IC are always there. • IR is “hidden” from the programmer. • IC and A can be manipulated, the former somewhat • indirectly. • This will all become more clear presently. Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • A program is composed of one-word instructions. Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • A program is composed of one-word instructions. • The instruction counter (IC) holds the address of the next instruction to be executed. Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • A program is composed of one-word instructions. • The instruction counter (IC) holds the address of the next instruction to be executed. • The instruction register (IR) holds the instruction that is being executed. Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • A program is composed of one-word instructions. • The instruction counter (IC) holds the address of the next instruction to be executed. • The instruction register (IR) holds the instruction that is being executed. Here is the format of an instruction: • opcode operand • 4 bits 16 bits Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • A program is composed of one-word instructions. • The instruction counter (IC) holds the address of the next instruction to be executed. • The instruction register (IR) holds the instruction that is being executed. Here is the format of an instruction: • opcode operand Other machines have • 4 bits 16 bits other formats. Found in the attic
Inside the CPU there are three registers: • The instruction register: IR (20 bits, i.e., one word) • The instruction counter: IC (16 bits, i.e., an address) • The accumulator: A (20 bits, i.e., one word) • A program is composed of one-word instructions. • The instruction counter (IC) holds the address of the next instruction to be executed. • The instruction register (IR) holds the instruction that is being executed. Here is the format of an instruction: • opcode operand • 4 bits 16 bits The bits in the opcode activate various circuits. Essentially, opcode = kind of instruction. Found in the attic
opcode operand 4 bits 16 bits For example: opcode = 1 : store the contents of A , the operand is the address m[ operand ] := A Found in the attic
opcode operand 4 bits 16 bits For example: opcode = 1 : store the contents of A , the operand is the address m[ operand ] := A In other words, the contents of the accumulator is copied to the memory word indicated by the operand (the contents of the accumulator remain the same). Found in the attic
opcode operand 4 bits 16 bits For example: opcode = 1 : store the contents of A , the operand is the address m[ operand ] := A In other words, the contents of the accumulator is copied to the memory word indicated by the operand (the contents of the accumulator remain the same). The word “store” is justified by the fact that the memory used to be called “the store”. Found in the attic