Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. /* File: Assembly */
  2. /* Author: Daniel Kesselman (email: danielkesselman98@hotmail.com */
  3. /* Date: 25-9-2017 */
  4. /* Version: 1.0 */
  5. /* Description: Performs 8 different assembly instructions with 2 registers.
  6. * Includes addition, subtraction, multiplication and in/decrementation. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. int main (int argc, char *argv[]) {
  13. int counter, R1, R2;
  14. char input, n;
  15. while (input != 'E') {
  16. scanf ("%c", &input);
  17. /* LCS command */
  18. if (input == 'L') {
  19. for (counter = 0; counter < 5; counter++) {
  20. scanf ("%c", &input);
  21. }
  22. if (input == '1') {
  23. for (counter = 0; counter < 2; counter++) {
  24. scanf ("%c", &n);
  25. }
  26. R1 = n;
  27. }
  28. else {
  29. for (counter = 0; counter < 2; counter++) {
  30. scanf ("%c", &n);
  31. }
  32. R2 = n;
  33. }
  34. }
  35. /* INC command */
  36. else if (input == 'I') {
  37. for (counter = 0; counter < 5; counter++) {
  38. scanf ("%c", &input);
  39. }
  40. if (input == '1') {
  41. R1 ++;
  42. }
  43. else {
  44. R2 ++;
  45. }
  46. }
  47. /* DEC command */
  48. else if (input == 'D') {
  49. for (counter = 0; counter < 5; counter++) {
  50. scanf ("%c", &input);
  51. }
  52. if (input == '1') {
  53. R1 --;
  54. }
  55. else {
  56. R2 --;
  57. }
  58. }
  59. /* ADD command */
  60. else if (input == 'A') {
  61. for (counter = 0; counter < 5; counter++) {
  62. scanf ("%c", &input);
  63. }
  64. if (input == '1') {
  65. for (counter = 0; counter < 3; counter++) {
  66. scanf ("%c", &input);
  67. }
  68. if (input == '1') {
  69. R1 = R1 + R1;
  70. }
  71. else {
  72. R1 = R1 + R2;
  73. }
  74. }
  75. else {
  76. for (counter = 0; counter < 3; counter++) {
  77. scanf ("%c", &input);
  78. }
  79. if (input == '1') {
  80. R2 = R2 + R1;
  81. }
  82. else {
  83. R2 = R2 + R2;
  84. }
  85. }
  86. }
  87. /* SUB command */
  88. else if (input == 'S') {
  89. for (counter = 0; counter < 5; counter++) {
  90. scanf ("%c", &input);
  91. }
  92. if (input == '1') {
  93. for (counter = 0; counter < 3; counter++) {
  94. scanf ("%c", &input);
  95. }
  96. if (input == '1') {
  97. R1 = R1 - R1;
  98. }
  99. else {
  100. R1 = R1 - R2;
  101. }
  102. }
  103. else {
  104. for (counter = 0; counter < 3; counter++) {
  105. scanf ("%c", &input);
  106. }
  107. if (input == '1') {
  108. R2 = R2 - R1;
  109. }
  110. else {
  111. R2 = R2 - R2;
  112. }
  113. }
  114. }
  115. /* MUL command */
  116. else if (input == 'M') {
  117. for (counter = 0; counter < 5; counter++) {
  118. scanf ("%c", &input);
  119. }
  120. if (input == '1') {
  121. for (counter = 0; counter < 3; counter++) {
  122. scanf ("%c", &input);
  123. }
  124. if (input == '1') {
  125. R1 = R1 * R1;
  126. }
  127. else {
  128. R1 = R1 * R2;
  129. }
  130. }
  131. else {
  132. for (counter = 0; counter < 3; counter++) {
  133. scanf ("%c", &input);
  134. }
  135. if (input == '1') {
  136. R2 = R2 * R1;
  137. }
  138. else {
  139. R2 = R2 * R2;
  140. }
  141. }
  142. }
  143. /* OUT command */
  144. else if (input == 'O') {
  145. for (counter = 0; counter < 5; counter++) {
  146. scanf ("%c", &input);
  147. }
  148. if (input == '1') {
  149. printf ("%d\n", R1);
  150. }
  151. else {
  152. printf ("%d\n", R2);
  153. }
  154. }
  155. }
  156. return 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement