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

Write a program that first ask the user how many number would they like to enter

ID: 3917995 • Letter: W

Question

Write a program that first ask the user how many number would they like to enter then ask what numbers would they like to enter and store them in an array Then display a menu option Press 1 if you want to bubblesort that array in ascending order Press 2 if you want to bubblesort that array in descending order Press 3 if you would like to find the max value Press 4 if you would like to find the min value Press 5 if you would like to find the average of all the values in the array. Result in float if possible Press 6 if you would like to find a specific number ask the user for the key and tell if it is in the array or not if it is at what index. Press 7 to exit the program
This program should be written in MIPS ASSAMBLE Write a program that first ask the user how many number would they like to enter then ask what numbers would they like to enter and store them in an array Then display a menu option Press 1 if you want to bubblesort that array in ascending order Press 2 if you want to bubblesort that array in descending order Press 3 if you would like to find the max value Press 4 if you would like to find the min value Press 5 if you would like to find the average of all the values in the array. Result in float if possible Press 6 if you would like to find a specific number ask the user for the key and tell if it is in the array or not if it is at what index. Press 7 to exit the program
This program should be written in MIPS ASSAMBLE Then display a menu option Press 1 if you want to bubblesort that array in ascending order Press 2 if you want to bubblesort that array in descending order Press 3 if you would like to find the max value Press 4 if you would like to find the min value Press 5 if you would like to find the average of all the values in the array. Result in float if possible Press 6 if you would like to find a specific number ask the user for the key and tell if it is in the array or not if it is at what index. Press 7 to exit the program
This program should be written in MIPS ASSAMBLE

Explanation / Answer

swap(int*, int*):

push rbp

mov rbp, rsp

mov QWORD PTR [rbp-24], rdi

mov QWORD PTR [rbp-32], rsi

mov rax, QWORD PTR [rbp-24]

mov eax, DWORD PTR [rax]

mov DWORD PTR [rbp-4], eax

mov rax, QWORD PTR [rbp-32]

mov edx, DWORD PTR [rax]

mov rax, QWORD PTR [rbp-24]

mov DWORD PTR [rax], edx

mov rax, QWORD PTR [rbp-32]

mov edx, DWORD PTR [rbp-4]

mov DWORD PTR [rax], edx

nop

pop rbp

ret

bubbleSort(int*, int, bool):

push rbp

mov rbp, rsp

sub rsp, 32

mov QWORD PTR [rbp-24], rdi

mov DWORD PTR [rbp-28], esi

mov eax, edx

mov BYTE PTR [rbp-32], al

mov DWORD PTR [rbp-4], 0

.L9:

mov eax, DWORD PTR [rbp-28]

sub eax, 1

cmp DWORD PTR [rbp-4], eax

jge .L11

mov BYTE PTR [rbp-9], 0

mov DWORD PTR [rbp-8], 0

.L7:

mov eax, DWORD PTR [rbp-28]

sub eax, DWORD PTR [rbp-4]

sub eax, 1

cmp DWORD PTR [rbp-8], eax

jge .L4

cmp BYTE PTR [rbp-32], 0

je .L5

mov eax, DWORD PTR [rbp-8]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov edx, DWORD PTR [rax]

mov eax, DWORD PTR [rbp-8]

cdqe

add rax, 1

lea rcx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rcx

mov eax, DWORD PTR [rax]

cmp edx, eax

jle .L5

mov eax, DWORD PTR [rbp-8]

cdqe

add rax, 1

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rdx, rax

mov eax, DWORD PTR [rbp-8]

cdqe

lea rcx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rcx

mov rsi, rdx

mov rdi, rax

call swap(int*, int*)

mov BYTE PTR [rbp-9], 1

.L5:

movzx eax, BYTE PTR [rbp-32]

xor eax, 1

test al, al

je .L6

mov eax, DWORD PTR [rbp-8]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov edx, DWORD PTR [rax]

mov eax, DWORD PTR [rbp-8]

cdqe

add rax, 1

lea rcx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rcx

mov eax, DWORD PTR [rax]

cmp edx, eax

jge .L6

mov eax, DWORD PTR [rbp-8]

cdqe

add rax, 1

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rdx, rax

mov eax, DWORD PTR [rbp-8]

cdqe

lea rcx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rcx

mov rsi, rdx

mov rdi, rax

call swap(int*, int*)

mov BYTE PTR [rbp-9], 1

.L6:

add DWORD PTR [rbp-8], 1

jmp .L7

.L4:

movzx eax, BYTE PTR [rbp-9]

xor eax, 1

test al, al

jne .L12

add DWORD PTR [rbp-4], 1

jmp .L9

.L12:

nop

.L11:

nop

leave

ret

findElement(int*, int, int):

push rbp

mov rbp, rsp

mov QWORD PTR [rbp-24], rdi

mov DWORD PTR [rbp-28], esi

mov DWORD PTR [rbp-32], edx

mov BYTE PTR [rbp-5], 0

mov DWORD PTR [rbp-4], 0

.L16:

mov eax, DWORD PTR [rbp-4]

cmp eax, DWORD PTR [rbp-32]

jge .L14

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

cmp DWORD PTR [rbp-28], eax

jne .L15

mov BYTE PTR [rbp-5], 1

.L15:

add DWORD PTR [rbp-4], 1

jmp .L16

.L14:

cmp BYTE PTR [rbp-5], 0

je .L17

mov eax, DWORD PTR [rbp-4]

jmp .L18

.L17:

mov eax, -1

.L18:

pop rbp

ret

avgAllElement(int*, int):

push rbp

mov rbp, rsp

mov QWORD PTR [rbp-24], rdi

mov DWORD PTR [rbp-28], esi

mov DWORD PTR [rbp-8], 0

mov DWORD PTR [rbp-4], 0

.L21:

mov eax, DWORD PTR [rbp-4]

cmp eax, DWORD PTR [rbp-28]

jge .L20

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

add DWORD PTR [rbp-8], eax

add DWORD PTR [rbp-4], 1

jmp .L21

.L20:

mov eax, DWORD PTR [rbp-8]

cdq

idiv DWORD PTR [rbp-28]

cvtsi2ss xmm0, eax

pop rbp

ret

maxElement(int*, int):

push rbp

mov rbp, rsp

mov QWORD PTR [rbp-24], rdi

mov DWORD PTR [rbp-28], esi

mov DWORD PTR [rbp-8], -2147483648

mov DWORD PTR [rbp-4], 0

.L26:

mov eax, DWORD PTR [rbp-4]

cmp eax, DWORD PTR [rbp-28]

jge .L24

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

cmp DWORD PTR [rbp-8], eax

jge .L25

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

mov DWORD PTR [rbp-8], eax

.L25:

add DWORD PTR [rbp-4], 1

jmp .L26

.L24:

mov eax, DWORD PTR [rbp-8]

pop rbp

ret

minElement(int*, int):

push rbp

mov rbp, rsp

mov QWORD PTR [rbp-24], rdi

mov DWORD PTR [rbp-28], esi

mov DWORD PTR [rbp-8], 2147483647

mov DWORD PTR [rbp-4], 0

.L31:

mov eax, DWORD PTR [rbp-4]

cmp eax, DWORD PTR [rbp-28]

jge .L29

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

cmp DWORD PTR [rbp-8], eax

jle .L30

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

mov DWORD PTR [rbp-8], eax

.L30:

add DWORD PTR [rbp-4], 1

jmp .L31

.L29:

mov eax, DWORD PTR [rbp-8]

pop rbp

ret

.LC0:

.string "%d "

printArray(int*, int):

push rbp

mov rbp, rsp

sub rsp, 32

mov QWORD PTR [rbp-24], rdi

mov DWORD PTR [rbp-28], esi

mov DWORD PTR [rbp-4], 0

.L35:

mov eax, DWORD PTR [rbp-4]

cmp eax, DWORD PTR [rbp-28]

jge .L34

mov eax, DWORD PTR [rbp-4]

cdqe

lea rdx, [0+rax*4]

mov rax, QWORD PTR [rbp-24]

add rax, rdx

mov eax, DWORD PTR [rax]

mov esi, eax

mov edi, OFFSET FLAT:.LC0

mov eax, 0

call printf

add DWORD PTR [rbp-4], 1

jmp .L35

.L34:

mov edi, 110

call putchar

nop

leave

ret

.LC1:

.string "1 - Bubble Sort Ascending"

.LC2:

.string " 2 - Bubble Sort Descending"

.LC3:

.string " 3 - Find Max Value"

.LC4:

.string " 4 - Find Min Value"

.LC5:

.string " 5 - Find Average of Values"

.LC6:

.string " 6 - Find a value in array"

.LC7:

.string " 7 - Quit the program"

.LC8:

.string " Enter a selection: "

.LC9:

.string "%d"

get_menu_choice():

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], 0

.L39:

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC2

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC3

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC4

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC5

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC6

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC7

mov eax, 0

call printf

mov edi, OFFSET FLAT:.LC8

mov eax, 0

call printf

lea rax, [rbp-4]

mov rsi, rax

mov edi, OFFSET FLAT:.LC9

mov eax, 0

call scanf

mov eax, DWORD PTR [rbp-4]

test eax, eax

jle .L39

mov eax, DWORD PTR [rbp-4]

cmp eax, 7

jle .L38

jmp .L39

.L38:

mov eax, DWORD PTR [rbp-4]

leave

ret

.LC10:

.string "Sorted array: "

main:

push rbp

mov rbp, rsp

sub rsp, 48

mov DWORD PTR [rbp-48], 64

mov DWORD PTR [rbp-44], 34

mov DWORD PTR [rbp-40], 25

mov DWORD PTR [rbp-36], 12

mov DWORD PTR [rbp-32], 22

mov DWORD PTR [rbp-28], 11

mov DWORD PTR [rbp-24], 90

mov DWORD PTR [rbp-4], 7

call get_menu_choice()

mov DWORD PTR [rbp-8], eax

cmp DWORD PTR [rbp-8], 6

ja .L42

mov eax, DWORD PTR [rbp-8]

mov rax, QWORD PTR .L44[0+rax*8]

jmp rax

.L44:

.quad .L42

.quad .L49

.quad .L48

.quad .L47

.quad .L46

.quad .L45

.quad .L43

.L49:

mov ecx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov edx, 0

mov esi, ecx

mov rdi, rax

call bubbleSort(int*, int, bool)

.L48:

mov ecx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov edx, 1

mov esi, ecx

mov rdi, rax

call bubbleSort(int*, int, bool)

.L47:

mov edx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov esi, edx

mov rdi, rax

call maxElement(int*, int)

.L46:

mov edx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov esi, edx

mov rdi, rax

call minElement(int*, int)

.L45:

mov edx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov esi, edx

mov rdi, rax

call avgAllElement(int*, int)

.L43:

mov edx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov esi, 25

mov rdi, rax

call findElement(int*, int, int)

.L42:

mov edi, OFFSET FLAT:.LC10

call puts

mov edx, DWORD PTR [rbp-4]

lea rax, [rbp-48]

mov esi, edx

mov rdi, rax

call printArray(int*, int)

mov eax, 0

leave

ret

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