Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.35 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <errno.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9.  
  10.  
  11.  
  12. /*These variables are associated with the implementation of the VM*/
  13. int fp ;
  14. int i ;
  15. int j, k ;
  16. char input_line [7] ;
  17.  
  18. /*These are variables representing the VM itself*/
  19.  
  20. char IR[6] ;
  21. int PC = 0 ;
  22.  
  23. int P[4]; //these are the pointer registers
  24.  
  25.  
  26. int R[4] ; //GP regs
  27.  
  28. int ACC ;
  29. int PSW[2] ;
  30. char memory [100][6] ; //this is the program memory for first program
  31. short int opcode ; //nice to know what we are doing
  32. int program_line = 0 ;
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /* Provide implementation of the helper functions. You are free to provide as
  40. many additional helper functions as desired.
  41. */
  42.  
  43.  
  44. //This function returns the integer value of operand 1
  45. //when this operand is an immediate two-byte integer.
  46.  
  47.  
  48.  
  49. int ParseOp1 (char *IR) {
  50.  
  51. int parseVal;
  52. int val1 = (int)((IR[2]) - 48);
  53. int val2 = (int)((IR[3]) - 48);
  54. parseVal = (10 * val1) + val2;
  55. return parseVal;
  56. }
  57.  
  58.  
  59.  
  60. // returns the integer value of operand 2 when this operand is a two-byte integer.
  61. int ParseOp2 (char *IR) {
  62.  
  63. int parseVal;
  64. int val1 = (int)((IR[4]) - 48);
  65. int val2 = (int)((IR[5]) - 48);
  66. parseVal = (10 * val1) + val2;
  67. return parseVal;
  68. }
  69.  
  70. //returns the integer value of operands 1 and 2 combined to form a 4-byte integer.
  71. int ParseOP1andOP2Imm(char *IR)
  72. {
  73. int parseVal;
  74. parseVal = ParseOp1(IR) * 100;
  75. parseVal += ParseOp2(IR);
  76. return parseVal;
  77. }
  78.  
  79. // returns the register number of the register used as operand 1 of an instruction.
  80. // Can be either Pointer or General-Purpose register.
  81. int ParseOp1Reg (char *IR)
  82. {
  83. int val = (int)((IR[3]) - 48);
  84. return val;
  85. }
  86.  
  87. // returns the register number of a register used as operand 2 of an instruction.
  88. // Can be either a Pointer or General-Purpose register.
  89. int ParseOp2Reg (char *IR)
  90. {
  91. int val = (int)((IR[5]) - 48);
  92. return val;
  93. }
  94.  
  95. // returns the data stored at memory location Memory_Location
  96. int FetchData(int Memory_Location)
  97. {
  98. int parseVal;
  99. parseVal = (memory[Memory_Location][2] - 48) * 1000;
  100. parseVal += (memory[Memory_Location][3] - 48) * 100;
  101. parseVal += (memory[Memory_Location][4] - 48) * 10;
  102. parseVal += (memory[Memory_Location][5] - 48);
  103. return parseVal;
  104. }
  105.  
  106.  
  107. //Prints out the contents of the IR on the same line.
  108. void PrintIR(char *IR)
  109. {
  110. printf("IR:");
  111. for (int i = 0; i < 6; ++i)
  112. {
  113. printf("%c",IR[i]);
  114. }
  115. }
  116.  
  117. void printMEM(int upto){
  118. for(int i=0; i<upto; i++){
  119. printf("%c %c %c %c %c %c \n", memory[i][0],memory[i][1],
  120. memory[i][2],memory[i][3],
  121. memory[i][4],memory[i][5]);
  122. }
  123.  
  124. }
  125.  
  126.  
  127. //prints out the contents of memory from row 0 to row upto.
  128. //This should print out all instructions and data stored in memory.
  129.  
  130.  
  131. //Now its time for the instruction execution functions.
  132. // Here is the first.
  133.  
  134. int OP0(char *IR)
  135. { int PREG, VAL ;
  136. printf("Opcode = 00. Load Pointer Immediate\n");
  137. PrintIR(IR) ;
  138.  
  139. PREG = ParseOp1Reg(IR) ;
  140. VAL = ParseOp2 (IR) ;
  141. P[PREG] = VAL;
  142. printf("%d has been loaded into P%d \n", PREG, VAL);
  143. return 1;
  144. }
  145.  
  146. int OP1(char *IR)
  147. { int PREG, VAL ;
  148. printf("Opcode = 01. Add to Pointer Immediate\n") ;
  149. PrintIR(IR) ;
  150.  
  151. PREG = ParseOp1Reg(IR) ;
  152. VAL = ParseOp2 (IR) ;
  153. P[PREG] += VAL;
  154. printf("%d has been added to P%d \n", PREG, VAL);
  155. return 1;
  156. }
  157.  
  158. int OP2(char *IR)
  159. { int PREG, VAL ;
  160. printf("Opcode = 02. Subtract From Pointer Immediate\n") ;
  161. PrintIR(IR) ;
  162.  
  163. PREG = ParseOp1Reg(IR) ;
  164. VAL = ParseOp2 (IR) ;
  165. P[PREG] -= VAL;
  166. printf("%d has been subtracted from P%d \n", PREG, VAL);
  167. return 1;
  168. }
  169.  
  170. int OP3(char *IR)
  171. {
  172. printf("Opcode = 03. Load Accumulator Immediate\n") ;
  173. PrintIR(IR) ;
  174. ACC = ParseOP1andOP2Imm(IR);
  175. printf("%d has been loaded into the accumulator \n", ACC);
  176. return 1;
  177. }
  178.  
  179. int OP4(char *IR)
  180. { int VAL;
  181. printf("Opcode = 04. Load Accumulator Register Addressing\n") ;
  182. PrintIR(IR) ;
  183. VAL = ParseOp1Reg(IR);
  184. ACC = P[VAL];
  185. printf("%d has been loaded into the accumulator \n", ACC);
  186. return 1;
  187. }
  188.  
  189. int OP5(char *IR)
  190. {
  191. int VAL;
  192. printf("Opcode = 05. Load Accumulator Direct Addressing\n") ;
  193. PrintIR(IR) ;
  194. VAL = ParseOp1(IR);
  195. ACC = FetchData(VAL);
  196. printf("%d has been loaded into the accumulator \n", ACC);
  197. return 1;
  198. }
  199.  
  200. int OP6(char *I)
  201. { int VAL, tmpACC;
  202. printf("Opcode = 06. Store Accumulator Register Addressing\n") ;
  203. PrintIR(IR) ;
  204. tmpACC = ACC;
  205. VAL = ParseOp1Reg(IR);
  206. memory[P[VAL]][5] = tmpACC%10;
  207. tmpACC /= 10;
  208. memory[P[VAL]][4] = tmpACC%10;
  209. tmpACC /= 10;
  210. memory[P[VAL]][3] = tmpACC%10;
  211. tmpACC /= 10;
  212. memory[P[VAL]][2] = tmpACC%10;
  213. memory[P[VAL]][1] = 90;
  214. memory[P[VAL]][0] = 90;
  215. printf("%d has been saved in memory location %d\n", ACC,P[VAL]);
  216. return 1;
  217. }
  218.  
  219. int OP7(char *IR)
  220. { int VAL, tmpACC;
  221. printf("Opcode = 07. Store Accumulator Direct Addressing\n");
  222. PrintIR(IR) ;
  223.  
  224. tmpACC = ACC;
  225. VAL = ParseOp1(IR);
  226.  
  227. memory[VAL][5] = tmpACC%10;
  228. tmpACC /= 10;
  229. memory[VAL][4] = tmpACC%10;
  230. tmpACC /= 10;
  231. memory[VAL][3] = tmpACC%10;
  232. tmpACC /= 10;
  233. memory[VAL][2] = tmpACC%10;
  234. memory[VAL][1] = 90;
  235. memory[VAL][0] = 90;
  236. printf("%d has been saved in memory location %d\n", ACC,VAL);
  237. return 1;
  238. }
  239.  
  240. int OP8(char *IR) {
  241. int PREG, VAL, tmp ;
  242. printf("Opcode = 08. Store Register to memory: Register Addressing\n") ;
  243. PrintIR(IR) ;
  244.  
  245. PREG = ParseOp1Reg(IR) ;
  246. VAL = ParseOp2Reg (IR) ;
  247. tmp = R[PREG];
  248. memory[P[VAL]][5] = tmp%10;
  249. tmp /= 10;
  250. memory[P[VAL]][4] = tmp%10;
  251. tmp /= 10;
  252. memory[P[VAL]][3] = tmp%10;
  253. tmp /= 10;
  254. memory[P[VAL]][2] = tmp%10;
  255. tmp /= 10;
  256. memory[P[VAL]][1] = 90;
  257. memory[P[VAL]][0] = 90;
  258. printf("%d has been save in memory location %d \n", R[PREG], P[VAL]);
  259. return 1;
  260. }
  261.  
  262. int OP9(char *IR) {
  263. int PREG, VAL, tmp ;
  264. printf("Opcode = 09. Store Register to memory: Direct Addressing\n") ;
  265. PrintIR(IR) ;
  266.  
  267. PREG = ParseOp1Reg(IR) ;
  268. VAL = ParseOp2(IR) ;
  269. tmp = R[PREG];
  270. memory[VAL][5] = tmp%10;
  271. tmp /= 10;
  272. memory[VAL][4] = tmp%10;
  273. tmp /= 10;
  274. memory[VAL][3] = tmp%10;
  275. tmp /= 10;
  276. memory[VAL][2] = tmp%10;
  277. tmp /= 10;
  278. memory[VAL][1] = 90;
  279. memory[VAL][0] = 90;
  280. printf("%d has been save in memory location %d \n", R[PREG], VAL);
  281. return 1;
  282. }
  283.  
  284. int OP10(char *IR) {
  285. int PREG, VAL;
  286. printf("Opcode = 10. Load Register from memory: Register Addressing \n") ;
  287. PrintIR(IR) ;
  288.  
  289. PREG = ParseOp1Reg(IR) ;
  290. VAL = ParseOp2Reg(IR) ;
  291. R[PREG] = FetchData(P[VAL]);
  292. printf("R%d has been loaded with value %d \n", PREG, R[PREG]);
  293. return 1;
  294. }
  295.  
  296. int OP11(char *IR) {
  297. int PREG, VAL, tmp ;
  298. printf("Opcode = 11. Load Register from memory: Direct Addressing \n") ;
  299. PrintIR(IR) ;
  300.  
  301. PREG = ParseOp1Reg(IR) ;
  302. VAL = ParseOp2(IR) ;
  303. R[PREG] = FetchData(VAL);
  304. printf("R%d has been loaded with value %d \n", PREG, R[PREG]);
  305. return 1;
  306. }
  307.  
  308. int OP12(char *IR) {
  309. int VAL;
  310. printf("Opcode = 12. Load Register R0 Immediate\n") ;
  311. PrintIR(IR) ;
  312.  
  313. R[0] = ParseOP1andOP2Imm(IR);
  314. printf("R0 has been loaded with value %d \n", R[0]);
  315. return 1;
  316. }
  317.  
  318. int OP13(char *IR) {
  319. int PREG, VAL;
  320. printf("Opcode = 13. Register to Register Transfer\n") ;
  321. PrintIR(IR) ;
  322.  
  323. PREG = ParseOp1Reg(IR) ;
  324. VAL = ParseOp2Reg(IR) ;
  325. R[PREG] = R[VAL];
  326. printf("R%d has been loaded with value %d \n", PREG, R[PREG]);
  327. return 1;
  328. }
  329.  
  330. int OP14(char *IR) {
  331. int PREG;
  332. printf("Opcode = 14. Load Accumulator from Register\n") ;
  333. PrintIR(IR) ;
  334.  
  335. PREG = ParseOp1Reg(IR);
  336. ACC = R[PREG];
  337. printf("ACC has been loaded with value %d \n", ACC);
  338. return 1;
  339. }
  340.  
  341.  
  342. int OP15(char *IR) {
  343. int PREG;
  344. printf("Opcode = 15. Load Register from Accumulator\n") ;
  345. PrintIR(IR) ;
  346.  
  347. PREG = ParseOp1Reg(IR);
  348. R[PREG] = ACC;
  349. printf("R%d has been loaded with value %d \n", PREG, R[PREG]);
  350. return 1;
  351. }
  352.  
  353. int OP16(char *IR) {
  354. int VAL;
  355. printf("Opcode = 16. Add Accumulator Immediate\n") ;
  356. PrintIR(IR) ;
  357.  
  358. VAL= ParseOP1andOP2Imm(IR);
  359. ACC += VAL;
  360. printf("%d has been added to the accumulator \n", VAL );
  361. return 1;
  362. }
  363.  
  364. int OP17(char *IR) {
  365. int VAL;
  366. printf("Opcode = 17. Subtract Accumulator Immediate\n") ;
  367. PrintIR(IR) ;
  368.  
  369. VAL= ParseOP1andOP2Imm(IR);
  370. ACC -= VAL;
  371. printf("%d has been subtracted from the accumulator \n", VAL );
  372. return 1;
  373. }
  374.  
  375. int OP18(char *IR) {
  376. int PREG;
  377. printf("Opcode = 18. Add contents of Register to Accumulator\n") ;
  378. PrintIR(IR) ;
  379.  
  380. PREG = ParseOp1Reg(IR);
  381. ACC += R[PREG];
  382. printf("R%d has been added to the accumulator \n", R[PREG]);
  383. return 1;
  384. }
  385.  
  386. int OP19(char *IR) {
  387. int PREG;
  388. printf("Opcode = 19. Subtract contents of Register from Accumulator\n") ;
  389. PrintIR(IR) ;
  390.  
  391. PREG = ParseOp1Reg(IR);
  392. ACC -= R[PREG];
  393. printf("R%d has been subtracted from the accumulator \n", R[PREG]);
  394. return 1;
  395. }
  396.  
  397. int OP20(char *IR) {
  398. int PREG, VAL;
  399. printf("Opcode = 20. Add Accumulator Register Addressing\n") ;
  400. PrintIR(IR) ;
  401.  
  402. PREG = ParseOp1Reg(IR);
  403. VAL = FetchData(P[PREG]);
  404. ACC += VAL;
  405. printf("%d has been added to the accumulator \n", P[PREG]);
  406. return 1;
  407. }
  408.  
  409. int OP21(char *IR) {
  410. int PREG, VAL;
  411. printf("Opcode = 21. Add Accumulator Direct Addressing\n") ;
  412. PrintIR(IR);
  413.  
  414. PREG = ParseOp1(IR);
  415. VAL = FetchData(PREG);
  416. ACC += VAL;
  417. printf("%d has been added to the accumulator \n", VAL);
  418. return 1;
  419. }
  420.  
  421. int OP22(char *IR) {
  422. int PREG, VAL;
  423. printf("Opcode = 22. Subtract Accumulator Register Addressing\n") ;
  424. PrintIR(IR) ;
  425.  
  426. PREG = ParseOp1Reg(IR);
  427. VAL = FetchData(P[PREG]);
  428. ACC -= VAL;
  429. printf("%d has been subtracted from the accumulator \n", P[PREG]);
  430. return 1;
  431. }
  432.  
  433. int OP23(char *IR) {
  434. int PREG, VAL;
  435. printf("Opcode = 23. Subtract Accumulator Direct Addressing\n") ;
  436. PrintIR(IR);
  437.  
  438. PREG = ParseOp1(IR);
  439. VAL = FetchData(PREG);
  440. ACC -= VAL;
  441. printf("%d has been subtracted from the accumulator \n", VAL);
  442. return 1;
  443. }
  444.  
  445. int OP24(char *IR, int *PSW) {
  446. int PREG;
  447. printf("Opcode = 24. Compare Equal Register Addressing\n") ;
  448. PrintIR(IR);
  449.  
  450. PREG = ParseOp1Reg(IR);
  451.  
  452. if(FetchData(P[PREG]) == ACC) {
  453. PSW[0] = 1;
  454. printf("PSW[0] has been set to true\n");
  455. }
  456. else {
  457. PSW[0] = 0;
  458. printf("PSW[0] has been set to false\n");
  459. }
  460. return 1;
  461. }
  462.  
  463. int OP25(char *IR, int *PSW) {
  464. int PREG, VAL;
  465. printf("Opcode = 25. Compare Less Register Addressing\n") ;
  466. PrintIR(IR);
  467.  
  468. PREG = ParseOp1Reg(IR);
  469.  
  470. if(FetchData(P[PREG]) > ACC) {
  471. PSW[0] = 1;
  472. printf("PSW[0] has been set to true\n");
  473. }
  474. else {
  475. PSW[0] = 0;
  476. printf("PSW[0] has been set to false\n");
  477. }
  478. return 1;
  479. }
  480.  
  481. int OP26(char *IR, int *PSW) {
  482. int PREG, VAL;
  483. printf("Opcode = 26. Compare Greater Register Addressing\n") ;
  484. PrintIR(IR);
  485.  
  486. PREG = ParseOp1Reg(IR);
  487.  
  488. if(FetchData(P[PREG]) < ACC) {
  489. PSW[0] = 1;
  490. printf("PSW[0] has been set to true\n");
  491. }
  492. else {
  493. PSW[0] = 0;
  494. printf("PSW[0] has been set to false\n");
  495. }
  496. return 1;
  497. }
  498.  
  499. int OP27(char *IR, int *PSW) {
  500.  
  501. printf("Opcode = 27. Compare Greater Immediate\n") ;
  502. PrintIR(IR);
  503.  
  504.  
  505. if(ParseOP1andOP2Imm(IR) < ACC) {
  506. PSW[0] = 1;
  507. printf("PSW[0] has been set to true\n");
  508. }
  509. else {
  510. PSW[0] = 0;
  511. printf("PSW[0] has been set to false\n");
  512. }
  513. return 1;
  514. }
  515.  
  516. int OP28(char *IR, int *PSW) {
  517.  
  518. printf("Opcode = 28. Compare Equal Immediate\n") ;
  519. PrintIR(IR);
  520.  
  521.  
  522. if(ParseOP1andOP2Imm(IR) == ACC) {
  523. PSW[0] = 1;
  524. printf("PSW[0] has been set to true\n");
  525. }
  526. else {
  527. PSW[0] = 0;
  528. printf("PSW[0] has been set to false\n");
  529. }
  530. return 1;
  531. }
  532.  
  533. int OP29(char *IR, int *PSW) {
  534.  
  535. printf("Opcode = 29. Compare Less Immediate\n") ;
  536. PrintIR(IR);
  537.  
  538.  
  539. if(ParseOP1andOP2Imm(IR) > ACC) {
  540. PSW[0] = 1;
  541. printf("PSW[0] has been set to true\n");
  542. }
  543. else {
  544. PSW[0] = 0;
  545. printf("PSW[0] has been set to false\n");
  546. }
  547. return 1;
  548. }
  549.  
  550. int OP30(char *IR, int *PSW) {
  551. int PREG;
  552. printf("Opcode = 30. Compare Register Equal\n");
  553. PrintIR(IR);
  554.  
  555. PREG = ParseOp1Reg(IR);
  556.  
  557. if(FetchData(R[PREG] == ACC)) {
  558. PSW[0] = 1;
  559. printf("PSW[0] has been set to true\n");
  560. }
  561. else {
  562. PSW[0] = 0;
  563. printf("PSW[0] has been set to false\n");
  564. }
  565. return 1;
  566. }
  567.  
  568. int OP31(char *IR, int *PSW) {
  569. int PREG;
  570. printf("Opcode = 31. Compare Register Less\n") ;
  571. PrintIR(IR);
  572.  
  573. PREG = ParseOp1Reg(IR);
  574.  
  575. if(FetchData(R[PREG] > ACC)) {
  576. PSW[0] = 1;
  577. printf("PSW[0] has been set to true\n");
  578. }
  579. else {
  580. PSW[0] = 0;
  581. printf("PSW[0] has been set to false\n");
  582. }
  583. return 1;
  584. }
  585.  
  586. int OP32(char *IR, int *PSW) {
  587. int PREG;
  588. printf("Opcode = 32. Compare Register Greater\n") ;
  589. PrintIR(IR);
  590.  
  591. PREG = ParseOp1Reg(IR);
  592.  
  593. if(FetchData(R[PREG] < ACC)) {
  594. PSW[0] = 1;
  595. printf("PSW[0] has been set to true\n");
  596. }
  597. else {
  598. PSW[0] = 0;
  599. printf("PSW[0] has been set to false\n");
  600. }
  601. return 1;
  602. }
  603.  
  604. int OP33(char *IR, int *PSW, int *PC) {
  605. int VAL;
  606. printf("Opcode = 33. Branch Conditional True\n") ;
  607. PrintIR(IR);
  608.  
  609. VAL = ParseOp1(IR);
  610.  
  611. if(PSW[0] == 1) {
  612. *PC = VAL;
  613. printf("Program counter set to %d \n", VAL);
  614. }
  615. else {
  616. PC += 1;
  617. printf("Branch condiction failed\n");
  618. }
  619. return 1;
  620. }
  621.  
  622. int OP34(char *IR, int *PSW, int *PC) {
  623. int VAL;
  624. printf("Opcode = 34. Branch Conditional False\n") ;
  625. PrintIR(IR);
  626.  
  627. VAL = ParseOp1(IR);
  628.  
  629. if(PSW[0] == 0) {
  630. *PC = VAL;
  631. printf("Program counter set to %d \n", VAL);
  632. }
  633. else {
  634. PC += 1;
  635. printf("Branch condiction failed\n");
  636. }
  637. return 1;
  638. }
  639.  
  640. int OP35(char *IR, int *PSW, int *PC) {
  641. int VAL;
  642. printf("Opcode = 35. Branch Unconditional\n") ;
  643. PrintIR(IR);
  644.  
  645. VAL = ParseOp1(IR);
  646. *PC = VAL;
  647. printf("Program counter set to %d \n", VAL);
  648.  
  649. return 1;
  650. }
  651.  
  652. int OP99(char *IR) {
  653. printf("Opcode = 99. Halt\n") ;
  654. return 1;
  655. }
  656.  
  657. /* Now its your turn! Provide the prototype and implementation for the remaining opcodes. */
  658.  
  659. main(int argc, char *argv[])
  660. {
  661.  
  662. //Step 1 Read file into VM memory. Assume the file name is program2.
  663.  
  664. fp = open("program2", O_RDONLY) ; //always check the return value.
  665. printf("Open is %d\n", fp) ;
  666.  
  667. if (fp < 0) //error in read
  668. {
  669. printf("Could not open file\n");
  670. exit(0) ;
  671. }
  672.  
  673.  
  674. //read in the first line of the program
  675.  
  676. int ret = read (fp, input_line, 7 ) ; //returns number of characters read`
  677.  
  678. while (1)
  679. {
  680. if (ret <= 0) //indicates end of file or error
  681. break ; //breaks out of infinite loop
  682.  
  683. //copy from input line into program memory
  684.  
  685. printf("Copying Program line %d into memory\n", program_line) ;
  686. for (i = 0; i < 6 ; i++)
  687. {
  688. memory[program_line][i] = input_line[i] ;
  689. printf("%c ", memory[program_line][i]) ;
  690. }
  691. printf("\n") ;
  692.  
  693. //read in next line of code
  694.  
  695. ret = read (fp, input_line, 7 ) ;
  696.  
  697. //if the firat character is a 'Z' then you are reading data.
  698. //No more program code so break out of loop
  699.  
  700.  
  701. if(input_line[0] == 'Z')
  702. break ;
  703.  
  704. program_line++ ; //now at a new line in the prog
  705. }
  706.  
  707. printf("PROGRAM COPIED INTO VM MEMORY!!\n") ;
  708.  
  709. int Done = 0 ;
  710. PC = 0;
  711. while (!Done)
  712. {for (i = 0; i < 6 ; i++)
  713. IR[i] = memory[PC][i] ;
  714.  
  715. opcode = ((int) (IR[0])- 48) * 10 ;
  716. opcode += ((int) (IR[1])- 48) ;
  717. printf("\n In Program Execution Loop: New PC is %d OPCODE IS %d\n\n", PC, opcode) ;
  718.  
  719. /* You need to put in the case statements for the remaining opcodes */
  720. switch(opcode) {
  721. case 0: OP0(IR) ; PC++; break ;
  722. case 1: OP1(IR) ; PC++; break ;
  723. case 2: OP2(IR) ; PC++; break ;
  724. case 3: OP3(IR) ; PC++ ; break ;
  725. case 4: OP4(IR) ; PC++ ; break;
  726. case 5: OP5(IR) ; PC++; break ;
  727. case 6: OP6(IR) ; PC++ ; break ;
  728. case 7: OP7(IR) ; PC++; break ;
  729. case 8: OP8(IR) ; PC++; break ;
  730. case 9: OP9(IR) ; PC++; break ;
  731. case 10: OP10(IR) ; PC++; break ;
  732. case 11: OP11(IR) ; PC++; break ;
  733. case 12: OP12(IR) ; PC++; break ;
  734. case 13: OP13(IR) ; PC++; break ;
  735. case 14: OP14(IR) ; PC++; break ;
  736. case 15: OP15(IR) ; PC++; break ;
  737. case 16: OP16(IR) ; PC++; break ;
  738. case 17: OP17(IR) ; PC++; break ;
  739. case 18: OP18(IR) ; PC++; break ;
  740. case 19: OP19(IR) ; PC++; break ;
  741. case 20: OP20(IR) ; PC++; break ;
  742. case 21: OP21(IR) ; PC++; break ;
  743. case 22: OP22(IR) ; PC++; break ;
  744. case 23: OP23(IR) ; PC++; break ;
  745. case 24: OP24(IR, PSW) ; PC++; break ;
  746. case 25: OP25(IR, PSW) ; PC++; break ;
  747. case 26: OP26(IR, PSW) ; PC++ ; break;
  748. case 27: OP27(IR, PSW) ; PC++; break ;
  749. case 28: OP28(IR, PSW) ; PC++; break ;
  750. case 29: OP29(IR, PSW); PC++ ; break ;
  751. case 30: OP30(IR, PSW) ; PC++; break ;
  752. case 31: OP31(IR, PSW) ; PC++; break ;
  753. case 32: OP32(IR, PSW) ; PC++; break ;
  754. case 33: OP33(IR, PSW, &PC) ; break ;
  755. case 34: OP34(IR, PSW, &PC) ; break ;
  756. case 35: OP35(IR, PSW, &PC) ; break ;
  757. case 99: printf("ALL DONE\n") ; Done = 1 ;
  758. default: printf("Instruction %d not found!~\n", opcode) ;
  759. exit(0) ;
  760. }
  761. }
  762. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement