sorting - Assembly Programming (I'm a Beginner) Bubble Sort -


i need make bubble sort in assembly, don't understand why keeps breaking exception error. i'm using visual studios debug. right now, don't understand base pointers well

        .586         .model flat          include io.h          .stack 4096          .data          example_data byte 1,3,4,5,2,5,7,4,6,0         num_of_elements byte 10         prompt1 byte "numbers",0          .code         _mainproc proc             mov eax, dword ptr[num_of_elements] ;whatever programmer entered             dec eax                             ;less 1 (since 10 elements = 0-9)             mov dword ptr[num_of_elements], eax ;save new value              lea eax, example_data               ;point eax start addr             xor ebx, ebx                        ;reset (data reg 1)             xor edx, edx                        ;reset (data reg 2)             xor ecx, ecx                        ;reset counter          stillsort:             mov bl, byte ptr[eax]               ;get 1 byte             mov dl, byte ptr[eax+1]             ;and byte right             cmp bl, dl                          ;compare 2             jg notdone                          ;if byte 2 > byte 1, not sorted, go sort             push eax                            ;save             push ecx                            ;save counter             lea eax, example_data               ;go start (for test)             xor ecx, ecx                        ;reset counter             jmp test_sorted                     ;go test whole list          notdone:             mov byte ptr[eax], dl               ;put byte 2 in byte 1 position             mov byte ptr[eax+1], bl             ;put byte 1 in byte 2 position             inc eax                             ;go next byte             inc ecx                             ;count             cmp ecx, dword ptr[num_of_elements] ;10 elements (0-9)             jnz stillsort                       ;still sorting (no reset)             lea eax, example_data               ;did 10 elements, go again start             xor ecx, ecx                        ;reset counter             jmp stillsort                       ;back sort code          test_sorted:             mov bl, byte ptr[eax]               ;get 1 byte             mov dl, byte ptr[eax+1]             ;and byte right             cmp bl, dl                          ;compare             jg nope                             ;if byte 2 > byte 1 whole list isnt sorted             inc eax                             ;try next byte             inc ecx                             ;count             cmp ecx, dword ptr[num_of_elements] ;10 elements (0-9)             jz done                             ;all 10 elements sorted             jmp test_sorted                     ;or loop          nope:             pop ecx                             ;get old count             pop eax                             ;back last byte on             inc eax                             ;but 1 more             inc ecx                             ;increase counter             cmp ecx, dword ptr[num_of_elements] ;10 elements (0-9)             jnz stillsort                       ;sorting             lea eax, example_data               ;it last element, start             xor ecx, ecx                        ;reset counter             jmp stillsort                       ;sorting          done:             pop ecx                             ;clear stack             pop eax                             ;clear stack             xor eax, eax                        ;exit code 0             ret         _mainproc endp         end 


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -