Advertisement
rglaurent1

Instructions Final Project

Jul 23rd, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 30.09 KB | None | 0 0
  1. .global asm_main
  2. .align 4
  3. memory: .space 2000000
  4. .align 4
  5.  
  6. asm_main:
  7.     LDR R2, =0x000103F0 ;@ should be Zmem
  8.     LDR R3, =0b01000000 ;@ Opcode test
  9.     STR R3, [R2]
  10. checkSize:
  11. ;@ Could check size to see if it even is an OPCODE
  12. ;@ If it is check the type
  13. ;@ Else crash
  14. checkType:
  15.     LDR R0, [R2]
  16.     LSR R1, R0, #6
  17.     CMP R1, #0b11
  18.     BEQ Ctype
  19.     CMP R1, #0b10
  20.     BEQ Atype
  21.     B Btype
  22.  
  23. Ctype:
  24.     MOV R5, #100
  25.     LSR R1, R0, #5
  26.     ANDS R1, #0b00000001
  27.     BEQ twoOperands
  28.     BNE variableOperands
  29.  
  30. Atype:
  31.     MOV R5, #200
  32.     LSR R1, R0, #4
  33.     AND R1, #0b00000011
  34.     CMP R1, #0b00000011
  35.     BEQ zeroOperands
  36.     BNE oneOperand
  37.  
  38. Btype:
  39.     MOV R5, #300
  40.     LSR R1, R0, #6
  41.     ANDS R1, #0b00000001
  42.     BEQ 1Bconstant
  43.     B 1Bindicator
  44.  
  45. twoOperands:
  46.     B twoOperands
  47. variableOperands:
  48.     B variableOperands
  49. zeroOperands:
  50.     B zeroOperands
  51. oneOperand:
  52.     B oneOperand
  53. -----------------------------------------------------------------------------------------------------------------------
  54. .global asm_main
  55. .align 4
  56. memory: .space 2000000
  57. .align 4
  58.  
  59. asm_main:
  60.     LDR R2, =0x000103F0 ;@ should be Zmem
  61.     LDR R3, =0b01100000 ;@ Opcode test
  62.     STR R3, [R2]
  63. checkSize:
  64. ;@ Could check size to see if it even is an OPCODE
  65. ;@ If it is check the type
  66. ;@ Else crash
  67. checkType:
  68.     LDRB R0, [R2]
  69.     LSR R1, R0, #6
  70.     CMP R1, #0b11
  71.     BEQ Ctype
  72.     CMP R1, #0b10
  73.     BEQ Atype
  74.     B Btype
  75.  
  76. Ctype:
  77.     AND R5, R0, #0b11000000
  78.     LSR R1, R0, #5
  79.     ANDS R1, #0b00000001
  80.     BEQ twoOperands
  81.     BNE variableOperands
  82.  
  83. Atype:
  84.     AND R5, R0, #0b11000000 ;@testing
  85.     LSR R1, R0, #4 ;@ shift 4th and 5th bit
  86.     AND R1, #0b00000011;@ Extract 4th and 5th bit
  87.     MOV R2, R1 ;@Store for later use in instruction finding
  88.     CMP R1, #0b00000011
  89.     BEQ zeroOperands
  90.     B oneOperand
  91.  
  92. Btype:
  93.     AND R5, R0, #0b11000000
  94.     LSR R1, R0, #6
  95.     ANDS R1, #0b00000001
  96.     BEQ 1Bconstant
  97.     B 1Bindicator
  98.  
  99. twoOperands:
  100.     ;@ Retrieve each operand and store them into R1 and R0
  101.     B twoOperands
  102.    
  103. variableOperands:
  104.     B variableOperands
  105.    
  106. zeroOperands:
  107.     AND R4, R0, #0b00110000
  108.     ADD R5, R4
  109.     B 4bitInstructionIndicator
  110.    
  111. oneOperand:
  112.     AND R4, R0, #0b00110000
  113.     ADD R5, R4
  114.     CMP R1, #0b10
  115.     BEQ 1Bindicator
  116.     CMP R1, #0b01
  117.     BEQ 1Bconstant
  118.     B 2Bconstant
  119.    
  120. 1Bconstant:
  121.     ;@ Retrieve Operand and store into R0
  122.     B instructionIndicator
  123.    
  124. 2Bconstant:
  125.     ;@ Retrieve Operand and store into R0
  126.     B instructionIndicator
  127.    
  128. 1Bindicator:
  129.     ;@ Retrieve Operand and store into R0
  130.     B instructionIndicator
  131.    
  132. 4bitInstructionIndicator:
  133.     AND R1, R0, #0b00001111
  134.     ADD R5, R1
  135.     CMP R2, #0b00000011 ;@R2 is
  136.     BEQ zero
  137.     B one
  138.  
  139. 5bitInstructionIndicator:
  140.     AND R1, R0, #0b00011111
  141.     ADD R5, R1
  142.     BL CfindInstruction
  143.     B 5bitInstructionIndicator
  144.  
  145. zero:
  146.     CMP R1, #0b00000010
  147.     BEQ PRINT
  148.     CMP R1, #0b00001000
  149.     BEQ RET_POPPED
  150.     CMP R1, #0b00001101
  151.     BEQ VERIFY
  152.     B crash
  153.    
  154. one:
  155.  
  156. ------------------------------------------------------------------------------------------------
  157. .global asm_main
  158. .align 4
  159. memory: .space 2000000
  160. .align 4
  161.  
  162. asm_main:
  163.     LDR R2, =0x000103F0 ;@ should be Zmem
  164.     LDR R3, =0b10101111 ;@ Opcode test
  165.     STR R3, [R2]
  166. checkSize:
  167. ;@ Could check size to see if it even is an OPCODE
  168. ;@ If it is check the type
  169. ;@ Else crash
  170. checkType:
  171.     LDRB R0, [R2]
  172.     LSR R1, R0, #6 ;@ shift 7th and 6th bits
  173.     CMP R1, #0b11
  174.     BEQ Ctype
  175.     CMP R1, #0b10
  176.     BEQ Atype
  177.     ;@B Btype
  178.  
  179. Ctype:
  180.     AND R5, R0, #0b11000000 ;@testing
  181.     LSR R1, R0, #5 ;@ shift 5th bit
  182.     AND R1, #0b00000001;@ Extract 5th bit
  183.     MOV R2, R1 ;@Store for later use in instruction finding
  184.     CMP R1, #0b00000001
  185.     BNE twoOperands
  186.     BEQ variableOperands
  187.  
  188. Atype:
  189.     AND R5, R0, #0b11000000 ;@testing
  190.     LSR R1, R0, #4 ;@ shift 4th and 5th bits
  191.     AND R1, #0b00000011;@ Extract 4th and 5th bit
  192.     MOV R2, R1 ;@Store for later use in instruction finding
  193.     CMP R1, #0b00000011
  194.     BEQ zeroOperands
  195.     B oneOperand
  196.  
  197. /*Btype:
  198.     AND R5, R0, #0b11000000
  199.     LSR R1, R0, #6
  200.     ANDS R1, #0b00000001
  201.     BEQ 1Bconstant
  202.     B 1Bindicator*/
  203.  
  204. twoOperands:
  205.     ;@ Retrieve each operand and store them into R1 and R0
  206.     B CInstructionIndicator
  207.  
  208. variableOperands:
  209.     ;@ Not sure what happens here yet
  210.     B CInstructionIndicator
  211.  
  212. zeroOperands:
  213.     AND R4, R0, #0b00100000;@testing
  214.     ADD R5, R4;@testing
  215.     B AInstructionIndicator
  216.  
  217. oneOperand:
  218.     AND R4, R0, #0b00110000
  219.     ADD R5, R4
  220.     CMP R1, #0b10
  221.     BEQ indicator1B
  222.     CMP R1, #0b01
  223.     BEQ constant1B
  224.     B constant2B
  225.  
  226. constant1B:
  227.     ;@ Retrieve Operand and store into R0
  228.     B AInstructionIndicator
  229.  
  230. constant2B:
  231.     ;@ Retrieve Operand and store into R0
  232.     B AInstructionIndicator
  233.  
  234. indicator1B:
  235.     ;@ Retrieve Operand and store into R0
  236.     B AInstructionIndicator
  237.  
  238. AInstructionIndicator:
  239.     AND R1, R0, #0b00001111
  240.     ADD R5, R1
  241.     CMP R2, #0b00000011 ;@R2 determines the number of operands
  242.     BEQ zero
  243.     B one
  244.  
  245. CInstructionIndicator:
  246.     AND R1, R0, #0b00011111
  247.     ADD R5, R1
  248.     CMP R1, #0b1
  249.     BEQ variable
  250.     B two
  251.  
  252. zero:
  253.     CMP R1, #0b00000010
  254.     BEQ PRINT
  255.     CMP R1, #0b00001000
  256.     BEQ RET_POPPED
  257.     CMP R1, #0b00001101
  258.     BEQ VERIFY
  259.     B crash
  260.  
  261. one:
  262.     CMP R1, #0b00000101
  263.     BEQ INC
  264.     CMP R1, #0b00000110
  265.     BEQ DEC
  266.     CMP R1, #0b00001111
  267.     BEQ CALL_1N
  268.     CMP R1, #0b00001011
  269.     BEQ RET
  270.     B crash
  271.  
  272. two:
  273.     CMP R1, #0b00010100
  274.     BEQ ADD
  275.  
  276.     CMP R1, #0b00010101
  277.     BEQ SUB
  278.  
  279.     CMP R1, #0b00010110
  280.     BEQ MUL
  281.  
  282.     CMP R1, #0b00010111
  283.     BEQ DIV
  284.  
  285.     CMP R1, #0b00011000
  286.     BEQ MOD
  287.  
  288.     CMP R1, #0b00000001
  289.     BEQ JE
  290.  
  291.     CMP R1, #0b00000010
  292.     BEQ JL
  293.  
  294.     CMP R1, #0b00000011
  295.     BEQ JG
  296.  
  297.     CMP R1, #0b00011001
  298.     BEQ CALL_2S
  299.  
  300.     CMP R1, #0b00011010
  301.     BEQ CALL_2N
  302.  
  303.     CMP R1, #0b00001010
  304.     BEQ TEST_ATTR
  305.  
  306.     CMP R1, #0b00001011
  307.     BEQ SET_ATTR
  308.  
  309.     CMP R1, #0b00001100
  310.     BEQ CLEAR_ATTR
  311.  
  312.     B crash
  313.  
  314.  
  315. variable:
  316. B crash
  317.  
  318. crash:
  319. ;@ Print the invalid intruction and its location in HEX
  320. ;@ Should probably loop back to execute or something
  321. B crash
  322.  
  323. ;@ 0 Operand instructions
  324.  
  325. PRINT:
  326. B PRINT
  327.  
  328. RET_POPPED:
  329. B RET_POPPED
  330.  
  331. VERIFY:
  332. B VERIFY
  333.  
  334. ;@ 1 Operand instructions
  335.  
  336. INC:
  337. B INC
  338.  
  339. DEC:
  340. B DEC
  341.  
  342. CALL_1N:
  343. B CALL_1N
  344.  
  345. RET:
  346. B RET
  347.  
  348. ;@ 2 Operand instructions
  349.  
  350. ADD:
  351.     B ADD
  352. SUB:
  353.     B SUB
  354. MUL:
  355.     B MUL
  356. DIV:
  357.     B DIV
  358. MOD:
  359.     B MOD
  360. JE:
  361.     B JE
  362. JL:
  363.     B JL
  364. JG:
  365.     B JG
  366. CALL_2S:
  367.     B CALL_2S
  368. CALL_2N:
  369.     B CALL_2N
  370. TEST_ATTR:
  371.     B TEST_ATTR
  372. SET_ATTR:
  373.     B SET_ATTR
  374. CLEAR_ATTR:
  375.     B CLEAR_ATTR
  376. ----------------------------------------------------------------------------------------------
  377. .global asm_main
  378. .align 4
  379. memory: .space 2000000
  380. .align 4
  381.  
  382. asm_main:
  383.     LDR R2, =0x000103F0 ;@ should be Zmem
  384.     LDR R3, =0b01001001 ;@ Opcode test
  385.     STR R3, [R2]
  386. checkSize:
  387. ;@ Could check size to see if it even is an OPCODE
  388. ;@ If it is check the type
  389. ;@ Else crash
  390. checkType:
  391.     LDRB R0, [R2]
  392.     LSR R1, R0, #6 ;@ shift 7th and 6th bits
  393.     MOV R4, R1
  394.     CMP R1, #0b11
  395.     BEQ Ctype
  396.     CMP R1, #0b10
  397.     BEQ Atype
  398.     B Btype
  399.  
  400. Ctype:
  401.     AND R5, R0, #0b11000000 ;@testing
  402.     LSR R1, R0, #5 ;@ shift 5th bit
  403.     AND R1, #0b00000001;@ Extract 5th bit
  404.     MOV R2, R1 ;@Store for later use in instruction finding
  405.     CMP R1, #0b00000001
  406.     BNE twoOperands
  407.     BEQ variableOperands
  408.  
  409. Atype:
  410.     AND R5, R0, #0b11000000 ;@testing
  411.     LSR R1, R0, #4 ;@ shift 4th and 5th bits
  412.     AND R1, #0b00000011;@ Extract 4th and 5th bit
  413.     MOV R2, R1 ;@Store for later use in instruction finding
  414.     CMP R1, #0b00000011
  415.     BEQ zeroOperands
  416.     B oneOperand
  417.  
  418. Btype:
  419.     AND R5, R0, #0b11000000
  420.     LSR R1, R0, #6 ;@ shift 6th bit
  421.     AND R1, #0b00000001;@ Extract 6th bit
  422.     MOV R2, R1 ;@Store for later use in instruction finding
  423.     CMP R1, #0b00000001
  424.     BEQ indicator1B;@ ------------------ NEEDS TO GO TO FIRST
  425.     B constant1B
  426.  
  427.  
  428. twoOperands:
  429.     ;@ Retrieve each operand and store them into R1 and R0
  430.     B CInstructionIndicator
  431.  
  432. variableOperands:
  433.     ;@ Not sure what happens here yet
  434.     B CInstructionIndicator
  435.  
  436. zeroOperands:
  437.     AND R4, R0, #0b00100000;@testing
  438.     ADD R5, R4;@testing
  439.     B AInstructionIndicator
  440.  
  441. oneOperand:
  442.     AND R4, R0, #0b00110000
  443.     ADD R5, R4
  444.     CMP R1, #0b10
  445.     BEQ indicator1B
  446.     CMP R1, #0b01
  447.     BEQ constant1B
  448.     B constant2B
  449.  
  450. constant1B:
  451.     ;@ Retrieve Operand and store into R0
  452.     CMP R4, #0b00000010
  453.     BEQ AInstructionIndicator
  454.     AND R1, R0, #0b00011111
  455.     B two
  456.  
  457. constant2B:
  458.     ;@ Retrieve Operand and store into R0
  459.     B AInstructionIndicator
  460.  
  461. indicator1B:
  462.     ;@ Retrieve Operand and store into R0
  463.     CMP R4, #0b00000010
  464.     BEQ AInstructionIndicator
  465.     AND R1, R0, #0b00011111
  466.     B two
  467.  
  468. AInstructionIndicator:
  469.     AND R1, R0, #0b00001111
  470.     ADD R5, R1
  471.     CMP R2, #0b00000011 ;@R2 determines the number of operands
  472.     BEQ zero
  473.     B one
  474.  
  475. CInstructionIndicator:
  476.     AND R1, R0, #0b00011111
  477.     ADD R5, R1
  478.     CMP R2, #0b1
  479.     BEQ variable
  480.     B two
  481.  
  482. zero:
  483.     CMP R1, #0b00000010
  484.     BEQ PRINT
  485.     CMP R1, #0b00001000
  486.     BEQ RET_POPPED
  487.     CMP R1, #0b00001101
  488.     BEQ VERIFY
  489.     B crash
  490.  
  491. one:
  492.     CMP R1, #0b00000101
  493.     BEQ INC
  494.     CMP R1, #0b00000110
  495.     BEQ DEC
  496.     CMP R1, #0b00001111
  497.     BEQ CALL_1N
  498.     CMP R1, #0b00001011
  499.     BEQ RET
  500.     B crash
  501.  
  502. two:
  503.     CMP R1, #0b00010100
  504.     BEQ ADD
  505.  
  506.     CMP R1, #0b00010101
  507.     BEQ SUB
  508.  
  509.     CMP R1, #0b00010110
  510.     BEQ MUL
  511.  
  512.     CMP R1, #0b00010111
  513.     BEQ DIV
  514.  
  515.     CMP R1, #0b00011000
  516.     BEQ MOD
  517.  
  518.     CMP R1, #0b00000001
  519.     BEQ JE
  520.  
  521.     CMP R1, #0b00000010
  522.     BEQ JL
  523.  
  524.     CMP R1, #0b00000011
  525.     BEQ JG
  526.  
  527.     CMP R1, #0b00011001
  528.     BEQ CALL_2S
  529.  
  530.     CMP R1, #0b00011010
  531.     BEQ CALL_2N
  532.  
  533.     CMP R1, #0b00001010
  534.     BEQ TEST_ATTR
  535.  
  536.     CMP R1, #0b00001011
  537.     BEQ SET_ATTR
  538.  
  539.     CMP R1, #0b00001100
  540.     BEQ CLEAR_ATTR
  541.  
  542.     B crash
  543.  
  544.  
  545. variable:
  546.     CMP R1, #0b00011000
  547.     BEQ NOT
  548.  
  549.     CMP R1, #0b00000101
  550.     BEQ PRINT_CHAR
  551.  
  552.     CMP R1, #0b00000110
  553.     BEQ PRINT_NUM
  554.  
  555.     CMP R1, #0b00001000
  556.     BEQ PUSH
  557.  
  558.     CMP R1, #0b00001001
  559.     BEQ PULL
  560.  
  561.     B crash
  562.  
  563. crash:
  564. ;@ Print the invalid intruction and its location in HEX
  565. ;@ Should probably loop back to execute or something
  566. B crash
  567.  
  568. ;@ 0 Operand Instructions
  569.  
  570. PRINT:
  571. B PRINT
  572.  
  573. RET_POPPED:
  574. B RET_POPPED
  575.  
  576. VERIFY:
  577. B VERIFY
  578.  
  579. ;@ 1 Operand Instructions
  580.  
  581. INC:
  582. B INC
  583.  
  584. DEC:
  585. B DEC
  586.  
  587. CALL_1N:
  588. B CALL_1N
  589.  
  590. RET:
  591. B RET
  592.  
  593. ;@ 2 Operand Instructions
  594.  
  595. ADD:
  596.     B ADD
  597. SUB:
  598.     B SUB
  599. MUL:
  600.     B MUL
  601. DIV:
  602.     B DIV
  603. MOD:
  604.     B MOD
  605. JE:
  606.     B JE
  607. JL:
  608.     B JL
  609. JG:
  610.     B JG
  611. CALL_2S:
  612.     B CALL_2S
  613. CALL_2N:
  614.     B CALL_2N
  615. TEST_ATTR:
  616.     B TEST_ATTR
  617. SET_ATTR:
  618.     B SET_ATTR
  619. CLEAR_ATTR:
  620.     B CLEAR_ATTR
  621.  
  622. ;@ Variable Operand Instructions
  623.  
  624. NOT:
  625. B NOT
  626.  
  627. PRINT_CHAR:
  628. B PRINT_CHAR
  629.  
  630. PRINT_NUM:
  631. B PRINT_NUM
  632.  
  633. PUSH:
  634. B PUSH
  635.  
  636. PULL:
  637. B PULL
  638. ---------------------------------------------------------------------------------------------
  639. .global asm_main
  640. .align 4
  641. memory: .space 2000000
  642. .align 4
  643.  
  644. asm_main:
  645.     LDR R2, =0x000103F0 ;@ should be Zmem
  646.     LDR R3, =0b01001001 ;@ Opcode test
  647.     STR R3, [R2]
  648. checkSize:
  649. ;@ Could check size to see if it even is an OPCODE
  650. ;@ If it is check the type
  651. ;@ Else crash
  652. checkType:
  653.     LDRB R0, [R2]
  654.     LSR R1, R0, #6 ;@ shift 7th and 6th bits
  655.     MOV R4, R1
  656.     CMP R1, #0b11
  657.     BEQ Ctype
  658.     CMP R1, #0b10
  659.     BEQ Atype
  660.     B Btype
  661.  
  662. Ctype:
  663.     AND R5, R0, #0b11000000 ;@testing
  664.     LSR R1, R0, #5 ;@ shift 5th bit
  665.     AND R1, #0b00000001;@ Extract 5th bit
  666.     MOV R2, R1 ;@Store for later use in instruction finding
  667.     CMP R1, #0b00000001
  668.     BNE twoOperands
  669.     BEQ variableOperands
  670.  
  671. Atype:
  672.     AND R5, R0, #0b11000000 ;@testing
  673.     LSR R1, R0, #4 ;@ shift 4th and 5th bits
  674.     AND R1, #0b00000011;@ Extract 4th and 5th bit
  675.     MOV R2, R1 ;@Store for later use in instruction finding
  676.     CMP R1, #0b00000011
  677.     BEQ zeroOperands
  678.     B oneOperand
  679.  
  680. Btype:
  681.     AND R5, R0, #0b11000000
  682.     LSR R1, R0, #6 ;@ shift 6th bit
  683.     AND R1, #0b00000001;@ Extract 6th bit
  684.     MOV R2, R1 ;@Store for later use in instruction finding
  685.     CMP R1, #0b00000001
  686.     BEQ Bindicator1B;@ ------------------ NEEDS TO GO TO FIRST
  687.     B Bconstant1B
  688.  
  689. Bindicator1B:
  690.     ;@store into r0
  691.     B Btype2
  692.    
  693. Bconstant1B:
  694.     ;@store into r0
  695.     B Btype2
  696.  
  697. Btype2:
  698.     ;@AND R5, R0, #0b11000000
  699.     LSR R1, R0, #5 ;@ shift 6th bit
  700.     AND R1, #0b00000001;@ Extract 6th bit
  701.     MOV R2, R1 ;@Store for later use in instruction finding
  702.     CMP R1, #0b00000001
  703.     BEQ B2indicator1B
  704.     B B2constant1B
  705.    
  706. B2indicator1B:
  707.     ;@store into R1
  708.     B two
  709.    
  710. B2constant1B:
  711.     ;@store into R1
  712.     B two  
  713.  
  714. twoOperands:
  715.     ;@ Retrieve each operand and store them into R1 and R0
  716.     B CInstructionIndicator
  717.  
  718. variableOperands:
  719.     ;@ Not sure what happens here yet      
  720.     B CInstructionIndicator
  721.  
  722. zeroOperands:
  723.     AND R4, R0, #0b00100000;@testing
  724.     ADD R5, R4;@testing
  725.     B AInstructionIndicator
  726.  
  727. oneOperand:
  728.     AND R4, R0, #0b00110000
  729.     ADD R5, R4
  730.     CMP R1, #0b10
  731.     BEQ indicator1B
  732.     CMP R1, #0b01
  733.     BEQ constant1B
  734.     B constant2B
  735.  
  736. constant1B:
  737.     ;@ Retrieve Operand and store into R0
  738.     ;@CMP R4, #0b00000010
  739.     B AInstructionIndicator
  740.     ;@AND R1, R0, #0b00011111
  741.     ;@B two
  742.  
  743. constant2B:
  744.     ;@ Retrieve Operand and store into R0
  745.     B AInstructionIndicator
  746.  
  747. indicator1B:
  748.     ;@ Retrieve Operand and store into R0
  749.     ;@ CMP R4, #0b00000010
  750.     B AInstructionIndicator
  751.     ;@ AND R1, R0, #0b00011111
  752.     ;@ B two
  753.  
  754. AInstructionIndicator:
  755.     AND R1, R0, #0b00001111
  756.     ADD R5, R1
  757.     CMP R2, #0b00000011 ;@R2 determines the number of operands
  758.     BEQ zero
  759.     B one
  760.  
  761. CInstructionIndicator:
  762.     AND R1, R0, #0b00011111
  763.     ADD R5, R1
  764.     CMP R2, #0b1
  765.     BEQ variable
  766.     B two
  767.  
  768. zero:
  769.     CMP R1, #0b00000010
  770.     BEQ PRINT
  771.     CMP R1, #0b00001000
  772.     BEQ RET_POPPED
  773.     CMP R1, #0b00001101
  774.     BEQ VERIFY
  775.     B crash
  776.  
  777. one:
  778.     CMP R1, #0b00000101
  779.     BEQ INC
  780.     CMP R1, #0b00000110
  781.     BEQ DEC
  782.     CMP R1, #0b00001111
  783.     BEQ CALL_1N
  784.     CMP R1, #0b00001011
  785.     BEQ RET
  786.     B crash
  787.  
  788. two:
  789.     CMP R1, #0b00010100
  790.     BEQ ADD
  791.  
  792.     CMP R1, #0b00010101
  793.     BEQ SUB
  794.  
  795.     CMP R1, #0b00010110
  796.     BEQ MUL
  797.  
  798.     CMP R1, #0b00010111
  799.     BEQ DIV
  800.  
  801.     CMP R1, #0b00011000
  802.     BEQ MOD
  803.  
  804.     CMP R1, #0b00000001
  805.     BEQ JE
  806.  
  807.     CMP R1, #0b00000010
  808.     BEQ JL
  809.  
  810.     CMP R1, #0b00000011
  811.     BEQ JG
  812.  
  813.     CMP R1, #0b00011001
  814.     BEQ CALL_2S
  815.  
  816.     CMP R1, #0b00011010
  817.     BEQ CALL_2N
  818.  
  819.     CMP R1, #0b00001010
  820.     BEQ TEST_ATTR
  821.  
  822.     CMP R1, #0b00001011
  823.     BEQ SET_ATTR
  824.  
  825.     CMP R1, #0b00001100
  826.     BEQ CLEAR_ATTR
  827.  
  828.     B crash
  829.  
  830.  
  831. variable:
  832.     CMP R1, #0b00011000
  833.     BEQ NOT
  834.  
  835.     CMP R1, #0b00000101
  836.     BEQ PRINT_CHAR
  837.  
  838.     CMP R1, #0b00000110
  839.     BEQ PRINT_NUM
  840.  
  841.     CMP R1, #0b00001000
  842.     BEQ PUSH
  843.  
  844.     CMP R1, #0b00001001
  845.     BEQ PULL
  846.  
  847.     B crash
  848.  
  849. crash:
  850. ;@ Print the invalid intruction and its location in HEX
  851. ;@ Should probably loop back to execute or something
  852. B crash
  853.  
  854. ;@ 0 Operand Instructions
  855.  
  856. PRINT:
  857. B PRINT
  858.  
  859. RET_POPPED:
  860. B RET_POPPED
  861.  
  862. VERIFY:
  863. B VERIFY
  864.  
  865. ;@ 1 Operand Instructions
  866.  
  867. INC:
  868.     B INC
  869.  
  870. DEC:
  871.     B DEC
  872.  
  873. CALL_1N:
  874.     B CALL_1N
  875.  
  876. RET:
  877.     B RET
  878.  
  879. ;@ 2 Operand Instructions
  880.  
  881. ADD:
  882.     B ADD
  883.    
  884. SUB:
  885.     B SUB
  886.    
  887. MUL:
  888.     B MUL
  889.    
  890. DIV:
  891.     B DIV
  892.    
  893. MOD:
  894.     B MOD
  895.    
  896. JE:
  897.     B JE
  898.    
  899. JL:
  900.     B JL
  901.    
  902. JG:
  903.     B JG
  904.    
  905. CALL_2S:
  906.     B CALL_2S
  907.    
  908. CALL_2N:
  909.     B CALL_2N
  910.    
  911. TEST_ATTR:
  912.     B TEST_ATTR
  913.    
  914. SET_ATTR:
  915.     B SET_ATTR
  916.    
  917. CLEAR_ATTR:
  918.     B CLEAR_ATTR
  919.  
  920. ;@ Variable Operand Instructions
  921.  
  922. NOT:
  923. B NOT
  924.  
  925. PRINT_CHAR:
  926. B PRINT_CHAR
  927.  
  928. PRINT_NUM:
  929. B PRINT_NUM
  930.  
  931. PUSH:
  932. B PUSH
  933.  
  934. PULL:
  935. B PULL
  936. --------------------------------------------------------------------------------------------------------------------------
  937.  
  938. ;@ WORKING ATYPE, BTYPE, CTYPE INSTRUCTION CHECK
  939.  
  940. .global asm_main
  941. .align 4
  942. memory: .space 2000000
  943. .align 4
  944.  
  945. asm_main:
  946.     LDR R2, =0x000103F0 ;@ should be Zmem
  947.     LDR R3, =0b01010100 ;@ Opcode test
  948.     STRB R3, [R2]
  949. checkSize:
  950. ;@ Could check size to see if it even is an OPCODE
  951. ;@ If it is check the type
  952. ;@ Else crash
  953. checkType:
  954.     LDRB R0, [R2]
  955.     LSR R1, R0, #6 ;@ shift 7th and 6th bits
  956.     MOV R4, R1
  957.     CMP R1, #0b11
  958.     BEQ Ctype
  959.     CMP R1, #0b10
  960.     BEQ Atype
  961.     B Btype
  962.  
  963. Ctype:
  964.     AND R5, R0, #0b11000000 ;@testing
  965.     LSR R1, R0, #5 ;@ shift 5th bit
  966.     AND R1, #0b00000001;@ Extract 5th bit
  967.     MOV R2, R1 ;@Store for later use in instruction finding
  968.     CMP R1, #0b00000001
  969.     BNE twoOperands
  970.     BEQ variableOperands
  971.  
  972. Atype:
  973.     AND R5, R0, #0b11000000 ;@testing
  974.     LSR R1, R0, #4 ;@ shift 4th and 5th bits
  975.     AND R1, #0b00000011;@ Extract 4th and 5th bit
  976.     MOV R2, R1 ;@Store for later use in instruction finding
  977.     CMP R1, #0b00000011
  978.     BEQ zeroOperands
  979.     B oneOperand
  980.  
  981. Btype:
  982.     AND R5, R0, #0b11000000
  983.     LSR R1, R0, #6 ;@ shift 6th bit
  984.     AND R1, #0b00000001;@ Extract 6th bit
  985.     MOV R2, R1 ;@Store for later use in instruction finding
  986.     CMP R1, #0b00000001
  987.     BEQ Bindicator1B;@ ------------------ NEEDS TO GO TO FIRST
  988.     B Bconstant1B
  989.  
  990. Bindicator1B:
  991.     ;@store into r0
  992.     B Btype2
  993.  
  994. Bconstant1B:
  995.     ;@store into r0
  996.     B Btype2
  997.  
  998. Btype2:
  999.     ;@AND R5, R0, #0b11000000
  1000.     LSR R1, R0, #5 ;@ shift 6th bit
  1001.     AND R1, #0b00000001;@ Extract 6th bit
  1002.     MOV R2, R1 ;@Store for later use in instruction finding
  1003.     CMP R1, #0b00000001
  1004.     BEQ B2indicator1B
  1005.     B B2constant1B
  1006.  
  1007. B2indicator1B:
  1008.     ;@store into R1
  1009.     AND R1, R0, #0b00011111
  1010.     ADD R5, R1
  1011.     B two
  1012.  
  1013. B2constant1B:
  1014.     ;@store into R1
  1015.     AND R1, R0, #0b00011111
  1016.     ADD R5, R1
  1017.     B two
  1018.  
  1019. twoOperands:
  1020.     ;@ Retrieve each operand and store them into R1 and R0
  1021.     B CInstructionIndicator
  1022.  
  1023. variableOperands:
  1024.     ;@ Not sure what happens here yet
  1025.     B CInstructionIndicator
  1026.  
  1027. zeroOperands:
  1028.     AND R4, R0, #0b00100000;@testing
  1029.     ADD R5, R4;@testing
  1030.     B AInstructionIndicator
  1031.  
  1032. oneOperand:
  1033.     AND R4, R0, #0b00110000
  1034.     ADD R5, R4
  1035.     CMP R1, #0b10
  1036.     BEQ Aindicator1B
  1037.     CMP R1, #0b01
  1038.     BEQ Aconstant1B
  1039.     B Aconstant2B
  1040.  
  1041. Aconstant1B:
  1042.     ;@ Retrieve Operand and store into R0
  1043.     ;@CMP R4, #0b00000010
  1044.     B AInstructionIndicator
  1045.     ;@AND R1, R0, #0b00011111
  1046.     ;@B two
  1047.  
  1048. Aconstant2B:
  1049.     ;@ Retrieve Operand and store into R0
  1050.     B AInstructionIndicator
  1051.  
  1052. Aindicator1B:
  1053.     ;@ Retrieve Operand and store into R0
  1054.     ;@ CMP R4, #0b00000010
  1055.     B AInstructionIndicator
  1056.     ;@ AND R1, R0, #0b00011111
  1057.     ;@ B two
  1058.  
  1059. AInstructionIndicator:
  1060.     AND R1, R0, #0b00001111
  1061.     ADD R5, R1
  1062.     CMP R2, #0b00000011 ;@R2 determines the number of operands
  1063.     BEQ zero
  1064.     B one
  1065.  
  1066. CInstructionIndicator:
  1067.     AND R1, R0, #0b00011111
  1068.     ADD R5, R1
  1069.     CMP R2, #0b1
  1070.     BEQ variable
  1071.     B two
  1072.  
  1073. zero:
  1074.     CMP R1, #0b00000010
  1075.     BEQ PRINT
  1076.     CMP R1, #0b00001000
  1077.     BEQ RET_POPPED
  1078.     CMP R1, #0b00001101
  1079.     BEQ VERIFY
  1080.     B crash
  1081.  
  1082. one:
  1083.     CMP R1, #0b00000101
  1084.     BEQ INC
  1085.     CMP R1, #0b00000110
  1086.     BEQ DEC
  1087.     CMP R1, #0b00001111
  1088.     BEQ CALL_1N
  1089.     CMP R1, #0b00001011
  1090.     BEQ RET
  1091.     B crash
  1092.  
  1093. two:
  1094.     CMP R1, #0b00010100
  1095.     BEQ ADD
  1096.  
  1097.     CMP R1, #0b00010101
  1098.     BEQ SUB
  1099.  
  1100.     CMP R1, #0b00010110
  1101.     BEQ MUL
  1102.  
  1103.     CMP R1, #0b00010111
  1104.     BEQ DIV
  1105.  
  1106.     CMP R1, #0b00011000
  1107.     BEQ MOD
  1108.  
  1109.     CMP R1, #0b00000001
  1110.     BEQ JE
  1111.  
  1112.     CMP R1, #0b00000010
  1113.     BEQ JL
  1114.  
  1115.     CMP R1, #0b00000011
  1116.     BEQ JG
  1117.  
  1118.     CMP R1, #0b00011001
  1119.     BEQ CALL_2S
  1120.  
  1121.     CMP R1, #0b00011010
  1122.     BEQ CALL_2N
  1123.  
  1124.     CMP R1, #0b00001010
  1125.     BEQ TEST_ATTR
  1126.  
  1127.     CMP R1, #0b00001011
  1128.     BEQ SET_ATTR
  1129.  
  1130.     CMP R1, #0b00001100
  1131.     BEQ CLEAR_ATTR
  1132.  
  1133.     B crash
  1134.  
  1135.  
  1136. variable:
  1137.     CMP R1, #0b00011000
  1138.     BEQ NOT
  1139.  
  1140.     CMP R1, #0b00000101
  1141.     BEQ PRINT_CHAR
  1142.  
  1143.     CMP R1, #0b00000110
  1144.     BEQ PRINT_NUM
  1145.  
  1146.     CMP R1, #0b00001000
  1147.     BEQ PUSH
  1148.  
  1149.     CMP R1, #0b00001001
  1150.     BEQ PULL
  1151.  
  1152.     B crash
  1153.  
  1154. crash:
  1155. ;@ Print the invalid intruction and its location in HEX
  1156. ;@ Should probably loop back to execute or something
  1157. B crash
  1158.  
  1159. ;@ 0 Operand Instructions
  1160.  
  1161. PRINT:
  1162. B PRINT
  1163.  
  1164. RET_POPPED:
  1165. B RET_POPPED
  1166.  
  1167. VERIFY:
  1168. B VERIFY
  1169.  
  1170. ;@ 1 Operand Instructions
  1171.  
  1172. INC:
  1173.     B INC
  1174.  
  1175. DEC:
  1176.     B DEC
  1177.  
  1178. CALL_1N:
  1179.     B CALL_1N
  1180.  
  1181. RET:
  1182.     B RET
  1183.  
  1184. ;@ 2 Operand Instructions
  1185.  
  1186. ADD:
  1187.     B ADD
  1188.  
  1189. SUB:
  1190.     B SUB
  1191.  
  1192. MUL:
  1193.     B MUL
  1194.  
  1195. DIV:
  1196.     B DIV
  1197.  
  1198. MOD:
  1199.     B MOD
  1200.  
  1201. JE:
  1202.     B JE
  1203.  
  1204. JL:
  1205.     B JL
  1206.  
  1207. JG:
  1208.     B JG
  1209.  
  1210. CALL_2S:
  1211.     B CALL_2S
  1212.  
  1213. CALL_2N:
  1214.     B CALL_2N
  1215.  
  1216. TEST_ATTR:
  1217.     B TEST_ATTR
  1218.  
  1219. SET_ATTR:
  1220.     B SET_ATTR
  1221.  
  1222. CLEAR_ATTR:
  1223.     B CLEAR_ATTR
  1224.  
  1225. ;@ Variable Operand Instructions
  1226.  
  1227. NOT:
  1228. B NOT
  1229.  
  1230. PRINT_CHAR:
  1231. B PRINT_CHAR
  1232.  
  1233. PRINT_NUM:
  1234. B PRINT_NUM
  1235.  
  1236. PUSH:
  1237. B PUSH
  1238.  
  1239. PULL:
  1240. B PULL
  1241. -------------------------------------------------------------------------------------------------------------
  1242. .global asm_main
  1243. .align 4
  1244. Zmemory: .space 2000000
  1245. .align 4
  1246.  
  1247. asm_main:
  1248.     LDR R7, =Zmemory ;@ should be Zmem
  1249.     LDR R3, =0b01010100 ;@ Opcode test
  1250.     STRB R3, [R7]
  1251. checkSize:
  1252. ;@ Could check size to see if it even is an OPCODE
  1253. ;@ If it is check the type
  1254. ;@ Else crash
  1255. checkType:
  1256.     LDRB R8, [R2]
  1257.     LSR R9, R8, #6 ;@ shift 7th and 6th bits
  1258.     MOV R4, R1
  1259.     CMP R9, #0b11
  1260.     BEQ Ctype
  1261.     CMP R9, #0b10
  1262.     BEQ Atype
  1263.     B Btype
  1264.  
  1265. Ctype:
  1266.     ;@AND R5, R0, #0b11000000 ;@testing
  1267.     LSR R9, R8, #5 ;@ shift 5th bit
  1268.     AND R9, #0b00000001;@ Extract 5th bit
  1269.     MOV R10, R9 ;@Store for later use in instruction finding
  1270.     CMP R9, #0b00000001
  1271.     BNE twoOperands
  1272.     BEQ variableOperands
  1273.  
  1274. Atype:
  1275.     ;@AND R5, R0, #0b11000000 ;@testing
  1276.     LSR R9, R8, #4 ;@ shift 4th and 5th bits
  1277.     AND R9, #0b00000011;@ Extract 4th and 5th bit
  1278.     MOV R10, R9 ;@Store for later use in instruction finding
  1279.     CMP R9, #0b00000011
  1280.     BEQ zeroOperands
  1281.     B oneOperand
  1282.  
  1283. Btype:
  1284.     ;@AND R5, R0, #0b11000000
  1285.     LSR R9, R8, #6 ;@ shift 6th bit
  1286.     AND R9, #0b00000001;@ Extract 6th bit
  1287.     MOV R10, R9 ;@Store for later use in instruction finding
  1288.     CMP R9, #0b00000001
  1289.     BEQ Bindicator1B;@ ------------------ NEEDS TO GO TO FIRST
  1290.     B Bconstant1B
  1291.  
  1292. Bindicator1B:
  1293.     ;@store into r0
  1294.    
  1295.     B Btype2
  1296.  
  1297. Bconstant1B:
  1298.     ;@store into r0
  1299.     B Btype2
  1300.  
  1301. Btype2:
  1302.     ;@AND R5, R0, #0b11000000
  1303.     LSR R9, R8, #5 ;@ shift 6th bit
  1304.     AND R9, #0b00000001;@ Extract 6th bit
  1305.     MOV R10, R9 ;@Store for later use in instruction finding
  1306.     CMP R9, #0b00000001
  1307.     BEQ B2indicator1B
  1308.     B B2constant1B
  1309.  
  1310. B2indicator1B:
  1311.     ;@store into R1
  1312.     AND R9, R8, #0b00011111
  1313.     ADD R5, R9
  1314.     B two
  1315.  
  1316. B2constant1B:
  1317.     ;@store into R1
  1318.     AND R9, R8, #0b00011111
  1319.     ADD R5, R9
  1320.     B two
  1321.  
  1322.  
  1323. twoOperands:
  1324.     ;@ Retrieve each operand and store them into R1 and R0
  1325.     LDRB R11, []
  1326.     B CInstructionIndicator
  1327.  
  1328. variableOperands:
  1329.     ;@ Not sure what happens here yet
  1330.     B CInstructionIndicator
  1331.  
  1332. zeroOperands:
  1333.     AND R4, R0, #0b00100000;@testing
  1334.     ADD R5, R4;@testing
  1335.     B AInstructionIndicator
  1336.  
  1337. oneOperand:
  1338.     AND R4, R0, #0b00110000
  1339.     ADD R5, R4
  1340.     CMP R9, #0b10
  1341.     BEQ Aindicator1B
  1342.     CMP R9, #0b01
  1343.     BEQ Aconstant1B
  1344.     B Aconstant2B
  1345.  
  1346. Aconstant1B:
  1347.     ;@ Retrieve Operand and store into R0
  1348.     ;@CMP R4, #0b00000010
  1349.    
  1350.     B AInstructionIndicator
  1351.     ;@AND R1, R0, #0b00011111
  1352.     ;@B two
  1353.  
  1354. Aconstant2B:
  1355.     ;@ Retrieve Operand and store into R0
  1356.     B AInstructionIndicator
  1357.  
  1358. Aindicator1B:
  1359.     ;@ Retrieve Operand and store into R0
  1360.     ;@ CMP R4, #0b00000010
  1361.     B AInstructionIndicator
  1362.     ;@ AND R1, R0, #0b00011111
  1363.     ;@ B two
  1364.  
  1365. AInstructionIndicator:
  1366.     AND R9, R0, #0b00001111
  1367.     ADD R5, R9
  1368.     CMP R10, #0b00000011 ;@R2 determines the number of operands
  1369.     BEQ zero
  1370.     B one
  1371.  
  1372. CInstructionIndicator:
  1373.     AND R9, R0, #0b00011111
  1374.     ADD R5, R9
  1375.     CMP R10, #0b1
  1376.     BEQ variable
  1377.     B two
  1378.  
  1379. zero:
  1380.     CMP R9, #0b00000010
  1381.     BEQ PRINT
  1382.    
  1383.     CMP R9, #0b00001000
  1384.     BEQ RET_POPPED
  1385.    
  1386.     CMP R9, #0b00001101
  1387.     BEQ VERIFY
  1388.    
  1389.     B crash
  1390.  
  1391. one:
  1392.     CMP R9, #0b00000101
  1393.     BEQ INC
  1394.    
  1395.     CMP R9, #0b00000110
  1396.     BEQ DEC
  1397.    
  1398.     CMP R9, #0b00001111
  1399.     BEQ CALL_1N
  1400.    
  1401.     CMP R9, #0b00001011
  1402.     BEQ RET
  1403.    
  1404.     B crash
  1405.  
  1406. two:
  1407.     CMP R9, #0b00010100
  1408.     BEQ ADD
  1409.  
  1410.     CMP R9, #0b00010101
  1411.     BEQ SUB
  1412.  
  1413.     CMP R9, #0b00010110
  1414.     BEQ MUL
  1415.  
  1416.     CMP R9, #0b00010111
  1417.     BEQ DIV
  1418.  
  1419.     CMP R9, #0b00011000
  1420.     BEQ MOD
  1421.  
  1422.     CMP R9, #0b00000001
  1423.     BEQ JE
  1424.  
  1425.     CMP R9, #0b00000010
  1426.     BEQ JL
  1427.  
  1428.     CMP R9, #0b00000011
  1429.     BEQ JG
  1430.  
  1431.     CMP R9, #0b00011001
  1432.     BEQ CALL_2S
  1433.  
  1434.     CMP R9, #0b00011010
  1435.     BEQ CALL_2N
  1436.  
  1437.     CMP R9, #0b00001010
  1438.     BEQ TEST_ATTR
  1439.  
  1440.     CMP R9, #0b00001011
  1441.     BEQ SET_ATTR
  1442.  
  1443.     CMP R9, #0b00001100
  1444.     BEQ CLEAR_ATTR
  1445.  
  1446.     B crash
  1447.  
  1448.  
  1449. variable:
  1450.     CMP R9, #0b00011000
  1451.     BEQ NOT
  1452.  
  1453.     CMP R9, #0b00000101
  1454.     BEQ PRINT_CHAR
  1455.  
  1456.     CMP R9, #0b00000110
  1457.     BEQ PRINT_NUM
  1458.  
  1459.     CMP R9, #0b00001000
  1460.     BEQ PUSH
  1461.  
  1462.     CMP R9, #0b00001001
  1463.     BEQ PULL
  1464.  
  1465.     B crash
  1466.  
  1467. crash:
  1468. ;@ Print the invalid intruction and its location in HEX
  1469. ;@ Should probably loop back to execute or something
  1470.  
  1471. B crash
  1472.  
  1473. ;@ 0 Operand Instructions
  1474.  
  1475. PRINT:
  1476. B PRINT
  1477.  
  1478. RET_POPPED:
  1479. B RET_POPPED
  1480.  
  1481. VERIFY:
  1482. B VERIFY
  1483.  
  1484. ;@ 1 Operand Instructions
  1485.  
  1486. INC:
  1487.     B INC
  1488.  
  1489. DEC:
  1490.     B DEC
  1491.  
  1492. CALL_1N:
  1493.     B CALL_1N
  1494.  
  1495. RET:
  1496.     B RET
  1497.  
  1498. ;@ 2 Operand Instructions
  1499.  
  1500. ADD:
  1501.     B ADD
  1502.  
  1503. SUB:
  1504.     B SUB
  1505.  
  1506. MUL:
  1507.     B MUL
  1508.  
  1509. DIV:
  1510.     B DIV
  1511.  
  1512. MOD:
  1513.     B MOD
  1514.  
  1515. JE:
  1516.     B JE
  1517.  
  1518. JL:
  1519.     B JL
  1520.  
  1521. JG:
  1522.     B JG
  1523.  
  1524. CALL_2S:
  1525.     B CALL_2S
  1526.  
  1527. CALL_2N:
  1528.     B CALL_2N
  1529.  
  1530. TEST_ATTR:
  1531.     B TEST_ATTR
  1532.  
  1533. SET_ATTR:
  1534.     B SET_ATTR
  1535.  
  1536. CLEAR_ATTR:
  1537.     B CLEAR_ATTR
  1538.  
  1539. ;@ Variable Operand Instructions
  1540.  
  1541. NOT:
  1542. B NOT
  1543.  
  1544. PRINT_CHAR:
  1545. B PRINT_CHAR
  1546.  
  1547. PRINT_NUM:
  1548. B PRINT_NUM
  1549.  
  1550. PUSH:
  1551. B PUSH
  1552.  
  1553. PULL:
  1554. B PULL
  1555. .global asm_main
  1556. .align 4
  1557. Zmemory: .space 2000000
  1558. .align 4
  1559.  
  1560. asm_main:
  1561.     MOV R12, #0 ;@ONLY USED in div and mod
  1562.     MOV R4, #0 ;@ Zpc
  1563.     LDR R7, =Zmemory ;@ should be Zmem
  1564.     LDRB R3, =0b00011000 ;@ Opcode test
  1565.     STRB R3, [R7]
  1566.     LDRB R3, =0b00001000 ;@ Operand1 test
  1567.     STRB R3, [R7,#1]
  1568.     LDRB R3, =0b00000011 ;@ Operand2 test
  1569.     STRB R3, [R7,#2]
  1570.     ;@ LDRB R3, =0b00001000 ;@ Destination test
  1571.     ;@ STRB R3, [R7,#3]
  1572. checkSize:
  1573. ;@ Could check size to see if it even is an OPCODE
  1574. ;@ If it is check the type
  1575. ;@ Else crash
  1576. checkType:
  1577.     LDRB R8, [R7]
  1578.     ADD R4, #1
  1579.     LSR R9, R8, #6 ;@ shift 7th and 6th bits
  1580.     ;@MOV R4, R9
  1581.     CMP R9, #0b11
  1582.     BEQ Ctype
  1583.     CMP R9, #0b10
  1584.     BEQ Atype
  1585.     B Btype
  1586.  
  1587. Ctype:
  1588.     ;@AND R5, R0, #0b11000000 ;@testing
  1589.     LSR R9, R8, #5 ;@ shift 5th bit
  1590.     AND R9, #0b00000001;@ Extract 5th bit
  1591.     MOV R10, R9 ;@Store for later use in instruction finding
  1592.     CMP R9, #0b00000001
  1593.     BNE twoOperands
  1594.     BEQ variableOperands
  1595.  
  1596. Atype:
  1597.     ;@AND R5, R0, #0b11000000 ;@testing
  1598.     LSR R9, R8, #4 ;@ shift 4th and 5th bits
  1599.     AND R9, #0b00000011;@ Extract 4th and 5th bit
  1600.     MOV R10, R9 ;@Store for later use in instruction finding
  1601.     CMP R9, #0b00000011
  1602.     BEQ zeroOperands
  1603.     B oneOperand
  1604.  
  1605. Btype:
  1606.     ;@AND R5, R0, #0b11000000
  1607.     LSR R9, R8, #6 ;@ shift 6th bit
  1608.     AND R9, #0b00000001;@ Extract 6th bit
  1609.     MOV R10, R9 ;@Store for later use in instruction finding
  1610.     CMP R9, #0b00000001
  1611.     BEQ Bindicator1B;@ ------------------ NEEDS TO GO TO FIRST
  1612.     B Bconstant1B
  1613.  
  1614. Bindicator1B:
  1615.     ;@store into r0
  1616.  
  1617.     B Btype2
  1618.  
  1619. Bconstant1B:
  1620.     ;@store into r0
  1621.     LDRB R0, [R7,R4]
  1622.     ADD R4, #1
  1623.     B Btype2
  1624.  
  1625. Btype2:
  1626.     ;@AND R5, R0, #0b11000000
  1627.     LSR R9, R8, #5 ;@ shift 6th bit
  1628.     AND R9, #0b00000001;@ Extract 6th bit
  1629.     MOV R10, R9 ;@Store for later use in instruction finding
  1630.     CMP R9, #0b00000001
  1631.     BEQ B2indicator1B
  1632.     B B2constant1B
  1633.  
  1634. B2indicator1B:
  1635.     ;@store into R1
  1636.  
  1637.     AND R9, R8, #0b00011111
  1638.     B two
  1639.  
  1640. B2constant1B:
  1641.     ;@store into R1
  1642.     LDRB R1, [R7, R4]
  1643.     ADD R4, #1
  1644.     AND R9, R8, #0b00011111
  1645.     B two
  1646.  
  1647.  
  1648. twoOperands:
  1649.     ;@ Retrieve each operand and store them into R1 and R0
  1650.     LDRB R0, [R7,R4]
  1651.     ADD R4, #1
  1652.     LDRB R1, [R7, R4]
  1653.     ADD R4, #1
  1654.     B CInstructionIndicator
  1655.  
  1656. variableOperands:
  1657.     ;@ Not sure what happens here yet
  1658.     B CInstructionIndicator
  1659.  
  1660. zeroOperands:
  1661.     AND R4, R0, #0b00100000;@testing
  1662.     ADD R5, R4;@testing
  1663.     B AInstructionIndicator
  1664.  
  1665. oneOperand:
  1666.     AND R4, R0, #0b00110000
  1667.     ADD R5, R4
  1668.     CMP R9, #0b10
  1669.     BEQ Aindicator1B
  1670.     CMP R9, #0b01
  1671.     BEQ Aconstant1B
  1672.     B Aconstant2B
  1673.  
  1674. Aconstant1B:
  1675.     ;@ Retrieve Operand and store into R0
  1676.     ;@CMP R4, #0b00000010
  1677.  
  1678.     B AInstructionIndicator
  1679.     ;@AND R1, R0, #0b00011111
  1680.     ;@B two
  1681.  
  1682. Aconstant2B:
  1683.     ;@ Retrieve Operand and store into R0
  1684.     LDRH R0, [R7,R4]
  1685.     ADD R4, #1
  1686.     B AInstructionIndicator
  1687.  
  1688. Aindicator1B:
  1689.     ;@ Retrieve Operand and store into R0
  1690.     ;@ CMP R4, #0b00000010
  1691.     B AInstructionIndicator
  1692.     ;@ AND R1, R0, #0b00011111
  1693.     ;@ B two
  1694.  
  1695. AInstructionIndicator:
  1696.     AND R9, R0, #0b00001111
  1697.     ADD R5, R9
  1698.     CMP R10, #0b00000011 ;@R2 determines the number of operands
  1699.     BEQ zero
  1700.     B one
  1701.  
  1702. CInstructionIndicator:
  1703.     AND R9, R0, #0b00011111
  1704.     ADD R5, R9
  1705.     CMP R10, #0b1
  1706.     BEQ variable
  1707.     B two
  1708.  
  1709. zero:
  1710.     CMP R9, #0b00000010
  1711.     BEQ PRINT
  1712.  
  1713.     CMP R9, #0b00001000
  1714.     BEQ RET_POPPED
  1715.  
  1716.     CMP R9, #0b00001101
  1717.     BEQ VERIFY
  1718.  
  1719.     B crash
  1720.  
  1721. one:
  1722.     CMP R9, #0b00000101
  1723.     BEQ INC
  1724.  
  1725.     CMP R9, #0b00000110
  1726.     BEQ DEC
  1727.  
  1728.     CMP R9, #0b00001111
  1729.     BEQ CALL_1N
  1730.  
  1731.     CMP R9, #0b00001011
  1732.     BEQ RET
  1733.  
  1734.     B crash
  1735.  
  1736. two:
  1737.     CMP R9, #0b00010100
  1738.     BEQ ADD
  1739.  
  1740.     CMP R9, #0b00010101
  1741.     BEQ SUB
  1742.  
  1743.     CMP R9, #0b00010110
  1744.     BEQ MUL
  1745.  
  1746.     CMP R9, #0b00010111
  1747.     BEQ DIV
  1748.  
  1749.     CMP R9, #0b00011000
  1750.     BEQ MOD
  1751.  
  1752.     CMP R9, #0b00000001
  1753.     BEQ JE
  1754.  
  1755.     CMP R9, #0b00000010
  1756.     BEQ JL
  1757.  
  1758.     CMP R9, #0b00000011
  1759.     BEQ JG
  1760.  
  1761.     CMP R9, #0b00011001
  1762.     BEQ CALL_2S
  1763.  
  1764.     CMP R9, #0b00011010
  1765.     BEQ CALL_2N
  1766.  
  1767.     CMP R9, #0b00001010
  1768.     BEQ TEST_ATTR
  1769.  
  1770.     CMP R9, #0b00001011
  1771.     BEQ SET_ATTR
  1772.  
  1773.     CMP R9, #0b00001100
  1774.     BEQ CLEAR_ATTR
  1775.  
  1776.     B crash
  1777.  
  1778.  
  1779. variable:
  1780.     CMP R9, #0b00011000
  1781.     BEQ NOT
  1782.  
  1783.     CMP R9, #0b00000101
  1784.     BEQ PRINT_CHAR
  1785.  
  1786.     CMP R9, #0b00000110
  1787.     BEQ PRINT_NUM
  1788.  
  1789.     CMP R9, #0b00001000
  1790.     BEQ PUSH
  1791.  
  1792.     CMP R9, #0b00001001
  1793.     BEQ PULL
  1794.  
  1795.     B crash
  1796.  
  1797. crash:
  1798. ;@ Print the invalid intruction and its location in HEX
  1799. ;@ Should probably loop back to execute or something
  1800.  
  1801. B crash
  1802.  
  1803. ;@ 0 Operand Instructions
  1804.  
  1805. PRINT:
  1806. B PRINT
  1807.  
  1808. RET_POPPED:
  1809. B RET_POPPED
  1810.  
  1811. VERIFY:
  1812. B VERIFY
  1813.  
  1814. ;@ 1 Operand Instructions
  1815.  
  1816. INC:
  1817.     B INC
  1818.  
  1819. DEC:
  1820.     B DEC
  1821.  
  1822. CALL_1N:
  1823.     B CALL_1N
  1824.  
  1825. RET:
  1826.     B RET
  1827.  
  1828. ;@ 2 Operand Instructions
  1829.  
  1830. ADD:
  1831.     ADD R11, R0, R1 ;@R11 is currently the destination but this most likely will have to be stored in some locaton in Zmemory
  1832.     B crash;@ should CHANGE, needs to reloop
  1833.  
  1834. SUB:
  1835.     SUB R11, R0, R1 ;@R11 is currently the destination but this most likely will have to be stored in some locaton in Zmemory
  1836.     B crash ;@ should CHANGE, needs to reloop
  1837.  
  1838. MUL:
  1839.     MUL R11, R0, R1 ;@R11 is currently the destination but this most likely will have to be stored in some locaton in Zmemory
  1840.     B crash ;@ should CHANGE, needs to reloop
  1841.  
  1842. DIV:
  1843.     SUBS R0, R1
  1844.     ADDGE R12, #1
  1845.     BPL DIV
  1846.     MOV R11, R12
  1847.     B crash
  1848.  
  1849. MOD:
  1850.     SUBS R0, R1
  1851.     BPL MOD
  1852.     ADD R11, R0, R1
  1853.     B crash
  1854.  
  1855. JE:
  1856.     B JE
  1857.  
  1858. JL:
  1859.     B JL
  1860.  
  1861. JG:
  1862.     B JG
  1863.  
  1864. CALL_2S:
  1865.     B CALL_2S
  1866.  
  1867. CALL_2N:
  1868.     B CALL_2N
  1869.  
  1870. TEST_ATTR:
  1871.     B TEST_ATTR
  1872.  
  1873. SET_ATTR:
  1874.     B SET_ATTR
  1875.  
  1876. CLEAR_ATTR:
  1877.     B CLEAR_ATTR
  1878.  
  1879. ;@ Variable Operand Instructions
  1880.  
  1881. NOT:
  1882. B NOT
  1883.  
  1884. PRINT_CHAR:
  1885. B PRINT_CHAR
  1886.  
  1887. PRINT_NUM:
  1888. B PRINT_NUM
  1889.  
  1890. PUSH:
  1891. B PUSH
  1892.  
  1893. PULL:
  1894. B PULL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement