list REAL8 100 dup(0.0); list of numbers, size = 8 bytes
;***** This is supposed to be an array of REAL8
len DWORD LENGTHOF list ; size of list
lenMult DWORD ?
number DWORD ?
ptrArray DWORD list
InsertionSort PROTO arr:PTR DWORD
.code
main PROC
movesi,OFFSET list
moveax,0
;Populate Array With 100 Random Numbers
xorebx,ebx; initialize counter to 0
;mov edi, [len] ;put length in register for comparison if not a constant
movedx,OFFSET list ;Move what's pointing to list into edx
call fill
call print
invoke INSERTIONSORT, OFFSET list
call print
xorebx,ebx
call DumpRegs
call WaitMsg
exit
main ENDP
; PLACE ADDITIONAL PROCEDURES HERE
fill PROC uses edxebxeax
loophead:
call Random32
mov number,eax
fld number
fstp REAL8 PTR[edx+ebx*TYPE REAL8]
incebx
cmpebx,len ; compare with array length
jnz loophead
ret
fill ENDP
print PROC uses ebxedx
print_start:
fld REAL8 PTR[edx+ebx*TYPE REAL8]
call WriteFloat
call CrLF
fstp REAL8 PTR[edx+ebx*TYPE REAL8]
incebx
cmpebx, len
jnz print_start
ret
print ENDP
INSERTIONSORT PROC USES eaxecxesi, arr:PTR DWORD
; fld REAL8 PTR[edx+ebx*TYPE REAL8]
;fstp REAL8 PTR[edx+ebx*TYPE REAL8]
movecx,1;sort initializes counter at 1
moveax,0
Outer_loop:
pushecx
movecx,100
movesi, arr
Inner_Loop:
moveax,[esi]
FCOMPI [esi+TYPE REAL8],eax
jae Inner_Loop_2
xchgeax,[esi+TYPE REAL8];Works for 32 bits
mov[esi],eax;
Inner_Loop_2:
addesi,TYPE REAL8
loop Inner_Loop
popecx;clear memory
loop Outer_loop
Loop_End:
ret
INSERTIONSORT ENDP
END main
;***** Will not work on REAL8. And why did you make it worse by using a WORD? It is only 2 bytes long instead of 8.
;***** I said this morning that you cannot ues CMP. You should be using FCOMPI. And you need to use UNSIGNED branch instructions. Not a signed branch
;***** li;***** I said this morning that you cannot use CMP. You should be using FCOMPI. And you need to use UNSIGNED branch instructions. Not a signed branch