4.8.3 MARIE's Instruction Set MARIE has a very simple instruction set (yet it is reasonably powerful). Instructions need to be coded into binary. Each word in our computer is 16 bits wide, and (it appears that) we need 12 bits for at least one operand, so that means that we have 4 bits for the instruction code. This means that we can have up to 24 (16) instructions. Each instruction, therefore, will be represented as a 4-bit number in the range 0-15. These are the MARIE instructions: We are cheating on the input and output. In a real computer, numbers have to be converted from sequences of ASCII characters into their equivalent binary value. We are assuming that all input values have automatically been converted when they get into the Input register. And we will assume that the reverse process also happens automatically for the Output register. Note that all instructions must be in binary form for the computer to be able to execute them (which makes sense since we can only put zeros and ones into the computer's memory). However, there are two other ways to represent MARIE's instructions: 1. In Hex (column 2 of table above) 2. With an English word (e.g. Load, Store, etc., in column 3 of the table above) The instructions in numeric format are called machine language. The instructions in the form of English words are called assembly language. 4.8.4 Register Transfer Notation Each instruction can be broken down into smaller steps. These smaller steps are called microinstructions and they can be represented by using something called register transfer notation. A register transfer notation instruction represents the movement of data from one register to another in the CPU. To be able to do this, the registers must be connected: Note that for each instruction below, we assume that the following micro-instructions (which are the same for all instructions) have been executed. Fetch the instruction MAR PC MBR M[MAR] IR MBR PC PC + 1 NOTE: In the places where I use the notation "IR[Addr]" (see below), the author used "X". My notation more accurately describes what is going on. After the instruction has been fetched (above), the instruction is executed: Load X (op code = 1) MAR IR[Addr] MBR M[MAR] AC MBR NOTE: In the following instruction, the reason that the first two microinstructions can be executed in parallel is that they use different busses! Store X (op code = 2) MAR IR[Addr], M[MAR] MBR Add X (op code = 3) MAR IR[Addr] MBR M[MAR] AC AC + MBR Subt X (op code = 4) MAR IR[Addr] MBR M[MAR] AC AC - MBR Input (op code = 5) AC InREG Output (op code = 6) OutREG AC MBR AC Halt (op code = 7) No register transfer operations are performed. The program stops. Skipcond Note that this is actually 3 different instructions. The four bits of the op code are the same, but the instruction is effectively extended by two more bits. If you were writing instructions in assembly language, this instruction would most likely have 3 different forms: Skipcond Positive If AC > 0 then PC PC + 1 Skipcond Negative If AC < 0 then PC PC + 1 Skipcond Zero If AC = 0 then PC PC + 1 Jump X PC IR[Addr] 4.9 Instruction Processing 4.9.3 MARIE'S I/O Actual input and output on a real computer are somewhat complicated. MARIE makes one significant change from real CPUs: it glosses over the complications of input and output (and we should be glad that it does – real I/O is ugly). INPUT: When an Input instruction is executed on MARIE, the computer simply waits until the user presses a key (or keys) on the keyboard and presses the Enter key. Whatever the user types is copied directly into the inReg register, and then immediately (and automatically in this case) copied into the Accumulator register. OUTPUT: When an Output instruction is executed on MARIE, the computer copies the value in the Accumulator register to the outReg register, which causes it to be displayed on the output device. 4.10 A SIMPLE PROGRAM A program to add two numbers from memory. Hex Address Assembly language instruction Machine language instruction (Hex) 100 Load 104 1104 101 Add 105 3105 102 Store 106 2106 103 Halt 7000 104 0023 0023 105 FFE9 FFE9 106 0000 0000 Things to note: Program starts at location 100, not 0 All addresses are in HEX All data are in HEX All instructions are in HEX EVERY Assembly language instruction has a corresponding machine language instruction. Machine language and assembly language are equivalent. Here is the difference: Assembly language instructions are meant to be read by a person; machine language instructions are meant to be read by a computer. NOTE: The register transfer notation for this program is on page 205 in the textbook. Do the following: 1. Assemble this program by hand. 2. Execute this program by hand. 3. Use the MARIE editor to enter the assembly language version of the program. 4. Use the MARIE assembler to assemble the program into machine language. 5. Use the MARIE simulator to run the program.