Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Translate following C code to assembly Don\'t use jump table,use conditional bra

ID: 3564411 • Letter: T

Question

Translate following C code to assembly

Don't use jump table,use conditional branching only, and no ascii or cfi, only the basic assembly code.

#include <stdio.h>
enum dfaState { EE, OE, OO, EO }; // DFA states
enum dfaState state = EE; // initial DFA state
char input;
int main(void)
{

printf("Enter a string of 0s and 1s: ");
while (1) {

scanf("%c", &input);
if (input == ' ') // if end-of-line exit loop
break;
if ( (input != '0') && (input != '1') ) { // invalid input
printf("Invalid input: program terminating ");
break;
}

switch (state) { // input is either '0' or '1'
case EE:
state = (input == '0') ? OE : EO;
break;
case OE:
state = (input == '0') ? EE : OO;
break;
case OO:
state = (input == '0') ? EO : OE;
break;
case EO:
state = (input == '0') ? OO : EE;
break;
}
};

if (input == ' ') {
if (state == EE)
printf("Input accepted ");
else
printf("Input rejected ");
}
return 0;
}

Explanation / Answer

#include <stdio.h>
enum dfaState { EE, OE, OO, EO }; // DFA states
enum dfaState state = EE; // initial DFA state
char input;
int main(void)
{

printf("Enter a string of 0s and 1s: ");
while (1) {

scanf("%c", &input);
if (input == ' ') // if end-of-line exit loop
break;
if ( (input != '0') && (input != '1') ) { // invalid input
printf("Invalid input: program terminating ");
break;
}

switch (state) { // input is either '0' or '1'
case EE:
state = (input == '0') ? OE : EO;
break;
case OE:
state = (input == '0') ? EE : OO;
break;
case OO:
state = (input == '0') ? EO : OE;
break;
case EO:
state = (input == '0') ? OO : EE;
break;
}
};

if (input == ' ') {
if (state == EE)
printf("Input accepted ");
else
printf("Input rejected ");
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote