Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* File: Assembly */
- /* Author: Daniel Kesselman (email: danielkesselman98@hotmail.com */
- /* Date: 25-9-2017 */
- /* Version: 1.0 */
- /* Description: Performs 8 different assembly instructions with 2 registers.
- * Includes addition, subtraction, multiplication and in/decrementation. */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main (int argc, char *argv[]) {
- int counter, R1, R2;
- char input, n;
- while (input != 'E') {
- scanf ("%c", &input);
- /* LCS command */
- if (input == 'L') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- for (counter = 0; counter < 2; counter++) {
- scanf ("%c", &n);
- }
- R1 = n;
- }
- else {
- for (counter = 0; counter < 2; counter++) {
- scanf ("%c", &n);
- }
- R2 = n;
- }
- }
- /* INC command */
- else if (input == 'I') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R1 ++;
- }
- else {
- R2 ++;
- }
- }
- /* DEC command */
- else if (input == 'D') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R1 --;
- }
- else {
- R2 --;
- }
- }
- /* ADD command */
- else if (input == 'A') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- for (counter = 0; counter < 3; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R1 = R1 + R1;
- }
- else {
- R1 = R1 + R2;
- }
- }
- else {
- for (counter = 0; counter < 3; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R2 = R2 + R1;
- }
- else {
- R2 = R2 + R2;
- }
- }
- }
- /* SUB command */
- else if (input == 'S') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- for (counter = 0; counter < 3; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R1 = R1 - R1;
- }
- else {
- R1 = R1 - R2;
- }
- }
- else {
- for (counter = 0; counter < 3; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R2 = R2 - R1;
- }
- else {
- R2 = R2 - R2;
- }
- }
- }
- /* MUL command */
- else if (input == 'M') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- for (counter = 0; counter < 3; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R1 = R1 * R1;
- }
- else {
- R1 = R1 * R2;
- }
- }
- else {
- for (counter = 0; counter < 3; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- R2 = R2 * R1;
- }
- else {
- R2 = R2 * R2;
- }
- }
- }
- /* OUT command */
- else if (input == 'O') {
- for (counter = 0; counter < 5; counter++) {
- scanf ("%c", &input);
- }
- if (input == '1') {
- printf ("%d\n", R1);
- }
- else {
- printf ("%d\n", R2);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement