THE SIMPLE COMPUTER (SIM) The SIM CPU and Memory The Simple Computer (SIM) consists of a central processing unit (CPU) and a memory. Memory consists of 1000 memory cells, each of which contains a 4-digit decimal number called a word. The processor contains a processor register called the accumulator (acc) that also contains a 4-digit number. +-------------CPU-------------+ | | | +------+ | | acc | 0000 | | | +------+ | | | +-----------------------------+ / \ /| |\ | | | | \| |/ \ / +----------------+ | | | addr cont | | +------+ | | 000 | 1004 | | | +------+ | | 001 | 3005 | | | +------+ | | 002 | 2006 | | | +------+ | | 003 | 0000 | | | +------+ | | 004 | 0123 | | | +------+ | | 005 | 2222 | | | +------+ | | 006 | 0000 | | | +------+ | | ... ... | | +------+ | | 998 | 0000 | | | +------+ | | 999 | 0000 | | | +------+ | | | +-----MEMORY-----+ 2 Memory is a passive device that responds to fetch and store requests from the processor. To perform a fetch, the processor sends memory a 3-digit address (e.g. 005) and memory responds by sending the word at that address (e.g. 2222) back to the processor. The content of memory is not changed. To perform a store, the processor sends memory an address (e.g. 006) and a new contents (e.g. 2345). The new contents (2345) replaces the old contents (0000). A Very Simple SIM Program Memory contains both the data to be manipulated and the machine language instructions that manipulate the data. The following machine language program occupies memory addresses 000 through 006. Addresses 000 through 003 contain machine language instructions while addresses 004 through 006 contain the data to be manipulated. address contents function 000 1004 load the contents of memory cell 004 into the accumulator 001 3005 add the contents of memory cell 005 to the number in the accumulator 002 2006 store the number in the accumulator into memory cell 006 003 0000 halt the processor. 004 0123 005 2222 006 0000 This program illustrates the operation of four of the five different machine language instructions described below. instruction name effect 0000 halt halt the processor 1xxx ld load the number in memory cell xxx into the accumulator 2xxx st store the number in the accumulator into memory cell xxx 3xxx add add the number in memory cell xxx to the accumulator 4xxx sub subtract the number in memory cell xxx from the accumulator If the program in memory cells 000 through 006 is executed beginning at address 000, it will compute 0123 plus 2222 or 2345, store this result in address 006, and halt. Machine, Assembly, and High-Level Languages The following table shows the same program in three different types of languages. Normally, humans write code in a high-level language (the program on the right). A program called a compiler translates the high-level language program into an assembly language program (center). A program called an assembler translates the assembly language program into a machine language program (on the left) which is executed by the computer hardware. MACHINE LANGUAGE ASSEMBLY LANUGAGE HIGH LEVEL LANGUAGE 000 0030 a: .word 30 int a = 30; 001 0020 b: .word 20 int b = 20; 002 0000 sum: .word int sum; 003 0000 dif: .word int dif; 004 1000 start: ld a sum = a + b; 005 3001 add b 006 2002 st sum 007 1000 ld a dif = a - b; 008 4001 sub b 009 2003 st dif 010 0000 halt exit(0); 004 .end start Some things to notice. 1. Languages like C and Java are called high level languages because each statement in a high-level language may be translated into several assembly language or machine language statements. For example, the statement "sum = a + b;" is translated into three assembly and machine language statements. High level languages are "many to one". 2. Assembly language is just a "symbolic" way of representing a machine language program. Machine language consists of numerical addresses and operation codes. In assembly language, these numbers have been replaced by symbolic addresses and operation codes. Assembly language and machine language are "one to one". numerical symbolic numerical symbolic address address opcode opcode 000 a 0000 halt 001 b 1xxx ld 002 sum 2xxx st 003 dif 3xxx add 004 start 4xxx sub 3. In the assembly language version, ".word" is like "int" in a high-level language. The line ".end start" specifies that the program should begin execution at address "start" or "004".