ORG 00 / Address Jump Start / 000 Temp0, Hex 0 / 001 Temp1, Hex 0 / 002 Multa, Hex 0030 / 003 Address of Multa[0] Used by internal subroutines Mult, Div, and PrintDec Multb, Hex 0040 / 004 Address of Multb[0] Used by internal subroutines Mult, Div, and PrintDec DecStr, Hex 0050 / 005 Address of DecStr[0] Used by internal subroutines PrintDec One, Dec 1 / 006 One & True StackB, JnS B_Stack / 007 Address of first cell in the Recursion Stack StackP, Hex 0 / 008 Next cell in the Recursion stack to push on data. Hex 0 / 009 Hex 0 / 00A Hex 0 / 00B Hex 0 / 00C Hex 0 / 00D Hex 0 / 00E Hex 0 / 00F input0, Hex 0010 / 010 Values being passed into procedure input1, Hex 0011 / 011 input2, Hex 0012 / 012 input3, Hex 0013 / 013 input4, Hex 0014 / 014 input5, Hex 0015 / 015 input6, Hex 0016 / 016 input7, Hex 0017 / 017 input8, Hex 0018 / 018 input9, Hex 0019 / 019 inputA, Hex 001A / 01A inputB, Hex 001B / 01B inputC, Hex 001C / 01C inputD, Hex 001D / 01D Return, Hex 001E / 01E Return value for procedure B_ExpS, JnS B_ExpS / 01F Mark the beginning of the ExpS and contains its own address ExpS0, Hex 0020 / 020 Expression Evaluation Stack ExpS1, Hex 0021 / 021 ExpS2, Hex 0022 / 022 ExpS3, Hex 0023 / 023 ExpS4, Hex 0024 / 024 ExpS5, Hex 0025 / 025 ExpS6, Hex 0026 / 026 ExpS7, Hex 0027 / 027 ExpS8, Hex 0028 / 028 ExpS9, Hex 0029 / 029 ExpSA, Hex 002A / 02A ExpSB, Hex 002B / 02B ExpSC, Hex 002C / 02C ExpSD, Hex 002D / 02D ExpSE, Hex 002E / 02E L_ExpS, Hex 000F / 02F Lenght of ExpS / for(i=030 to 05F) Hex i Used for Multa,Multb,DecStr Hex 30 Hex 31 Hex 32 Hex 33 Hex 34 Hex 35 Hex 36 Hex 37 Hex 38 Hex 39 Hex 3a Hex 3b Hex 3c Hex 3d Hex 3e Hex 3f Hex 40 Hex 41 Hex 42 Hex 43 Hex 44 Hex 45 Hex 46 Hex 47 Hex 48 Hex 49 Hex 4a Hex 4b Hex 4c Hex 4d Hex 4e Hex 4f Hex 50 Hex 51 Hex 52 Hex 53 Hex 54 Hex 55 Hex 56 Hex 57 Hex 58 Hex 59 Hex 5a Hex 5b Hex 5c Hex 5d Hex 5e Hex 5f /************************************************************************************/ /* StoreInArray: */ /* Input: AC: address of a[0] */ /* ExpS0: index into a */ /* ExpS1: value to store */ /* Operation: a[ExpS0] = ExpS1; */ /* For example if AC=30, ExpS0=5, and ExpS1=72, then a[5]=72; */ /************************************************************************************/ StoreInArray, Hex 0 / Entry Point and Return Address / AC holds address of a[0] (eg 30) Add ExpS0 / Address of a[ExpS0] which is 35 Add StoreC / Add the command 2 to the front of the 35 / producing the command 2035. / This is the machine code for "Store 35" / which stores the value in AC into the cell addressed by 35 Store MadeC / Write this machine code where we need to execute it Load ExpS1 / Loads ExpS1 which is 72 into the accumulator MadeC, Hex 0 / Execute the machine code 2035 stored here / This stores the 72 in memory cell 35. JumpI StoreInArray / Return StoreC, Hex 2000 / The MARIE assembly code for "Store X" has the machine / code 2035 when x is memory cell 35 /************************************************************************************/ /* MStoreInArray: Same as StoreInArray but ExpSm changed to MExpSm for Mult & Div */ /************************************************************************************/ MStoreInArray, Hex 0 / Entry Point and Return Address / AC holds address of a[0] (eg 30) Add MExpS0 / Address of a[MExpS0] which is 35 Add StoreC / Add the command 2 to the front of the 35 / producing the command 2035. / This is the machine code for "Store 35" / which stores the value in AC into the cell addressed by 35 Store MMadeC / Write this machine code where we need to execute it Load MExpS1 / Loads MExpS1 which is 72 into the accumulator MMadeC, Hex 0 / Execute the machine code 2035 stored here / This stores the 72 in memory cell 35. JumpI MStoreInArray / Return /************************************************************************************/ /* Copy: A block of data is copied */ /* Input: CopyA is the address of first value to copy */ /* CopyB is the address of first cell to be copied to */ /* CopyL is the number of cells to be copied */ /************************************************************************************* Copy, Hex 0 / Entry Point and Return Address Load CopyB / Address of first cell to be copied to (say address is 35) Add StoreC / Add the command 2 to the front of the 35 / producing the command 2035. / This is the machine code for "Store 35" / which stores the value in AC into the cell addressed by 35 Store MadeC2 / Write this machine code where we need to execute it NextV, Clear AddI CopyA / Loads value to copy (say value is 72) MadeC2, Hex 0 / Execute the machine code 2035 stored here / This stores the 72 in memory cell 35. Load MadeC2 / Increment address in command giving where to copy to Add One Store MadeC2 Load CopyA / Increment address of value to copy Add One Store CopyA Load CopyL / Decrement CopyL to number of values left to copy Subt One Store CopyL Skipcond 400 / Skip if CopyL=0 because done copying values Jump NextV / Go copy next value JumpI Copy / Return CopyA, Hex 0 / Address of first value to copy CopyB, Hex 0 / Address of first cell to be copied to CopyL, Hex 0 / Number of cells to be copied /************************************************************************************/ /* Mult: */ /* Input: x,y (each <= 2^15-1 = 32767) */ /* Output: z = x*y */ /* Uses: */ /* Multa[i] = 2^i */ /* Multb[i] = 2^i * y */ /* i index for Multa & Multb */ /* neg boolean sign flag */ /* MExpS0,MExpS1,MExpS2,MExpS3 Same as ExpSm */ /* */ /* Written by Jeff See notes for proof of correctness */ /************************************************************************************* Mult, Hex 0 / Entry Point and Return Address /GetAssignmentv: neg = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetAss: neg = MExpS0; Load MExpS0 Store neg /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = x; Load Mx Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 0; Clear Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 000 Jump M002 /Jump over data line Load One Jump M003 /Jump over data line M002, Clear M003, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M000 /Else Jump to ElseCode /GetAssignmentv: x = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = x; Load Mx Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: x = MExpS0; Load MExpS0 Store Mx /GetAssignmentv: neg = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 1; Load One Store MExpS0 /GetAss: neg = MExpS0; Load MExpS0 Store neg Jump M001 /Jump to EndIf M000, Clear /ElseCode M001, Clear /EndIf /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multa JnS MStoreInArray /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = y; Load My Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multb JnS MStoreInArray /GetAssignmentv: i = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetAss: i = MExpS0; Load MExpS0 Store Mi /GetWhileStatement: M005, Clear /TopWhile /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = Multa[Exp]; /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = i; Load Mi Store MExpS1 Load Multa /Load address of Multa[0] Add MExpS1 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS0 /Save it /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = x; Load Mx Store MExpS1 Load MExpS0 Subt MExpS1 Subt One SkipCond 000 Jump M006 /Jump over data line Load One Jump M007 /Jump over data line M006, Clear M007, Store MExpS0 SkipCond 800 /If(true) Skip to code in while Jump M004 /Else Jump to EndWhile /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multa /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS2 = next term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = Multa[Exp]; /GetExp: MExpS3 = Exp = Term + ... + Term; /GetTerm: MExpS3 = Term = Fact * ... * Fact; /GetFact: MExpS3 = i; Load Mi Store MExpS3 Load Multa /Load address of Multa[0] Add MExpS3 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS2 /Save it /GetExp: MExpS1 = MExpS1 + MExpS2 Load MExpS1 Add MExpS2 Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multa JnS MStoreInArray /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multb /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS2 = next term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = Multa[Exp]; /GetExp: MExpS3 = Exp = Term + ... + Term; /GetTerm: MExpS3 = Term = Fact * ... * Fact; /GetFact: MExpS3 = i; Load Mi Store MExpS3 Load Multb /Load address of Multa[0] Add MExpS3 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS2 /Save it /GetExp: MExpS1 = MExpS1 + MExpS2 Load MExpS1 Add MExpS2 Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multb JnS MStoreInArray /GetAssignmentv: i = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetAss: i = MExpS0; Load MExpS0 Store Mi Jump M005 /Jump back to TopWhile M004, Clear /EndWhile /GetAssignmentv: z = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetAss: z = MExpS0; Load MExpS0 Store Mz /GetWhileStatement: M009, Clear /TopWhile /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 0; Clear Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 800 Jump M010 /Jump over data line Load One Jump M011 /Jump over data line M010, Clear M011, Store MExpS0 SkipCond 800 /If(true) Skip to code in while Jump M008 /Else Jump to EndWhile /GetAssignmentv: i = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: i = MExpS0; Load MExpS0 Store Mi /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = Multa[Exp]; /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = i; Load Mi Store MExpS1 Load Multa /Load address of Multa[0] Add MExpS1 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS0 /Save it /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = x; Load Mx Store MExpS1 Load MExpS0 Subt MExpS1 Subt One SkipCond 000 Jump M014 /Jump over data line Load One Jump M015 /Jump over data line M014, Clear M015, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M012 /Else Jump to ElseCode /GetAssignmentv: x = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = x; Load Mx Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multa /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: x = MExpS0; Load MExpS0 Store Mx /GetAssignmentv: z = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = z; Load Mz Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multb /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetAss: z = MExpS0; Load MExpS0 Store Mz Jump M013 /Jump to EndIf M012, Clear /ElseCode M013, Clear /EndIf Jump M009 /Jump back to TopWhile M008, Clear /EndWhile /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = neg; Load neg Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 400 Jump M018 /Jump over data line Load One Jump M019 /Jump over data line M018, Clear M019, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M016 /Else Jump to ElseCode /GetAssignmentv: z = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = z; Load Mz Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: z = MExpS0; Load MExpS0 Store Mz Jump M017 /Jump to EndIf M016, Clear /ElseCode M017, Clear /EndIf JumpI Mult / Return Mx, Hex 0 / Input to Mult & Div My, Hex 0 / Input to Mult & Div Mz, Hex 0 / Output from Mult & Div Mi, Hex 0 / index for Multa used Mult & Div neg, Hex 0 / saves if x is negative used Mult & Div MExpS0, Hex 0 / Same as ExpSm MExpS1, Hex 0 MExpS2, Hex 0 MExpS3, Hex 0 /************************************************************************************/ /* Div: */ /* Input: x,y (each <= 2^15-1 = 32767) */ /* Output: z = x/y (Also computes the remainder) */ /* x' = x%y is remainder */ /* i.e. z and x' so that x=z*y+x' and x' in [0,y) */ /* Uses: */ /* Multa[i] = 2^i */ /* Multb[i] = 2^i * y */ /* i index for Multa & Multb */ /* neg boolean sign flag */ /* */ /* Written by Jeff See notes for proof of correctness */ /************************************************************************************* Div, Hex 0 / Entry Point and Return Address /GetAssignmentv: neg = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetAss: neg = MExpS0; Load MExpS0 Store neg /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = x; Load Mx Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 0; Clear Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 000 Jump M022 /Jump over data line Load One Jump M023 /Jump over data line M022, Clear M023, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M020 /Else Jump to ElseCode /GetAssignmentv: x = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = x; Load Mx Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: x = MExpS0; Load MExpS0 Store Mx /GetAssignmentv: neg = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 1; Load One Store MExpS0 /GetAss: neg = MExpS0; Load MExpS0 Store neg Jump M021 /Jump to EndIf M020, Clear /ElseCode M021, Clear /EndIf /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = y; Load My Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 0; Clear Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 000 Jump M026 /Jump over data line Load One Jump M027 /Jump over data line M026, Clear M027, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M024 /Else Jump to ElseCode /GetAssignmentv: y = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = y; Load My Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: y = MExpS0; Load MExpS0 Store My /GetAssignmentv: neg = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 1; Load One Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = neg; Load neg Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: neg = MExpS0; Load MExpS0 Store neg Jump M025 /Jump to EndIf M024, Clear /ElseCode M025, Clear /EndIf /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multa JnS MStoreInArray /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = y; Load My Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multb JnS MStoreInArray /GetAssignmentv: i = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetAss: i = MExpS0; Load MExpS0 Store Mi /GetWhileStatement: M029, Clear /TopWhile /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = Multa[Exp]; /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = i; Load Mi Store MExpS1 Load Multb /Load address of Multa[0] Add MExpS1 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS0 /Save it /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = x; Load Mx Store MExpS1 Load MExpS0 Subt MExpS1 Subt One SkipCond 000 Jump M030 /Jump over data line Load One Jump M031 /Jump over data line M030, Clear M031, Store MExpS0 SkipCond 800 /If(true) Skip to code in while Jump M028 /Else Jump to EndWhile /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multa /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS2 = next term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = Multa[Exp]; /GetExp: MExpS3 = Exp = Term + ... + Term; /GetTerm: MExpS3 = Term = Fact * ... * Fact; /GetFact: MExpS3 = i; Load Mi Store MExpS3 Load Multa /Load address of Multa[0] Add MExpS3 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS2 /Save it /GetExp: MExpS1 = MExpS1 + MExpS2 Load MExpS1 Add MExpS2 Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multa JnS MStoreInArray /GetAssignmenta: Multa[Exp] = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multb /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS2 = next term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = Multa[Exp]; /GetExp: MExpS3 = Exp = Term + ... + Term; /GetTerm: MExpS3 = Term = Fact * ... * Fact; /GetFact: MExpS3 = i; Load Mi Store MExpS3 Load Multb /Load address of Multa[0] Add MExpS3 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS2 /Save it /GetExp: MExpS1 = MExpS1 + MExpS2 Load MExpS1 Add MExpS2 Store MExpS1 /GetAssignment: Multa[MExpS0] = MExpS1; Load Multb JnS MStoreInArray /GetAssignmentv: i = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetAss: i = MExpS0; Load MExpS0 Store Mi Jump M029 /Jump back to TopWhile M028, Clear /EndWhile /GetAssignmentv: z = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetAss: z = MExpS0; Load MExpS0 Store Mz /GetWhileStatement: M033, Clear /TopWhile /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 0; Clear Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 800 Jump M034 /Jump over data line Load One Jump M035 /Jump over data line M034, Clear M035, Store MExpS0 SkipCond 800 /If(true) Skip to code in while Jump M032 /Else Jump to EndWhile /GetAssignmentv: i = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = i; Load Mi Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: i = MExpS0; Load MExpS0 Store Mi /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = Multa[Exp]; /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = i; Load Mi Store MExpS1 Load Multb /Load address of Multa[0] Add MExpS1 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS0 /Save it /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = x; Load Mx Store MExpS1 Load MExpS0 Subt MExpS1 Subt One SkipCond 000 Jump M038 /Jump over data line Load One Jump M039 /Jump over data line M038, Clear M039, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M036 /Else Jump to ElseCode /GetAssignmentv: x = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = x; Load Mx Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multb /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: x = MExpS0; Load MExpS0 Store Mx /GetAssignmentv: z = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = z; Load Mz Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = Multa[Exp]; /GetExp: MExpS2 = Exp = Term + ... + Term; /GetTerm: MExpS2 = Term = Fact * ... * Fact; /GetFact: MExpS2 = i; Load Mi Store MExpS2 Load Multa /Load address of Multa[0] Add MExpS2 /Add the value i=Exp to address of Multa[0] for address of Multa[i] Store Temp0 Clear AddI Temp0 /Load the value of Multa[i] Store MExpS1 /Save it /GetExp: MExpS0 = MExpS0 + MExpS1 Load MExpS0 Add MExpS1 Store MExpS0 /GetAss: z = MExpS0; Load MExpS0 Store Mz Jump M037 /Jump to EndIf M036, Clear /ElseCode M037, Clear /EndIf Jump M033 /Jump back to TopWhile M032, Clear /EndWhile /GetIfStatement: /GetBooleanExp: MExpS0 = BooleanExp = BooleanTerm || ... || BooleanTerm; /GetBooleanTerm: MExpS0 = BooleanTerm = BooleanFact && ... && BooleanFact; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = neg; Load neg Store MExpS0 /GetExp: MExpS1 = Exp = Term + ... + Term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = 1; Load One Store MExpS1 Load MExpS0 Subt MExpS1 SkipCond 400 Jump M042 /Jump over data line Load One Jump M043 /Jump over data line M042, Clear M043, Store MExpS0 SkipCond 800 /If(true) Skip to 1st block of code Jump M040 /Else Jump to ElseCode /GetAssignmentv: z = Exp; /GetExp: MExpS0 = Exp = Term + ... + Term; /GetTerm: MExpS0 = Term = Fact * ... * Fact; /GetFact: MExpS0 = 0; Clear Store MExpS0 /GetExp: MExpS1 = next term; /GetTerm: MExpS1 = Term = Fact * ... * Fact; /GetFact: MExpS1 = z; Load Mz Store MExpS1 /GetExp: MExpS0 = MExpS0 - MExpS1 Load MExpS0 Subt MExpS1 Store MExpS0 /GetAss: z = MExpS0; Load MExpS0 Store Mz Jump M041 /Jump to EndIf M040, Clear /ElseCode M041, Clear /EndIf JumpI Div /************************************************************************************/ /* PrintDec: */ /* Input: x is an integer */ /* Output on screen x in ascii */ /* Uses: */ /* y,z,Multa,Multb,i,neg,MExpSm: Used by Div */ /* ExpS0,ExpS1: used by MStoreInArraya */ /* DecStr: Write the ascii in reverse */ /* ExpS0: index for DecStr */ /* */ /* Written by Jeff */ /************************************************************************************* PrintDec, Hex 0 / Entry Point and Return Address Load Ten Store ExpS0 / Next place to store a character is DecStr[Exp0] (assume #digits is at most 10) Load Ten Store My / We divide by 10 to get base 10 NextD, JnS Div / Divide z = x/10 x = x%10 Load Mx / Remainder is next low order digit Add Ascii0 / Cast digit into Ascii Store ExpS1 / Store next Ascii digit in ExpS1 Load DecStr / Address of DecStr[0] JnS StoreInArray / DecStr[ExpS0] = ExpS1 Load ExpS0 / --ExpS0 Subt One Store ExpS0 / Next place to store a character is DecStr[Exp0] Load Mz / The remaining high order digits of our number. Store Mx / is put back into x to be printed Skipcond 400 / Skip if x=0 because done getting digits Jump NextD / Go get next digit / done getting digits Load Ten / Where ExpS0 started Subt ExpS0 / # of digits to be printed Store StrL / Input to subroutine PrintStr Load DecStr / Address of DecStr[0] Add ExpS0 / Address of DecStr[ExpS0] Add One / Address of DecStr[ExpS0+1] is first Char to print Store Str / Input to subroutine PrintStr JnS PrintStr / Print the string JumpI PrintDec / Return Ten, Dec 10 / 10 for computing base 10 Ascii0, Dec 48 / Ascii for '0' /************************************************************************************/ /* PrintStr: */ /* Input: Str is address of first char in string to output */ /* StrL is number of characters to be outputted */ /* Output on screen string in ascii */ /************************************************************************************* PrintStr, Hex 0 / Entry Point and Return Address NextC, Clear AddI Str / Load next character to be printed Output / Output character Load Str / Increment Str to next character Add One Store Str Load StrL / Decrement StrL to number of characters left Subt One Store StrL Skipcond 400 / Skip if StrL=0 because done printing characters Jump NextC / Go print next character JumpI PrintStr / Return Str, Hex 0 / address of first char in string to output StrL, Hex 0 / number of characters to be outputted AsciiCR, Dec 13 / Ascii for carriage return /************************************************************************************/ /************************************************************************************/ /* */ /* The compiled MARIE code */ /* ------------------------- */ /* */ /************************************************************************************/ /************************************************************************************/ Start, Load StackB Store StackP / Initialize the Stack pointer (incase code run more than once.) JnS J_main Halt /********************* JoshJava Code to Compile ****************************/ /** public static void main (){ /** int i = 1; /** int x=2; /** int g=i+x; /** procedure(g); /** } /** public void procdure (int g){ /** int j = 10-gl /** System.out.print (j); /** } /***************************************************************************/