Question

In: Computer Science

Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers....

Write an assembly language program that repeatedly prompts the user to enter signed decimal integer numbers. The program should be run from the command prompt, output a text prompt to the screen, and then wait for the user to type in a number followed by the Enter key. (The legitimate range of user input values is any signed integer that can be represented in 32 bits.) After each number is entered, the program should determine and display the following information about the number: whether it is positive or negative; whether or not it is evenly divisible by 16; and whether or not it can be represented in 16 bits (in other words, is it in the range -32768 x +32767). For example, if the user entered the number +5, the output generated by the program should look similar to this:
+5 is a positive number.
+5 is not evenly divisible by 16.
+5 can be represented in 16 bits.
On the other hand, if the user entered -32816, the output would look like this:
-32816 is a negative number.
-32816 is evenly divisible by 16.
-32816 cannot be represented in 16 bits.
After determining and displaying the above information, the program should prompt the user to enter another number. This process should continue until the user enters the value 0 (which is neither positive nor negative). At that point, execution should terminate and return to the command prompt.
Assemble, link, and test your program. Make sure to test it for each of the eight possible input cases (permutations of positive vs. negative, divisible by 16 vs. not divisible by 16, and fits in 16 bits vs. does not fit in 16 bits), as well as the ninth possibility (the special case of 0, which exits the program). When you are sure it is working, run it from the command prompt and capture a screen shot(s) of a test run that illustrates all nine possibilities and the corresponding outputs.

Solutions

Expert Solution

Required Assembly code is given below:

.LC0:

        .string "%d"

.LC1:

        .string "%d is a positive number.\n"

.LC2:

        .string "%d is a negative number.\n"

.LC3:

        .string "%d is evenly divisible by 16.\n"

.LC4:

        .string "%d is not evenly divisible by 16.\n"

.LC5:

        .string "%d can be represented in 16 bits.\n"

.LC6:

        .string "%d cannot be represented in 16 bits.\n"

main:

        push    rbp

        mov     rbp, rsp

        sub     rsp, 16

.L8:

        lea     rax, [rbp-4]

        mov     rsi, rax

        mov     edi, OFFSET FLAT:.LC0

        mov     eax, 0

        call    __isoc99_scanf

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        jle     .L2

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC1

        mov     eax, 0

        call    printf

.L2:

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        jns     .L3

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC2

        mov     eax, 0

        call    printf

.L3:

        mov     eax, DWORD PTR [rbp-4]

        and     eax, 15

        test    eax, eax

        jne     .L4

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        je      .L4

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC3

        mov     eax, 0

        call    printf

.L4:

        mov     eax, DWORD PTR [rbp-4]

        and     eax, 15

        test    eax, eax

        je      .L5

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        je      .L5

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC4

        mov     eax, 0

        call    printf

.L5:

        mov     eax, DWORD PTR [rbp-4]

        cmp     eax, -32768

        jl      .L6

        mov     eax, DWORD PTR [rbp-4]

        cmp     eax, 32767

        jg      .L6

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        je      .L6

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC5

        mov     eax, 0

        call    printf

.L6:

        mov     eax, DWORD PTR [rbp-4]

        cmp     eax, -32768

        jge     .L7

        mov     eax, DWORD PTR [rbp-4]

        cmp     eax, 32767

        jle     .L7

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        je      .L7

        mov     eax, DWORD PTR [rbp-4]

        mov     esi, eax

        mov     edi, OFFSET FLAT:.LC6

        mov     eax, 0

        call    printf

.L7:

        mov     eax, DWORD PTR [rbp-4]

        test    eax, eax

        jne     .L8

        mov     eax, 0

        leave

        ret

Screenshot of above code output is given below:

PLEASE UPVOTE THE ANSWER AND FEEL FREE TO ASK YOUR DOUBTS IN COMMENT SECTION


Related Solutions

JAVA Language: Write a program that prompts the user to enter a positive integer n (0...
JAVA Language: Write a program that prompts the user to enter a positive integer n (0 up to 232 -1). You must write a function that takes as input n and returns a string s representing the number n in binary. For this assignment, you must use the method of successive division by 2 to convert the number to binary. Your main program must print out s. Example: If the user enters the number 66, your program must print out...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and print the average of the numbers. 2. Write a Java program that uses a for loop to print the odd numbers from 1 to 20. Print one number per line in the command line window. 3. Write a program which asks the user to input the size of potatoe fries she would like to purchase, and based on the size, it will tell her...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
Problem 1 Write a program that prompts the user to enter an integer It then tells...
Problem 1 Write a program that prompts the user to enter an integer It then tells the user if the integers is a multiple of 2, 3, 5, 7 or none of the above. Program language is C Ex. Enter an integer 12 You entered 12 The number you entered is a multiple of 2 ----------------------------------------------- Enter an integer 11 You entered 11 The number you entered is not a multiple of 2, 3, 5, or 7
Write a Java program that prompts the user to enter a list of integer values and...
Write a Java program that prompts the user to enter a list of integer values and displays whether the list is sorted in increasing order or not. Here is a sample run. Note that the first number in the input indicates the number of the elements in the list. <Output> Enter list: 8 101516619111 The list is not sorted <End Output <Output> Enter list: 10 11344579 11 21 The list is already sorted <End Output Create a complete class for...
Write a program that prompts the user to enter an integer from 1 to 15 and...
Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as shown in the following sample run: here............THE PYRAMID HAS TO BE THIS SHAPE AND IT IS DONE IN JAVA PLEASE 7 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT