·

Ciência da Computação ·

Organização de Computadores

Send your question to AI and receive an answer instantly

Ask Question

Preview text

4.8.1 The Architecture\nMARIE has the following characteristics:\n- Binary, two's complement\n- Stored program, fixed word length\n- Word (but not byte) addressable\n- 4K words of main memory (this implies 12 bits per address)\n- 16-bit data (words have 16 bits)\n- 16-bit instructions, 4 for the opcode and 12 for the address\n- A 16-bit accumulator (AC)\n- A 16-bit instruction register (IR)\n- A 16-bit memory buffer register (MBR)\n- A 12-bit program counter (PC)\n- A 12-bit memory address register (MAR)\n- An 8-bit input register\n- An 8-bit output register\n\nFIGURE 4.8 MARIE's Architecture\n\nare referenced implicitly in an instruction, as we see when we describe the instruction set for MARIE in Section 4.8.3.\n\nIn MARIE, there are seven registers, as follows:\n- AC: The accumulator, which holds data values. This is a general-purpose register and holds data that the CPU needs to process. Most computers today have multiple general-purpose registers.\n- MAR: The memory address register, which holds the memory address of the data being referenced.\n- MBR: The memory buffer register, which holds either the data just read from memory or the data ready to be written to memory.\n- PC: The program counter, which holds the address of the next instruction to be executed in the program.\n- IR: The instruction register, which holds the next instruction to be executed.\n- InREG: The input register, which holds data from the input device.\n- OutREG: The output register, which holds data for the output device. FIGURE 4.9 Datapath in MARIE\n\nBus\n 9\n ________\n | Main |\n | Memory|\n |________|\n |\n | 1\n V\n | MAR |\n |_________|\n |\n | 2\n V\n | PC |\n |_________|\n |\n | 3\n V\n | MBR |\n |_________|\n |\n | 4\n V\n | AC |\n |_________|\n |\n | 5\n V\n | InREG |\n |_________|\n |\n | 6\n V\n | OutREG |\n |_________|\n |\n | 7\n V\n | IR |\n |_________|\n |\n | 8\n V\n 16-bit bus\n\nFIGURE 4.10 MARIE's Instruction Format\n\n Bit 15 12 11 0\n Opcode Address\n\nInstruction Number\nBin Hex Instruction Meaning\n0001 1 Load X Load the contents of address X into AC.\n0010 2 Store X Store the contents of AC at address X.\n0011 3 Add X Add the contents of address X to AC and store the result in AC.\n0100 4 Subt X Subtract the contents of address X from AC and store the result in AC.\n0101 5 Input Input a value from the keyboard into AC.\n0110 6 Output Output the value in AC to the display.\n0111 7 Halt Terminate the program.\n1000 8 Skip Skip the next instructions on condition.\n1001 9 Jump X Load the value of X into FC.\n\nTABLE 4.2 MARIE's Instruction Set Load X\nRecall that this instruction loads the contents of memory location X into the AC. However, the address X must first be placed into the MAR. Then the data at location M[MAR] (or address X) is moved into the MBR. Finally, this data is placed in the AC.\n\n MAR ← X\n MBR ← M[MAR]\n AC ← MBR\n\nBecause the IR must use the bus to copy the value of X into the MAR, before the data at location X can be placed into the MBR, this operation requires two bus cycles. Therefore, these two operations are on separate lines to indicate they cannot occur during the same cycle. However, because we have a special connection between the MBR and the AC, the transfer of the data from the MBR to the AC can occur immediately after the data is put into the MBR, without waiting for the bus.\n\nStore X\nThis instruction stores the contents of the AC in memory location X:\n\n MAR ← X\n M[MAR] ← AC\n\nAdd X\nThe data value stored at address X is added to the AC. This can be accomplished as follows:\n\n MAR ← X\n MBR ← M[MAR]\n AC ← AC + MBR\n\nSubt X\nSimilar to Add, this instruction subtracts the value stored at address X from the accumulator and places the result back in the AC:\n\n MAR ← X\n MBR ← M[MAR]\n AC ← AC - MBR\n\nInput\nAny input from the input device is first routed into the InREG. Then the data is transferred into the AC:\n\n AC ← InREG\n\nOutput\nThis instruction causes the contents of the AC to be placed into the OutREG, where it is eventually sent to the output device:\n\n OutREG ← AC\n\nHalt\nNo operations are performed on registers; the machine simply ceases execution of the program. Skipcond\nRecall that this instruction uses the bits in positions 10 and 11 in the address field to determine what comparison to perform on the AC. Depending on this bit combination, the AC is checked to see whether it is negative, equal to 0, or greater than 0. If the given condition is true, then the next instruction is skipped. This is performed by incrementing the PC register by 1.\n\nChapter 4 / MARIE: An Introduction to a Simple Computer\nIf IR[11-10] = 00 then {If bits 10 and 11 in the IR are both 0}\nIf AC < 0 then PC <-- PC + 1\nelse if IR[11-10] = 01 then {if bit 11 = 0 and bit 10 = 1}\nIf AC = 0 then PC <-- PC + 1\nelse if IR[11-10] = 10 then {if bit 11 = 1 and bit 10 = 0}\nIf AC > 0 then PC <-- PC + 1\n\nIf the bits in positions ten and eleven are both ones, an error condition results. However, an additional condition could also be defined using these bit values.\n\nJump X\nThis instruction causes an unconditional branch to the given address, X. Therefore, to execute this instruction, X must be loaded into the PC.\n\nFC <- X\nIn reality, the lower or least significant 12 bits of the instruction register (or IR[11-0]) reflect the value of X. So this transfer is more accurately depicted as:\n\nFC <- IR[11-0]\n\nHex Address Instruction Binary Contents of Memory Address Hex Contents of Memory\n\nTABLE 4.3 A Program to Add Two Numbers Address Instruction\n\nTABLE 4.4 An Example Using Labels\n\nAddress Instruction\n\nTABLE 4.5 An Example Using Directives for Constants Instruction Number (hex) Instruction Meaning\n0 JnS X Store the PC at address X and jump to X + 1.\nA Clear Put all zeros in AC.\n5 AddI X Add indirect: Go to address X. Use the value at X as the actual address of the data operand to add to AC.\nC JumpI X Jump indirect: Go to address X. Use the value at X as the actual address of the location to jump to.\n\nTABLE 4.6 MARIE's Extended Instruction Set\n\nOpcode Instruction RTN\n0000 JnS X MBR <-- PC\nMAR <-- X\nM[MAR] <-- MBR\nMBR <-- X\nAC <-- AC + 1\nPC <-- AC\n0001 Load X MAR <-- X\nMBR <-- M[MAR]\nAC <-- MBR\n0010 Store X MAR <-- X, M[MAR] <-- AC\n0011 Add X MAR <-- X\nMBR <-- M[MAR]\nAC <-- AC + MBR\n0100 Subt X MAR <-- X\nMBR <-- M[MAR]\nAC <-- AC - MBR\n0101 Input AC <-- InREG\n0110 Output OutREG <-- AC\n0111 Halt\n1000 Skipcond If IR[11-10] = 00 then\nIf AC < 0 then PC <-- PC + 1\nElse If IR[11-10] = 01 then.\nIf AC = 0 then PC <-- PC + 1\nElse If IR[11-10] = 10 then.\nIf AC > 0 then PC <-- PC + 1\n1001 Jump X PC <-- IR[11-0]\n1010 Clear AC <-- 0\n1011 AddI X MAR <-- X\nMBR <-- M[MAR]\nMAR <-- MBR\nMBR <-- M[MAR]\nAC <-- AC + MBR\n1100 + JumpI X MAR <-- X\nMBR <-- M[MAR] EXAMPLE 4.1 Here is an example using a loop to add five numbers:\nAddress Instruction\n100 Load Addr /Load address of first number to be added\n101 Store Next /Store this address as our Next pointer\n102 Load Num /Load the number of items to be added\n103 Subt One /Decrement\n\n4.12 / Extending Our Instruction Set 211\n\n104 Store Ctr /Store this value in Ctr to control looping\n105 Loop,\n106 Add Sum /Load the Sum into AC\n107 Store Sum /Store this sum\n108 Load Next /Load Next\n109 Add One /Increment by one to point to next address\n10A Store Next /Store in our pointer Next\n10B Load Next /Load the loop control variable\n10C Subt One /Subtract one from the loop control variable\n10D Skipcond 000 /If control variable < 0, skip next\n10E Jump Loop /Otherwise, go to Loop\n10F Halt /Terminate program\n110 Addr, Hex 117 /Numbers to be summed start at location 118\n113 Next, Hex 0 /A pointer to the next number to add\n114 Num, Dec 5 /The number of values to add\n115 Sum, Dec 0 /The sum\n116 Ctr, Hex 1 /The loop control variable\n117 One, Dec 1 /Used to increment and decrement by 1\n118 15, Dec 15 /The values to be added together\n119 20, Dec 20\n11A 25, Dec 25\n11B 30, Dec 30\n\nNote: Line numbers in program are given for information only and are not required for use in the MarieSim environment. EXAMPLE 4.2 This example illustrates the use of an if/else construct to allow for selection. In particular, it implements the following:\n\nif X = Y then\n X = X * 2;\nelse\n Y = Y - X;\n\nAddress Instruction\n100 If, Load X /Load the first value\n101 Subt Y /Subtract the value of Y, store result in AC\n102 Skipcond 400 /If AC = 0, skip the next instructions\n103 Jump Else /Jump to Else part if AC is not equal to 0\n104 Then, Load X /Reload X so it can be doubled\n105 Add X /Double X\n106 Store X /Store the new value\n107 Jump Endif /Skip over the false, or else, part to end of it\n\nElse, Load Y /Start the else part by loading Y\n101 Subt X /Subtract X from Y\n102 Store Y /Store Y in Y\n103 Halt /Terminate program (it doesn't do much!)\n104 Endif, Load the loop control variable\n106 X, Dec 20 /Subtract one from the loop control variable\n\nExample 4.3 demonstrates how JnS and Jump are used to allow for subroutines. This program includes an additional subroutine, another example of an assembly directive. This statement tells the assembler where the program ends. Other potential directives include statements to let the assembler know how big the first program instruction, how to set up memory, and whether blocks of code are procedures. EXAMPLE 4.3 This example illustrates the use of a simple subroutine to double any number and can be coded.\nAddress Instruction\n100 Load X /Load the first number to be doubled\n101 Store Temp /Use Temp as a parameter to pass value to Subr\n102 JnS Subr /Store return address, jump to procedure\n103 Store Y /Store first number, doubled\n104 Load Y /Load the second number to be doubled\n105 Store Temp /Use Temp as a parameter to pass value to Subr\n106 JnS Subr /Store return address, jump to procedure\n107 Store Y /Store second number, doubled\n108 Halt /End program\n109 X, Dec 20 /\n10A Y, Dec 48 /\n10B Temp, Dec 0 /\n\nNote: Line numbers in program are given for information only and are not required for use in the MarieSim environment.\n\nUsing MARIE's simple instruction set, you should be able to implement any high-level programming language construct, such as loop statements and while statements. These are left as exercises at the end of the chapter.