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

Write a program in MIPS assembly language that asks the users to enter a value f

ID: 3587579 • Letter: W

Question

Write a program in MIPS assembly language that asks the users to enter a value for array size “n” and fill up the array with n integers. Then reverse the array and print it on the screen. You are required to do the following in your program:

Create up to 80 bytes of space in your program

“n”, the array size, should be greater than zero and less than 20

Each element of the array should be positive and divisible by 3

Array should be reversed within itself. i.e. you must not create another array to place the elements in reverse order

Explanation / Answer

.LC0:

.string "Enter array size (1 -20 ) : "

.LC1:

.string "%d"

.LC2:

.string "Reverse Array Elements"

.LC3:

.string "%d "

main:

push rbp

mov rbp, rsp

sub rsp, 96

mov edi, OFFSET FLAT:.LC0

call puts

lea rax, [rbp-16]

mov rsi, rax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call scanf

mov DWORD PTR [rbp-4], 0

.L3:

mov eax, DWORD PTR [rbp-16]

cmp DWORD PTR [rbp-4], eax

jge .L2

lea rax, [rbp-96]

mov edx, DWORD PTR [rbp-4]

movsx rdx, edx

sal rdx, 2

add rax, rdx

mov rsi, rax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call scanf

add DWORD PTR [rbp-4], 1

jmp .L3

.L2:

mov DWORD PTR [rbp-4], 0

mov eax, DWORD PTR [rbp-16]

sub eax, 1

mov DWORD PTR [rbp-8], eax

.L5:

mov eax, DWORD PTR [rbp-4]

cmp eax, DWORD PTR [rbp-8]

jge .L4

mov eax, DWORD PTR [rbp-4]

cdqe

mov eax, DWORD PTR [rbp-96+rax*4]

mov DWORD PTR [rbp-12], eax

mov eax, DWORD PTR [rbp-8]

cdqe

mov edx, DWORD PTR [rbp-96+rax*4]

mov eax, DWORD PTR [rbp-4]

cdqe

mov DWORD PTR [rbp-96+rax*4], edx

mov eax, DWORD PTR [rbp-8]

cdqe

mov edx, DWORD PTR [rbp-12]

mov DWORD PTR [rbp-96+rax*4], edx

add DWORD PTR [rbp-4], 1

sub DWORD PTR [rbp-8], 1

jmp .L5

.L4:

mov edi, OFFSET FLAT:.LC2

call puts

mov DWORD PTR [rbp-4], 0

.L7:

mov eax, DWORD PTR [rbp-16]

cmp DWORD PTR [rbp-4], eax

jge .L6

mov eax, DWORD PTR [rbp-4]

cdqe

mov eax, DWORD PTR [rbp-96+rax*4]

mov esi, eax

mov edi, OFFSET FLAT:.LC3

mov eax, 0

call printf

add DWORD PTR [rbp-4], 1

jmp .L7

.L6:

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