flat assembler
Message board for the users of flat assembler.

Index > Heap > Merge Sort

Author
Thread Post new topic Reply to topic
Xbuffer



Joined: 14 May 2014
Posts: 2
Xbuffer
Hello! I don't know where to write =)

Can you help me with merge sort algorithm? I wrote the mergeSort in fasm and it didn't work perfectly. Therefore I clear all code and try to start again. Smile

The result:... Can you show me how simple merge sort (well, non recursive) will look in FASM?

P.S. I started learning asm a week ago (University program).
Post 14 May 2014, 16:56
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
It would be better if you submitted what you have done so far and described what parts of the code are difficult for you to understand or implement. Maybe someone would be rather enthusiastic to do your homework from A to Z for you, but I doubt.
Post 14 May 2014, 18:36
View user's profile Send private message Reply with quote
Xbuffer



Joined: 14 May 2014
Posts: 2
Xbuffer
OK. Here it is. I don't know why, but FASM create .COM file instead .EXE.

org 100h

push somedata.size
push somedata
call msort

ret


somedata: db 01h, 05h, 03h, 02h, 04h, 04h, 0FFh
somedata.size = $ - somedata

msort:
pusha
mov bp, sp

mov ax, [ bp + 10h + 02h ]
mov dx, [ bp + 10h + 04h ]

mov cx, dx
shr cx, 01h

test cx, cx
jz ms_end

push cx
push ax

push cx
push ax
call msort

sub dx, cx
add ax, cx

push dx
push ax

push dx
push ax
call msort

call merge

ms_end:
popa
ret 0004h


merge:
pusha
mov bp, sp

mov bx, [ bp + 10h + 04h ]
mov si, [ bp + 10h + 06h ]
mov cx, [ bp + 10h + 08h ]
mov bp, [ bp + 10h + 02h ]

mov di, arr

mov dx, cx
add dx, bx

add bx, bp
add cx, si

cld

m_fill:
lodsb

cmp al, [ bp ]
jb m_si

mov al, [ bp ]
dec si
inc bp

stosb
cmp bp, bx
jnz m_fill

jmp m_over

m_si:
stosb
cmp si, cx
jnz m_fill

mov si, bp
mov cx, bx

m_over:
sub cx, si
rep movsb

mov cx, dx
lea si, [ di - 01h ]
lea di, [ bx - 01h ]

std
rep movsb

popa
ret 0008h

arr:
Post 21 May 2014, 16:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.