Well if you've looked on the board earlier you saw me struggling to make it sort Lastnames, Well I got it to sort lastnames, I wonder if anyone like to help me make it sort Last and First Names.
Namesort.asm is an assembly procedure for a Visual C++ program
the structure it's using is this

struct names {

char lastname[16];
char firstname[12];
int age;
};


I have included my files, too if anybody wants to play with it,
but maybe someone has an better idea with macros
The C++ file has it's file named to NameSortCGI.txt
And you also need the two ASM file Namesort.asm and PointerStructs.asm below too
There also more instructions on how to set these files up in the
Sorting samples I've posted in Algorithms.

Thanks Andy

:)
Posted on 2001-12-26 18:57:45 by andy981
Here is attachment Namesort.asm and it sorts now
Posted on 2001-12-26 19:00:17 by andy981
Here is attachment PointersStruct.asm
Posted on 2001-12-26 19:02:32 by andy981
.386
.MODEL flat, C

;C function
EXTERN malloc:NEAR
EXTERN free:NEAR
EXTERN strcmp:NEAR
EXTERN printf:NEAR

.DATA
formatd db "%d",0
format1 db "%s",0
format2 db "%s",0
.CODE
NameSort PROC proc C Arr:DWORD,count:DWORD

LOCAL First :DWORD
LOCAL Last :DWORD
LOCAL cntr :DWORD
LOCAL bLen :DWORD
LOCAL hMem :DWORD
LOCAL temp :DWORD

push ebx
push esi
push edi

mov cntr, 0

mov esi,Arr ; source address in ESI

; --------------------------
; allocate temporary buffer
; --------------------------
mov eax, count

mov eax, 10
add eax, 40
mov bLen, eax
;invoke SysAllocStringByteLen,0,bLen

push bLen
call malloc
mov hMem, eax

mov edi, hMem ; buffer address in EDI

; ------------------------------------
; set First and Last reference values
; ------------------------------------
mov First, 0
mov eax, count
dec eax
mov Last, eax ; Last = count - 1

outer_loop:
; -------------------
; calculate midpoint
; -------------------
mov eax, Last
add eax, First
shr eax, 1
; =========================
mov ebx, ; midpoint in EBX
mov temp, ebx



; =========================
mov ecx, First
mov edx, Last
; ---------------------------------------------------------
inner_loop:
push ebx
push ecx
push edx
mov eax,ebx
push eax
mov eax,
push eax
call strcmp
pop ebx
pop ebx
pop edx
pop ecx
pop ebx




;cmp , ebx

;jge wl2
cmp eax,0
jge wl2

inc ecx
jmp inner_loop
wl2:

push ebx
push ecx
push edx
mov eax,
push eax
mov eax,ebx
push eax
call strcmp
pop ebx
pop ebx
pop edx
pop ecx
pop ebx

;cmp , ebx
;cmp eax,0
;jle wl2Out
cmp eax,0
jge wl2Out
dec edx
jmp wl2
wl2Out:

;mov edx,eedx
;mov ecx,eecx
cmp ecx, edx ; If ecx > edx, exit inner loop
jg exit_innerx
; =========================
mov eax,
mov ebx, ; swap elements
mov , ebx
mov , eax
; =========================
mov ebx, temp ; restore EBX
inc ecx
dec edx
cmp ecx, edx
jle inner_loop
exit_innerx:
; ---------------------------------------------------------
cmp ecx, Last ; If ecx < Last jump over
jg iNxt

; =========================
mov eax, cntr
mov , ecx
mov ebx, Last
mov , ebx
; =========================
add cntr, 2
iNxt:
mov ebx, temp ; restore EBX
mov Last, edx ; Last = EDX
cmp edx, First ; compare Last & First
jg outer_loop

cmp cntr, 0
jz qsOut
sub cntr, 2
; =========================

mov eax, cntr
mov ebx,
mov First, ebx
mov ebx,
mov Last, ebx
; =========================
mov ebx, temp ; restore EBX
jmp outer_loop

qsOut:

;invoke SysFreeString,hMem
push hMem
call free
pop edi
pop esi
pop ebx
ret
NameSort ENDP
END


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Output is

Zimmer Frank 56 1244084
Anderson George 45 1244116
Bonker George 23 1244148
Kowaski Jimmy 47 1244180
Zoogle Tommy 31 1244212
Dutch Andy 33 1244244
Clark Vince 63 1244276
Gagnon Frank ? 1244308
Dobbs Denise ? 1244340
Madison George ? 1244372
Kenedy Jimmy ? 1244404
Tucker Tommy ? 1244436
Foster Andy ? 1244468
Madison Oscar ? 1244500
Gozalez Arnold ? 1244532



Anderson George 45 1244116
Bonker George 23 1244148
Clark Vince 63 1244276
Dobbs Denise ? 1244340
Dutch Andy 33 1244244
Foster Andy ? 1244468
Gagnon Frank ? 1244308
Gozalez Arnold ? 1244532
Kenedy Jimmy ? 1244404
Kowaski Jimmy 47 1244180
Madison Oscar ? 1244500
Madison George ? 1244372
Tucker Tommy ? 1244436
Zimmer Frank 56 1244084
Zoogle Tommy 31 1244212
Press any key to continue
Posted on 2001-12-26 21:37:03 by andy981