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

\"main asm 26 Memory allocation of Arrays must be done before the RESET and stop

ID: 3807918 • Letter: #

Question

"main asm 26 Memory allocation of Arrays must be done before the RESET and stopNDT 27 ARY1 set 0x0200 Memory allocation ARY1 28 ARY is -set 0x0210 ;Memory allocation ARYS 29 ARY2 .set 0x0220 ;Memory allocation ARY2 30 ARY2S set ex0230 ;Memory allocation AR2s 32 clr ;clearing all register being use is a good 33 clr programming practice clr R6 36 SORT1 mov. RARY1, R4 initialize R4 as a pointer to array1 mov. RARY1s, R6 initialize R4 as a pointer to arra sorted yl call Array Setupl ;then call subroutine Arraysetupl call aCOPY Copy elements from ARY1 to ARYis space Hall asORT Sort elements in ARAY1 42 SORT2 mov RARY2, R4 initialize R4 as a pointer to array2 mov.w SAARRY2S, R6 initialize R4 as a pointer to array2 sorted 43 call aArray setup2 then call subroutine ArraySetup2 ;Copy elements from ARY2 to ARY2s space call #COPY call Sort elements in ARAY2 Main loop Infinite Loop 48 Mainloop jmp 5e Array setupl mov.b a1e, e(R4) Array element initialization subroutine mov.b #17, 1(RA) First start with the number of elements mov.b R75, 2(R4) and then fill in the 10 element mov.b 67, 3(R4) 53 mov.b a23, 4(R4) mov.b a36, 5(RA) mov.b -7, 6(RA) 7(RA) mov.b 244 88 b 74, 9 (RA) 59 mov.b 18, 10(R4) 61 Array element subroutine 63 Array setup2 mov.b W10 First start with the number of element the 10 element and then fill 2(R4) nov.b a-4 mov, 23 4(R4) nov.b H-19 directory su UNC paths are not Defaulting Finished building target t lab2 out

Explanation / Answer

.LC0:
.string "Enter the number of elements to be sorted: "
.LC1:
.string "%d"
.LC2:
.string "%d. Enter element: "
.LC3:
.string "In ascending order: "
.LC4:
.string "%d "
main:
push rbp
mov rbp, rsp
sub rsp, 432
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-420]
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-420]
cmp DWORD PTR [rbp-4], eax
jge .L2
mov eax, DWORD PTR [rbp-4]
add eax, 1
mov esi, eax
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
lea rax, [rbp-416]
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-8], 0
.L8:
mov eax, DWORD PTR [rbp-420]
sub eax, 1
cmp eax, DWORD PTR [rbp-8]
jle .L4
mov DWORD PTR [rbp-4], 0
.L7:
mov eax, DWORD PTR [rbp-420]
sub eax, DWORD PTR [rbp-8]
sub eax, 1
cmp eax, DWORD PTR [rbp-4]
jle .L5
mov eax, DWORD PTR [rbp-4]
cdqe
mov edx, DWORD PTR [rbp-416+rax*4]
mov eax, DWORD PTR [rbp-4]
add eax, 1
cdqe
mov eax, DWORD PTR [rbp-416+rax*4]
cmp edx, eax
jle .L6
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-416+rax*4]
mov DWORD PTR [rbp-12], eax
mov eax, DWORD PTR [rbp-4]
add eax, 1
cdqe
mov edx, DWORD PTR [rbp-416+rax*4]
mov eax, DWORD PTR [rbp-4]
cdqe
mov DWORD PTR [rbp-416+rax*4], edx
mov eax, DWORD PTR [rbp-4]
add eax, 1
cdqe
mov edx, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-416+rax*4], edx
.L6:
add DWORD PTR [rbp-4], 1
jmp .L7
.L5:
add DWORD PTR [rbp-8], 1
jmp .L8
.L4:
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov DWORD PTR [rbp-4], 0
.L10:
mov eax, DWORD PTR [rbp-420]
cmp DWORD PTR [rbp-4], eax
jge .L9
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-416+rax*4]
mov esi, eax
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
add DWORD PTR [rbp-4], 1
jmp .L10
.L9:
mov eax, 0
leave
ret