0

New to assembly here. I am playing with implementation of different sorting algorithms, specifically bubble and insertion sort. The following code takes user input (10 integers) and stores that input in an array. How would I sort this data using the above mentioned sort types. I am familiar with the logic just not the implementation in assembly. FYI I am working in Visual Studio 2017.

.586
.MODEL FLAT

INCLUDE io.h

.STACK 4096

.DATA
user_array  DWORD 10 DUP (?)
nbrElts     DWORD 10

welcomeLbl BYTE "Array Bubble Sorting Program ", 0
wel_message BYTE "Please enter 10 unique integers", 0
prompt1 BYTE    "Please enter a number: ", 0
string  BYTE    40 DUP (?)

array_contentLbl BYTE "The values you entered: ", 0
array_val DWORD ?, 0ah, 0dh

resultLbl BYTE "Program will now sort the numbers", 0
waitMsg   BYTE "Please wait.....",0

.CODE

_MainProc PROC
output welcomeLbl, wel_message
lea ebx, user_array
mov ecx, nbrElts

forCount1:
    input   prompt1, string, 40     ; prompt user for a number
    atod    string                  ;convert to integer
    mov [ebx], eax
    add ebx, 4
    loop forCount1

lea ebx, user_array             ;ptr to array, index 0
mov ecx, nbrElts                ;move counter to ecx for loop

output resultLbl, waitMsg
;call bubble_sort

forCount2:                  ;loop to output array contents
    mov eax, [ebx]
    mov array_val, eax
    dtoa array_val, eax
    output array_contentLbl, array_val      
    add ebx, 4
    loop forCount2

quit:       mov eax, 0          ;clear memory
                mov ebx, 0
                mov ecx, 0
                mov edx, 0
    ret
_MainProc ENDP

;bubble_sort PROC

;bubble_sort ENDP

END
Chris Snook
  • 19
  • 1
  • 6
  • related: [Code-golfed bubblesort (19 bytes of x86 machine code)](https://codegolf.stackexchange.com/questions/77836/sort-an-integer-list/149038#149038). Porting it to sort 32-bit integers in 32-bit mode should be pretty easy, just use a temporary register for the swapping instead of a memory-destination rotate. An earlier version of the answer has an x86-64 version that sorts 32-bit integers with proper Bubble Sort: https://codegolf.stackexchange.com/revisions/149038/5. Of course these are not good examples of how to write asm because they're optimized for size at the expense of everything. – Peter Cordes Nov 28 '17 at 07:36
  • Not sure how that helps me. I wrote it in C and used VS dissassembler to get ASM but that seems like a cheap workaround. How can I implement this in win32 format – Chris Snook Nov 28 '17 at 22:06
  • Are you asking about the linked duplicate? It's a nice normal implementation of Bubble Sort in 32-bit x86 asm, MASM syntax. If you want something to copy/paste, use that (but replace the hard-coded size with a register). – Peter Cordes Nov 28 '17 at 23:56

0 Answers0