News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

part Sort in code not work help please

Started by master, January 03, 2010, 09:16:16 PM

Previous topic - Next topic

master

.data
Msg1 db "Enter Number n=" ,0
Msg2 db "Write Number (%d)=" ,0
Msg3 db "Number (%d)=" ,0
EndLine db 13,10 ,0


.data?
temp db 100 dup(?)
array dq 100 dup(?)
n dd ?
a dd ?
f1 dq ?
f2 dq ?
f3 dq ?


.code
ReadNumber Macro n1 ,f ,Msg ,t ,e

pushad
invoke wsprintf ,addr t ,addr Msg ,n1
invoke StdOut ,addr t
invoke StdIn ,addr t ,100
invoke StrToFloat ,addr t ,addr f
;invoke StdOut ,addr e
popad
endm


start:


invoke StdOut ,addr Msg1
invoke StdIn ,addr temp ,100
invoke atol ,addr temp
mov n ,eax

mov ecx ,n
mov eax ,1
L1:
mov ebx ,eax
dec ebx
mov a ,eax
push ecx
push eax
ReadNumber a ,f1 ,Msg2 ,temp ,EndLine
pop eax
pop ecx
fld f1
fstp array[ebx*8]
inc eax
loop L1

invoke StdOut ,addr EndLine



mov ebx ,0
L4:
mov ecx ,ebx
inc ecx
L3:
fld array[ebx*8]
fstp f1
fld array[ecx*8]
fst f2





fcom f1
fstsw ax
sahf
jnc L2






fld f2
fstp array[ebx*8]
fld f1
fstp array[ecx*8]


L2:
inc ecx
cmp ecx ,n
jl L3
inc ebx
mov eax ,n
dec eax
cmp ebx ,eax
jl L4



mov eax ,0
L5:
mov ebx ,eax
inc ebx
fld array[eax*8]
fstp f1
push eax
invoke wsprintf ,addr temp ,addr Msg3 ,ebx
invoke StdOut ,addr temp
invoke FloatToStr ,f1 ,addr temp
invoke StdOut ,addr temp
invoke StdOut ,addr EndLine
pop eax
inc eax
cmp eax ,n
jl L5


invoke ExitProcess ,0
end start

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

master

bubble sort Or algorithms Another
Algorithm is done properly (it seems), but floating point numbers will not print properly
I wrote a program for the sinus angle 0 to 90 degrees, but floating point numbers will not be true
Why output floating point numbers are these?


dedndave

fld array[eax*8]
fstp f1

you are addressing qwords

invoke FloatToStr ,f1 ,addr temp

not sure how FloatToStr works
maybe you need to pass the 2 dwords, or the addess of f1

you may want to use "real8" instead of "dq" to define them
that helps the assembler know what you are passing in and out of the FPU

master

Thankful dedndave

I just do everything I found
Scale may explain more?

dedndave

i see you are having more trouble with English than you are with assembly language - lol - that's ok
try to show us what you are getting and what you want to get - maybe we can work it from there

master

yes I'm Iranian and Persian language
I'm using Google Translation
I apologize if you write bad

Our teacher training is
Practice Description:
Taking integer number n of output
Taking  floating point number of output(Total n)
Sort them
Print sorted numbers