Q. Could anyone help me write this program in assembly language? The program should produce an output like this:
Please enter a number between 0 and 6 (Enter to stop): 2
The Day of Week is Tuesday
Please enter a number between 0 and 6 (Enter to stop): 9
Input Invalid
Please enter a number between 0 and 6 (Enter to stop):
Note: a. The user will be prompted for a character
b. if the input is between 0 and 6 inclusive, the program will print the day of week (0 is Sunday)
c. otherwise, it will print "input invalid"
d. repeat the program until the use just hit "enter" key
Please any help would be really appreciated. Thank you!
Please enter a number between 0 and 6 (Enter to stop): 2
The Day of Week is Tuesday
Please enter a number between 0 and 6 (Enter to stop): 9
Input Invalid
Please enter a number between 0 and 6 (Enter to stop):
Note: a. The user will be prompted for a character
b. if the input is between 0 and 6 inclusive, the program will print the day of week (0 is Sunday)
c. otherwise, it will print "input invalid"
d. repeat the program until the use just hit "enter" key
Please any help would be really appreciated. Thank you!
A. /*
You didn't specify which architecture you were writing assembly
language for, so I guess the default guess would be x86.
In any case, if you have a compiler for the platform you're
working on, you can get a *huge* head start on any assembly
language programming problem by prototyping in C and having
the compiler generate a version of assembly for you.
For special cases (like using atomics or vector instructions)
you can then replace the generic code with your hand-crafted
improvements.
For any flavor of Unix/Linux, use the "-S" option:
$ cc -S days.c
$ cat days.s
There are something equivalent on Windows, but you'll have
to look it up.
*/
#include <stdio.h>
char *days[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
};
int
main(int argc, char* argv[])
{
  char buffer[100];
  while (1) {
    printf("Please enter a number between 0 and 6 (Enter to stop):");
    fgets(buffer, sizeof(buffer), stdin);
    if (buffer[0] == '\n')
      break;
    int day = atoi(buffer);
    if ((day >= 0) && (day <= 6))
      printf("The Day of Week is %s\n", days[day]);
    else
      printf("Input Invalid\n");
  }
  return 0;
}
You didn't specify which architecture you were writing assembly
language for, so I guess the default guess would be x86.
In any case, if you have a compiler for the platform you're
working on, you can get a *huge* head start on any assembly
language programming problem by prototyping in C and having
the compiler generate a version of assembly for you.
For special cases (like using atomics or vector instructions)
you can then replace the generic code with your hand-crafted
improvements.
For any flavor of Unix/Linux, use the "-S" option:
$ cc -S days.c
$ cat days.s
There are something equivalent on Windows, but you'll have
to look it up.
*/
#include <stdio.h>
char *days[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
};
int
main(int argc, char* argv[])
{
  char buffer[100];
  while (1) {
    printf("Please enter a number between 0 and 6 (Enter to stop):");
    fgets(buffer, sizeof(buffer), stdin);
    if (buffer[0] == '\n')
      break;
    int day = atoi(buffer);
    if ((day >= 0) && (day <= 6))
      printf("The Day of Week is %s\n", days[day]);
    else
      printf("Input Invalid\n");
  }
  return 0;
}
Nec Projector Review
Plastic Shed Reviews
Ati Graphic Reviews
Nurse Uniforms Reviews
Cabochons Reviews
Inflatable Water Slides Reviews
Barcode Scanner Reviews
No comments:
Post a Comment