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).
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
Get Answers For Free
Most questions answered within 1 hours.