Introduction To MARIE, A Basic CPU Simulator

2y ago
97 Views
6 Downloads
1.04 MB
21 Pages
Last View : 4d ago
Last Download : 3m ago
Upload by : Madison Stoltz
Transcription

Introduction to MARIE, A Basic CPUSimulator2nd EditionJason Nyugen, Saurabh Joshi, Eric JiangTHE MARIE.JS TEAM (HTTPS://GITHUB.COM/MARIE-JS/)

Introduction to MARIE, A Basic CPU SimulatorCopyright 2016Second Edition Updated August 2016First Edition – July 2016By Jason Nyugen, Saurabh Joshi and Eric JiangThis document is licensed under the MIT LicenseTo contribute to our project visit: https//www.github.com/MARIE-js/MARIE.js/The MIT License (MIT)Copyright (c) 2016 Jason Nguyen, Saurabh Joshi, Eric JiangPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentationfiles (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOTLIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. INNO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Please reference this document at https://marie-js.github.io/MARIE.js/book.pdf for Student Integrity Policies for moreinformation please visit your university’s Student Integrity Policy.

Introduction to MARIE, A Basic CPU SimulatorContentsIntroduction to MARIE and MARIE.js . 2MARIE Instruction Set. 4Register Transfer Language . 6Introduction . 6RTL of Basic MARIE Code . 6Direct Addressing . 6Store X. 6Add X . 7Subt X . 7Jump X . 7Indirect Addressing . 7LoadI X . 7JnS X. 7JumpI X . 8Datapath Simulator . 9Register bank . 11Memory . 12Read control bus. 12Write control bus . 13Data bus . 13Address bus . 14Decode bus . 14The control unit, and putting it all together . 14Tutorials . 15A Simple Calculator . 15Concepts. 15Coding. 15Multiplication in MARIE. 17Explanation . 17Writing the Code . 17Full Code . 19Nyugen, Joshi and JiangPage 1 of 20

Introduction to MARIE, A Basic CPU SimulatorIntroduction to MARIE and MARIE.jsMARIE ('Machine Architecture that is Really Intuitive and Easy') is a machine architecture andassembly language served only for educational purposes from The Essentials of ComputerOrganization and Architecture (Linda Null, Julia Lobur). In addition, the publisher provides aset of simulator programs for the machine, written in Java. MARIE.js is a JavaScript versionimplementation of MARIE. It aims to be as faithful to the original Java programs as it can,while improving on features to make concepts more intuitive and easier to understand. Inthis book we will use MARIE.js this is available at: https://marie-js.github.io/MARIE.js/ Thebasic idea, is that the MARIE assembly language is a simple implementation of the vonNeumann architecture as shown below.An assembly language is the lowest level of abstraction you can get away from machinelanguage, which is binary code. Each instruction corresponds to its binary representation.There are several assembly languages, one for each machine architecture. More familiararchitectures like x86, ARM and MIPS are fairly complicated (x86 even more so than ARM andMIPS),which is why MARIE is designed to be easy to understand (hence its name).Nyugen, Joshi and JiangPage 2 of 20

Introduction to MARIE, A Basic CPU SimulatorSo in MARIE (as well as in other architectures) we have a collection of registers. Theseregisters are shown below: AC or Accumulator intermediate data is stored within the AC PC or Program Counter as the name suggests it stores the current position of theinstruction, with each instruction having its own address MAR or Memory Access Register stores or fetches the 'data' at the given address MBR or Memory Buffer Register stores the data when being transferred to or frommemory IR or Instruction Register: holds the current instructionNyugen, Joshi and JiangPage 3 of 20

Introduction to MARIE, A Basic CPU SimulatorMARIE Instruction SetIn MARIE, each instruction is 16 bits long with the first 4 bits representing the opcode and the remaining 12 bits are being used torepresent the address.For example the instruction CLEAR, the Opcode is A in HEX and 1010 in binary so the instruction will look something like1010.TypeArithmeticData TransferI/OInstructionHexSummaryOpcodeAdd X3Adds value in AC at address X into AC, AC AC XSubt X4Subtracts value in AC at address X into AC, AC AC - XAddI XBClearAAC 0Load X1Loads Contents of Address X into ACStore X2Stores Contents of AC into Address XInput5Request user to input a valueOutput6Prints value from ACNyugen, Joshi and JiangAdd Indirect: Use the value at X as the actual address of the data operand to add toACPage 4 of 20

Introduction to MARIE, A Basic CPU SimulatorJump XBranch9Jumps to Address XSkips the next instruction based on C: if (C) isSkipcond (C)8- 000: Skips if AC 0- 400: Skips if AC 0- 800: Skips if AC 0SubroutineJnS X0Jumps and Store: Stores PC at address X and jumps to X 1JumpI XCUses the value at X as the address to jump toStores value in AC at the indirect address.StoreIEe.g. StoreI addresspointerIndirectGets value from addresspointer, stores the AC value into the addressAddressingLoads value from indirect address into ACLoadIDe.g. LoadI addresspointerGets address value from addresspointer, loads value at the address into ACHaltNyugen, Joshi and Jiang7End the programPage 5 of 20

Introduction to MARIE, A Basic CPU SimulatorRegister Transfer LanguageIntroductionRegister Transfer Language or RTL shows how the CPU (Assembler) works. Within the CPUthere are many components including: AC or Accumulator : intermediate data is stored within the AC PC or Program Counter : as the name suggests it counts the current position of thecode, each line has it's own address MAR or Memory Access Register , stores or fetches the 'data' at the given address MBR or Memory Buffer Register , stores the data when being transferred IR or Instruction RegisterNote that the end of each code, you will need to increment the PC by 1, so:PC PC 1RTL of Basic MARIE CodeDirect AddressingLoad XAs explained earlier Load X loads the value from address X into the ACMAR XMBR M[MAR]AC MBR# load X (address) into MAR# load value stored at address into MBR# load value in MBR into ACStore XStore X stores the current value from the AC into address XMAR XMBR ACM[MAR] MBR# load address into MAR# load AC value into MBR# writes MBR value into the Memory of address indicated by the MARNyugen, Joshi and JiangPage 6 of 20

Introduction to MARIE, A Basic CPU SimulatorAdd XAdd X adds the value stored at address X into ACMAR XMBR M[MAR]AC AC MBR# load X into MAR# load value stored at address X into MBR# add value in AC with MBR value and store it back into ACSubt XSubt X subtracts the value in AC with the value stored at address XMAR XMBR M[MAR]AC AC - MBRJump XJump X jumps to address XPC XIndirect AddressingLoadI XLoadI X loads the value which is stored at address of the address X into the ACMARMBRMARMBRAC aluevaluevaluevalueX into MARstored at address X into MBRback into MAR (MAR cant write itself)into MBR stored at the address indicate by MARinto AC.JnS XJnS X or Jumps and Stores: Stores PC at address X and jumps to X 1MARMBRM[MAR]ACPC XPC 1MBRX 1ACNyugen, Joshi and Jiang#####loads value X into MARloads value of PC into MBRstores value in MBR into address of MARincrements X by 1 and stores it into ACjumps program counter to address indicated by ACPage 7 of 20

Introduction to MARIE, A Basic CPU SimulatorJumpI XJumpI X uses the value at X as the address to jump toMARMBRMARMBRPC XM[MAR]MBRM[MAR]MBRNyugen, Joshi and Jiang#####loads value X into MARloads value stored at address X into MBRloads value back into MARfetches the value at the address into MBRloads the value into PCPage 8 of 20

Introduction to MARIE, A Basic CPU SimulatorSubroutinesSubroutinesA subroutine is a sequence of instructions that is modular and can be executed multipletimes. If you are familiar with any programming language, you may see that subroutines aresimilar to functions. If you only dealt with functions in mathematics, you could viewsubroutines in terms of inputs and outputs. However the way they perform operations canbe quite different. Furthermore, MARIE doesn't provide a way to specify input or outputvalues (for programmers, parameter or return values).MARIE provides a way to call these subroutines by using the JnS instruction, and normalprogram execution can be resumed once the subroutine exits by using the JumpI instruction.ExampleHere is an example that prints the variable X, then halts the program:/ Enter subroutine PrintVariableXJnS PrintVariableXHaltPrintVariableX, HEX 000 / Used for storing return addressLoad XOutput/ Exit subroutine PrintVariableXJumpI PrintVariableXX, DEC 42The JnS instruction stores the address of the next instruction after it was called. In this case,the memory address points to the Halt instruction. This is the return address which will belater used to restore program execution. Once it has done that, it then jumps to theinstruction immediately below the label PrintVariableX, by using the memory addressof PrintVariableX and incrementing that value once.Once the subroutine performs its intended task, and runs the JumpI instruction, it loads thememory address stored at the PrintVariableX label, and stores it into the PC register. Note thatwe don't need to increment the PC register here as it is already taken care of in the fetch partof the fetch-decode-execute cycle before it entered the subroutine. Program execution isresumed from where it was, and the program halts as the Halt instruction is executed.The major part of subroutines is that it can be reused. Here is a slightly modified examplethat illustrates this.Nyugen, Joshi and JiangPage 9 of 20

Introduction to MARIE, A Basic CPU Simulator/ Call subroutine PrintVariableXJnS PrintVariableXLoad XAdd YStore XJnS PrintVariableX / Call subroutine PrintVariableX againHaltPrintVariableX, HEX 000 / Used for storing return addressLoad XOutput/ Exit subroutine PrintVariableXJumpI PrintVariableXX, DEC 42Y, DEC 5It doesn't matter where you call the subroutines (unless the subroutine calls itself), or howmany calls you make to the subroutines. The return address will be overwritten, and programexecution will always be resumed to where it was once the subroutine exits.Nyugen, Joshi and JiangPage 10 of 20

Introduction to MARIE, A Basic CPU SimulatorDatapath SimulatorThe datapath simulator is incorporated into MARIE.js, and can be accessed via themenu: View Datapath.The purpose of this visualisation is to give an understanding of how instructions and microinstructions relate to sequence of physical signals.Register bankThe MARIE simulator register bank is a set of 7 registers used for different purposes. Forexample, the PC register holds the memory address that points to the next instruction.Here is a list of the registers used in the MARIE simulator.NameOpcodeAbbreviation# of bits storedMemory Address Register001MAR12Program Counter010PC12Memory Buffer ut110OUT16Instruction Register111IR16Nyugen, Joshi and JiangPage 11 of 20

Introduction to MARIE, A Basic CPU SimulatorMemoryThe memory stores data in a sequence of locations. At this point of time, nothing much isshown in the memory, apart from whether data is being read from or written to memory.It is important to know that the data in each memory cell has no meaning in itself. Forexample, a memory cell may represent as data 0000 (which is very common as usually mostof memory cells are empty), but can also be seen as a JnS instruction with memoryaddress 000, as the highest hexadecimal value is the same as the opcode for the JnSinstruction.Read control busThe read control bus tells which register (or memory) to output data into the data bus.AbbreviationOpcodeActivate WiresM[MAR]000*MrMAR001P0PC010P1MBR011P1 P0AC100P2IN101P2 P0OUT110P2 P1IR111P2 P1 P0* While the memory opcode is 000, it technically means that we do not want to access anyregister. This is the reason why we have a separate memory read wire so that we can tell thememory exactly when we want to fetch the contents of one memory cell.Nyugen, Joshi and JiangPage 12 of 20

Introduction to MARIE, A Basic CPU SimulatorWrite control busThe write control bus tells which register (or memory) to read from the data bus andoverride its value.AbbreviationOpcodeActivate WiresM[MAR]000*MwMAR001P3PC010P4MBR011P4 P3AC100P5IN101P5 P3OUT110P5 P4IR111P5 P4 P3* Like what is said previously in the read control bus section, this opcode just means do notwrite to any register. A separate memory write wire is activated instead when we need towrite to memoryData busThe data bus is 16 bits long, and is used for transferring data (which may hold memoryaddresses) between registers and/or the memory. It is connected to all registers as well asthe memory.Nyugen, Joshi and JiangPage 13 of 20

Introduction to MARIE, A Basic CPU SimulatorAddress busThe address bus is 12-bits long, and is connected to both the MAR register and the memory.Decode busThe "decode bus" is 4-bits long, and is connected to both the IR register and the controlunit. Only the highest 4 bits of the IR register is connected to the decode bus, which is usedas input for decoding which instruction is needed to be executed.The control unit, and putting it alltogetherThe control unit handles both the register bank, the memory, and the ALU. It does this bygenerating a sequence of signals, depending on what instruction it has decoded. Allinstructions begin with the fetch cycle, which the control unit fetches the next instructionfrom memory, and increments the program counter. Once the instruction is decoded, itexecutes the instruction by performing the corresponding sequence of RTL operations. EachRTL operation has its own set of signals that needs to be generated.The active 'LED' in the time sequence signal labelled Tn where n is an unsigned integer, showshow many RTL operations have been performed before the current one within the currentinstruction. These sequential signals are reset once the control unit has finished executingthe current instruction and is ready to execute the next instruction.The first three (T0, T1, T2) time sequence signals are dedicated to the fetch part of the fetchdecode-execute cycle. The rest of the time sequence depends on what instruction thecontrol unit has decoded from the IR.Nyugen, Joshi and JiangPage 14 of 20

Introduction to MARIE, A Basic CPU SimulatorTutorialsA Simple CalculatorIn this tutorial we are going to write some code which assembles a simple additioncalculator.ConceptsVariables in MARIE are in string, for example both the variables X and value work in MARIE.Variables are typically declared at the bottom of the code.The instruction INPUT takes a user input and loads it in

Introduction to MARIE, A asic PU Simulator Nyugen, Joshi and Jiang Page 2 of 20 Introduction to MARIE and MARIE.js MARIE ('Machine Architecture that is Really Intuitive and Easy') is a machine architecture and

Related Documents:

work/products (Beading, Candles, Carving, Food Products, Soap, Weaving, etc.) ⃝I understand that if my work contains Indigenous visual representation that it is a reflection of the Indigenous culture of my native region. ⃝To the best of my knowledge, my work/products fall within Craft Council standards and expectations with respect to

65 BLONDEL Jean LEFER Marie Françoise Mametz Aire/Lys 1750 837 203 66 BLOT Guillaume TAVERNE Marie Jeanne Coulomby 1765 871 237 67 BLOT Jean Baptiste WINTREBERT Marie Pétronille Esquerdes 1773 887 253 68 BLOT Pierre TAVERNE Marie Jeanne Coulomby 1764 866 232 .

Sault Ste. Marie is a major North American steel manufacturing centre and a regional transportation and logistics hub. 1. The data in this report is based on the Sault Ste. Marie census agglomeration area, which includes the City of Sault Ste. Marie, the townships of Laird, Macdonald, Meredith and Aberdeen Additional, Prince, and the Garden .

akuntansi musyarakah (sak no 106) Ayat tentang Musyarakah (Q.S. 39; 29) لًََّز ãَ åِاَ óِ îَخظَْ ó Þَْ ë Þٍجُزَِ ß ا äًَّ àَط لًَّجُرَ íَ åَ îظُِ Ûاَش

Collectively make tawbah to Allāh S so that you may acquire falāḥ [of this world and the Hereafter]. (24:31) The one who repents also becomes the beloved of Allāh S, Âَْ Èِﺑاﻮَّﺘﻟاَّﺐُّ ßُِ çﻪَّٰﻠﻟانَّاِ Verily, Allāh S loves those who are most repenting. (2:22

Visual Basic - Chapter 2 Mohammad Shokoohi * Adopted from An Introduction to Programming Using Visual Basic 2010, Schneider. 2 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events. 3 2.1 An Introduction to

59 TV Oranje Basic Light Basic Basic 23.5 12187 H 29900 2/3 60 Schlager TV Basic Light Basic Basic 00.0 0 H 0 61 INPLUS Basic Light Basic Basic 19.2 11229 V 22000 2/3 TV VLAANDEREN is een merk gebruikt onder licentie door Canal Luxembourg S. à r.l. Maatschappelijke zetel: Rue Albert Borschette 4, L-1246 Luxembourg

Astrodienst Ephemeris Tables for the year 1993 tropical zodiac contains Sun, Moon, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, True Node, Moon's .