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

Implement in ARM assembly language for sorting with a linkedlist. In the main fu

ID: 3824961 • Letter: I

Question

Implement in ARM assembly language for sorting with a linkedlist. In the main function, open a file to read a sequence of unsorted integers. For the first input integer, create a root node (8 bytes), holding the integer and one empty pointer. For each of the following input integers, build a link (call it X) containing the number and insert it to the linked list such that for any link with smaller integer should go before X and any link with integer of bigger or equal value should go after X. After all integers are inserted, the program would traverse the linked list and print out the sorted integers separated by space onto the screen. Specification: you should write Insert as a recursive function.

Explanation / Answer

//data to be sorted
Data Segment
arr1 db 8,2,7,4,3
Data Ends

Code Segment
Assume cs:code, ds:data

Begin:
mov ax, data   //move data to ax register
mov ds, ax       //copy content of ax to d and es
mov es, ax
mov bx, OFFSET arr1
mov cx, 5
mov dx, cx
L1:
mov si, 0
mov ax, si
inc ax
mov di, ax
mov dx, cx
L2:
mov al, [bx][si]
cmp al, [bx][di]
jg L4
L3:               //logic for placing left or right
inc si
inc di
dec dx
cmp dx, 00
je L1
jg L2
L4:
mov al, [bx][si]
mov ah, [bx][di]
mov [bx][si], ah
mov [bx][di], al
inc si
inc di   
dec dx
cmp dx, 00
je L1
jg L2
Exit:
mov ax, 4c00h
int 21h
Code Ends
End Begin

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