Lulu

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

; Function to subtract each numeric digit from the largest digit

subtract_from_largest:

xor ecx, ecx ; Clear counter register

.subtract_loop:

mov al, byte [esi + ecx] ; Load digit from numeric_array

mov bl, [largest_digit] ; Load largest digit

sub bl, al ; Subtract current digit from largest digit

mov [edi + ecx], bl ; Store result in temp_array

inc ecx ; Increment counter

cmp ecx, 10 ; Check if all digits processed

je .subtract_done ; If all digits processed, exit loop

jmp .subtract_loop

.subtract_done:

ret

; Function to sort array in ascending order (using Bubble Sort)

sort_array:

xor ecx, ecx ; Outer loop counter

.outer_loop:

xor edx, edx ; Inner loop counter

.inner_loop:

mov al, [esi + edx] ; Load current element

cmp al, [esi + edx + 1] ; Compare with next element

jle .no_swap ; If less than or equal, no swap needed

mov bl, [esi + edx + 1] ; Exchange elements


mov [esi + edx + 1], al

mov [esi + edx], bl

.no_swap:

You might also like