;; (C) David Vajda ;; Sat Dec 28 2024 ;; Assembler, nasm, x86/i386/amd64/i586, Sort global _start section .data toSortString: db "28312931932193281932123", 10, 13 toSortStringLen: dw 0 section .text _start: mov esi, toSortString toSortLoopOuter: mov ah, [esi] cmp ah, 10 je toSortLoopOuterEnd mov edi, esi toSortLoopInner: inc edi mov al, [edi] cmp al, 10 je toSortLoopInnerEnd mov ah, [esi] mov al, [edi] cmp ah, al jle NoExChange mov ah, [esi] mov al, [edi] mov [esi], al mov [edi], ah NoExChange: jmp toSortLoopInner toSortLoopInnerEnd: inc esi jmp toSortLoopOuter toSortLoopOuterEnd: mov esi, toSortString mov ecx, 0 count: mov ah, [esi] cmp ah, 10 je countend inc ecx inc esi jmp count countend: mov edx, ecx inc edx inc edx mov ecx, toSortString mov eax, 0x04 mov ebx, 0x01 int 0x80 mov eax, 0x01 mov ebx, 0x00 int 0x80 |
david@work:~/nasm20241228$ ./nasm20241228sort001 11111222222333333889999 david@work:~/nasm20241228$ |