Question

Write the following ANNA assembly language programs. 1.HighestnumberWrite an ANNA assembly program (high.ac) that will continuously...

Write the following ANNA assembly language programs.

1.HighestnumberWrite an ANNA assembly program (high.ac) that will continuously prompt the user for numbers. When the user enters a negative number, print the highest positive number entered by the user and exit the program. Print a zero if they did not enter any positive numbers.

2.DivisionWrite an ANNA assembly program (div.ac) that divides two positive numbers that come from user input and returns both the quotient and the remainder. For example, if the user enters 74 as a dividend and 7 as a divisor, then the quotient is 10 and the remainder is 4.

Notes:

•The first number the user enters is thedividend.–If it is zero or less, halt the program without printing anything.

•The the second number the user enters is thedivisor.–If it is zero or less, halt the program without printing anything.•The quotient must be the first number displayed.

•The remainder must be the second number displayed.

Assumptions:

You may make the following assumptions:

1. All input values will be 16-bit two’s complement numbers (-32,768 to32,767),

2. Overflow will not occur. Note: Given the previous assumption, this is only possible in problem 3 if someone enters over 32,768 integers in the same range).

Homework Answers

Answer #1

Question-1

.LC0:
        .string "Input a positive integer:"
.LC1:
        .string "%d"
.LC2:
        .string "No positive number entered\n"
.LC3:
        .string "Input next positive integer:"
.LC4:
        .string "Maximum value entered is %d\n"
.LC5:
        .string "No positive value entered is %d\n"
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 32
        mov     DWORD PTR [rbp-4], 0
        mov     DWORD PTR [rbp-16], 0
        mov     edi, OFFSET FLAT:.LC0
        call    puts
        lea     rax, [rbp-20]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    __isoc99_scanf
        mov     eax, DWORD PTR [rbp-20]
        test    eax, eax
        jg      .L2
        mov     esi, 0
        mov     edi, OFFSET FLAT:.LC2
        mov     eax, 0
        call    printf
        mov     eax, 0
        jmp     .L8
.L2:
        mov     eax, DWORD PTR [rbp-20]
        mov     DWORD PTR [rbp-8], eax
        mov     eax, DWORD PTR [rbp-20]
        mov     DWORD PTR [rbp-12], eax
        jmp     .L4
.L5:
        mov     eax, DWORD PTR [rbp-20]
        add     DWORD PTR [rbp-16], eax
        add     DWORD PTR [rbp-4], 1
        mov     eax, DWORD PTR [rbp-20]
        cmp     DWORD PTR [rbp-12], eax
        cmovge  eax, DWORD PTR [rbp-12]
        mov     DWORD PTR [rbp-12], eax
        mov     eax, DWORD PTR [rbp-20]
        cmp     DWORD PTR [rbp-8], eax
        cmovle  eax, DWORD PTR [rbp-8]
        mov     DWORD PTR [rbp-8], eax
        mov     edi, OFFSET FLAT:.LC3
        call    puts
        lea     rax, [rbp-20]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    __isoc99_scanf
.L4:
        mov     eax, DWORD PTR [rbp-20]
        test    eax, eax
        jg      .L5
        cmp     DWORD PTR [rbp-12], 0
        jle     .L6
        mov     eax, DWORD PTR [rbp-12]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC4
        mov     eax, 0
        call    printf
        jmp     .L7
.L6:
        mov     esi, 0
        mov     edi, OFFSET FLAT:.LC5
        mov     eax, 0
        call    printf
.L7:
        mov     eax, 0
.L8:
        leave
        ret

Question-2

.LC0:
        .string "Enter dividend: "
.LC1:
        .string "%d"
.LC2:
        .string "Enter divisor: "
.LC3:
        .string "Quotient is %d\n"
.LC4:
        .string "Remainder is %d"
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        lea     rax, [rbp-12]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    __isoc99_scanf
        mov     eax, DWORD PTR [rbp-12]
        test    eax, eax
        jg      .L2
        mov     eax, 0
        jmp     .L5
.L2:
        mov     edi, OFFSET FLAT:.LC2
        mov     eax, 0
        call    printf
        lea     rax, [rbp-16]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    __isoc99_scanf
        mov     eax, DWORD PTR [rbp-16]
        test    eax, eax
        jg      .L4
        mov     eax, 0
        jmp     .L5
.L4:
        mov     eax, DWORD PTR [rbp-12]
        mov     ecx, DWORD PTR [rbp-16]
        cdq
        idiv    ecx
        mov     DWORD PTR [rbp-4], eax
        mov     eax, DWORD PTR [rbp-12]
        mov     ecx, DWORD PTR [rbp-16]
        cdq
        idiv    ecx
        mov     DWORD PTR [rbp-8], edx
        mov     eax, DWORD PTR [rbp-4]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC3
        mov     eax, 0
        call    printf
        mov     eax, DWORD PTR [rbp-8]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC4
        mov     eax, 0
        call    printf
        mov     eax, 0
.L5:
        leave
        ret
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Assembly Programming in MIPS Write a program in MIPS assembler that performs the following computations: Prompts...
Assembly Programming in MIPS Write a program in MIPS assembler that performs the following computations: Prompts the user to enter two integers and stores the smaller one in the first data memory word (with the lowest address) and the larger one in the second data memory word. Then divides the larger word by the smaller one in integer and stores the integer quotient in the third data memory word and the remainder in the fourth data memory word. Finally, it...
Write a Hack Assembly Language program to calculate the quotient from a division operation. The values...
Write a Hack Assembly Language program to calculate the quotient from a division operation. The values of dividend a and divisor b are stored in RAM[0] (R0) and RAM[1] (R1), respectively. The dividend a is a non-negative integer, and the divisor b is a positive integer. Store the quotient in RAM[2] (R2). Ignore the remainder. Example: if you are given two numbers 15 and 4 as dividend a (R0) and divisor b (R1), respectively, the answer will be 3 stored...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
Write a python program that does the following: Prompts the user for three numbers in one...
Write a python program that does the following: Prompts the user for three numbers in one request. Be sure to specify the “delimiter” by which a user enters those three numbers. Divides the first number by the second number and add that result to the third number. Prints output that shows in one line the formula applied and the result of the calculation. Validate input by: •    Checking the user entered 3 values •    Appropriately checking for the following errors:...
1.Write pseudocode for a program that allows the user to input two numbers (X and Y)...
1.Write pseudocode for a program that allows the user to input two numbers (X and Y) and a code C. If the code has value 1, the program should output the larger of X and Y and otherwise output the smaller. Now convert your pseudocode to an assembly language program. Enter the program into the lab software assembler. Assemble the program and execute it with different input data. 2. Write pseudocode for a program that allows the user to input...
C program fractions.c that does the following: 1. The program starts by making the user enter...
C program fractions.c that does the following: 1. The program starts by making the user enter a non-negative integer number a, called the first numerator. If the user enters a negative number, the program repeats the entry. 2. The program then makes the user enter a positive integer number b, called the first denominator. If the user enters a non-positive number, the program repeats the entry. 3. The program then makes the user enter a non-negative integer number c, called...
1. Write a complete program in C++ that does the following: [2] asks a user to...
1. Write a complete program in C++ that does the following: [2] asks a user to enter two integer numbers (display a warning message that the second number should be different from zero) [3] reads the two numbers from the keyboard; [4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one. [3] displays the result of floating-point division. Make sure to follow programming style guidelines.
Binary Search Tree Code in Java Write a program that prompts user to enter however many...
Binary Search Tree Code in Java Write a program that prompts user to enter however many numbers they want to add to the binary search tree. Then have the user input numbers until the tree contains that many elements. If the user enters a number that already exists in the tree, then a message should be displayed "Number is already in the tree". Once all elements are added to the tree print its contents in sorted order. Assume all user...
Write some C++ program segments that solves the indicated tasks (you do not have to write...
Write some C++ program segments that solves the indicated tasks (you do not have to write a complete program, nor be concerned about "good" output; a small code segment will be enough). a) A program that gets a double number from the user, decides whether that number is positive, negative, or zero and display its decision on the screen. a) A function isPositive that takes as input a double number and returns the integer 1 if the number is positive,...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT