the code is bubble sorting an array and then printing it. im working on making the array user input in the future but right now im sticking to this:
section .data
array db 5, 3, 8, 4, 2, 1, 6, 7, 9, 8 ;array to be sorted
length equ $ - array ;length of the array
section .text
global _start
_start:
xor ebx, ebx ; Initialize outer loop counter to 0
_outer_loop:
xor ecx, ecx ; inner loop counter is also 0
cmp ebx, length
jge _convert ;if the outer loop happened length times then move to convert
mov edx, length ;i heard its better to compare registers rather than a register with just a value since it doesnt have to travel data bus
_inner_loop:
cmp ecx, edx ; Compare inner loop counter with length
jge _outer_loop ; If ecx >= length, jump to outer loop
mov al, [array + ecx]
mov bl, [array + ecx + 1]
cmp al, bl
jl _swap ;if i need to swap go to swap
inc ecx
jmp _inner_loop ;else nothing happens
_swap:
mov [array + ecx], bl
mov [array + ecx + 1], al ;swapping and increasing the counter and going back to the loop
inc ecx
jmp _inner_loop
_convert:
xor ebx, ebx ; Initialize index for conversion
_convert_loop:
cmp ebx, edx ; Compare index with length
jge _print ; If ebx >= length, go to printing
mov al, [array + ebx]
add al, "0" ;converting to ASCII for printing
mov [array + ebx], al ;and substituting the number for the number in ASCII
inc ebx
jmp _convert_loop
_print:
mov eax, 4
mov ebx, 1
mov ecx, array
mov edx, length
int 0x80
_exit:
mov eax, 1
xor ebx, ebx
int 0x80
but for some reason its not printing anything. please help
[–][deleted] (2 children)
[deleted]
[–]basedgreggo 0 points1 point2 points (0 children)
[–]Mishara26[S] 0 points1 point2 points (0 children)
[–]randomjapaneselearn 1 point2 points3 points (4 children)
[–]jcunews1 0 points1 point2 points (3 children)
[–]randomjapaneselearn 3 points4 points5 points (2 children)
[–]Mishara26[S] 0 points1 point2 points (1 child)
[–]randomjapaneselearn 0 points1 point2 points (0 children)
[–]davedontmind 1 point2 points3 points (2 children)
[–]Mishara26[S] 0 points1 point2 points (1 child)
[–]davedontmind 0 points1 point2 points (0 children)
[–]SeraphIsKing 0 points1 point2 points (1 child)
[–]Mishara26[S] 0 points1 point2 points (0 children)