flat assembler
Message board for the users of flat assembler.

Index > Windows > 32 bit code to 64 bit code

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 17 Oct 2013, 14:58
I have this code in a 32 bit program and it runs fine. when I put this code into a 64 bit program it gives me 0.0000 for the measurement instead of whatever like 39.6704

Code:
macro calculateresultlengthX {

;calculate result length x

;formula is resultlengthX = resultlengthXpixelstextbox / MeasuredlengthXpixelstextbox * MeasuredlengthXtextbox

;read in resultlengthXinpixelstextbox

invoke GetDlgItemTextA, [hwnd], resultlengthxpixelstextbox, bufferbuffer1, 100
cinvoke sscanf, bufferbuffer1, "%f", buffer1 

;read in MeasuredlengthXinpixelstextbox

invoke GetDlgItemTextA, [hwnd], measuredlengthxpixelstextbox, bufferbuffer2, 100
cinvoke sscanf, bufferbuffer2, "%f", buffer2

;resultlengthXpixels / MeasuredlengthXpixels

finit
fld dword [buffer1]
fld dword [buffer2] 
fdivp
fstp qword [buffer3]  

cinvoke sprintf, addr buffer1, "%.16lf", dword [buffer3], dword [buffer3 + 4]
invoke SetDlgItemTextA,[hwnd],resultlengthxtextbox,addr buffer1

;read in ResultlengthXtextbox to get the temporary value

invoke GetDlgItemTextA, [hwnd],resultlengthxtextbox, bufferbuffer1, 100
cinvoke sscanf, bufferbuffer1, "%f", buffer1

;read in MeasuredlengthXtextbox

invoke GetDlgItemTextA, [hwnd],measuredlengthxtextbox, bufferbuffer2, 100
cinvoke sscanf, bufferbuffer2, "%f", buffer2

;answer * MeasuredlengthXtextbox

finit
fld dword [buffer1]
fld dword [buffer2] 
fmulp
fstp qword [buffer3]  

cinvoke sprintf, addr buffer1, "%.16lf", dword [buffer3], dword [buffer3 + 4]
invoke SetDlgItemTextA,[hwnd],resultlengthxtextbox,addr buffer1

}
    


can someone show me how to convert this code to 64 bit.

thanks
Post 17 Oct 2013, 14:58
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 17 Oct 2013, 18:15
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:44; edited 1 time in total
Post 17 Oct 2013, 18:15
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1657
Location: Toronto, Canada
AsmGuru62 17 Oct 2013, 18:39
Post 17 Oct 2013, 18:39
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 17 Oct 2013, 18:48
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:44; edited 1 time in total
Post 17 Oct 2013, 18:48
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 17 Oct 2013, 22:02
thanks guys

I looked at the link AsmGuru62 gave
http://msdn.microsoft.com/en-us/library/ms235286.aspx

so I then looked at tutorials for SSE and I found this

http://neilkemp.us/src/sse_tutorial/sse_tutorial.html#C

so then I tried a simple test to see if I could divide numbers using SSE

Code:
mov [buffer1],20
mov [buffer2],2
mov rax,[buffer1]
mov rbx,[buffer2]
MOVUPS XMM0, [RAX]
MOVUPS XMM1, [RBX]
DIVPS XMM0, XMM1
MOVUPS dqword[buffer1], XMM0
    


but the code crashes my exe. I determined that the crash happens on the
MOVUPS XMM0, [RAX] line

so is their something I need to enable to use SSE?
can someone please show me some code, because I still dont get how to convert my code to 64 bit
Post 17 Oct 2013, 22:02
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 17 Oct 2013, 23:20
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:43; edited 1 time in total
Post 17 Oct 2013, 23:20
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 18 Oct 2013, 14:19
ok so I changed the code like you said HaHaAnonymous and it does not crash anymore.

the result should be 10 (20/2)

It now will give me a result in the textbox but it is always the same number like 4251078

I know this is just a formatting problem so how can I format the result.

this is what I have tried

Code:
mov [buffer1],20
      mov [buffer2],2
      mov rax,buffer1
      mov rbx,buffer2
      MOVUPS XMM0, [RAX]
      MOVUPS XMM1, [RBX]
      DIVPS XMM0, XMM1
      MOVUPS dqword[buffer1], XMM0
      cinvoke wsprintfA,addr buffer5,"%u",buffer1
     invoke SetDlgItemTextA,[hwnd],unitofmeasurementtextbox,addr buffer5
    


this gave me the 4251078

and

Code:
mov [buffer1],20
      mov [buffer2],2
      mov rax,buffer1
      mov rbx,buffer2
      MOVUPS XMM0, [RAX]
      MOVUPS XMM1, [RBX]       
      DIVPS XMM0, XMM1
      MOVUPS dqword[buffer1], XMM0
     cinvoke sprintf, addr buffer2, "%.16lf", dword [buffer1], dword [buffer1 + 4]
invoke SetDlgItemTextA,[hwnd],resultlengthxtextbox,addr buffer2
    


gave me still 0.00000000

if possible I would rather use the scanf because I can set the precision of the result

thanks
Post 18 Oct 2013, 14:19
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 18 Oct 2013, 15:52
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:43; edited 1 time in total
Post 18 Oct 2013, 15:52
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 18 Oct 2013, 16:04
I was just using the 20 and 2 for example.

this is what I want to do.

their is 3 textboxes one has always a whole number like 512 or 680
one has always a whole number like 512 or 680
one has a user defined measurement that could be a whole number or a decimal like 2 or 2.23

my 32 bit application read both of the whole number values in to buffers then called sscanf on them with the %f format. then it divided them using the fpu and put the result in a buffer. then it took the answer and multiplied it by the third textbox that contains a whole number or decimal and wrote the new answer to the answer textbox

an example would be like this 200/87*2.32 = answer in answer textbox

that is what I want to do with sse and 64 bit

so how can I do that

I also tried this but now it crashes again

mov rax,20.0
mov rbx,2.0
MOVupsXMM0, [RAX]
and
mov rax,20.0
mov rbx,2.0
MOVss XMM0, [RAX]
and
mov rax,20.0
mov rbx,2.0
MOVsd XMM0, [RAX]

all make it crash
Post 18 Oct 2013, 16:04
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 18 Oct 2013, 16:18
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:43; edited 1 time in total
Post 18 Oct 2013, 16:18
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 18 Oct 2013, 16:36
thanks for that. I am pretty sure it is now dividing and storing the correct value in xmm0 but the problem is how do I format xmm0 so that the user can see the real result, because it still shows a fake number like 4540154 or 0.000000
Post 18 Oct 2013, 16:36
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 18 Oct 2013, 19:07
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:43; edited 1 time in total
Post 18 Oct 2013, 19:07
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 19 Oct 2013, 00:24
does anyone know of a way how to use sprintf in 64 bit or how to format the number in just assembly

this is the line I use in 32 bit

Code:
cinvoke sprintf, addr buffer2, "%.16lf", dword [buffer1], dword [buffer1 + 4]
    


buffer1 has the number and buffer2 is empty and it gets the formatted number
Post 19 Oct 2013, 00:24
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 19 Oct 2013, 01:19
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:42; edited 1 time in total
Post 19 Oct 2013, 01:19
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 19 Oct 2013, 16:21
first off thanks for all the help

okay this is the code I am running now

Code:
 mov dword[buffer1],20.0
mov dword[buffer2],2.0
mov rax,buffer1 
mov rbx,buffer2
MOVUPS XMM0, [RAX]
MOVUPS XMM1, [RBX]
      DIVsd XMM0, XMM1
      MOVUPS dqword[buffer2], XMM0
      lea      rdi,[buffer2]
; format = "%lf"
mov      rsi,"%lf"
mov      rdx,rdi
invoke  MessageBoxA,[hwnd],abouttext,title,MB_OK
call     qword [sprintf]
invoke SetDlgItemTextA,[hwnd],resultlengthxtextbox,addr buffer2
    


for some reason if I remove the message box(which is what I want) it crashes when it calls sprintf
If I leave the message box in it gives me a number but in the Unicode format like -yy?

although it is giving different symbols for different calcs so it is probably working just not displaying them in a readable way.

how can I get it to show me 20.0/2.0 = 10.0 instead of -yy?
Post 19 Oct 2013, 16:21
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 19 Oct 2013, 17:09
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:42; edited 1 time in total
Post 19 Oct 2013, 17:09
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 19 Oct 2013, 17:34
I typed in the exact code you gave me and it gives me an empty textbox. I even pasted the code in a new template project and it is still a empty textbox

I think the problem is do I have to move the xmm0 into a buffer after the divss?

this is the line right after the divss code I was using before
Code:
MOVUPS dqword[buffer2], XMM0 
    


also dont the buffers have to be dq instead of dd because they are in a 64 bit program?

also you change the mov rdx,rdi line with xor rdx,rdx

when I change this 1 line in the above code I posted that gives me -yy?

if I use mov rdx,rdi it crashes
if I use xor rdx,rdx it does not crash but the textbox is empty
if I use mov rdx,rdi with messagebox it gives me -yy?

thanks
Post 19 Oct 2013, 17:34
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 19 Oct 2013, 21:45
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:41; edited 3 times in total
Post 19 Oct 2013, 21:45
View user's profile Send private message Reply with quote
patchariadog



Joined: 24 Mar 2013
Posts: 94
patchariadog 20 Oct 2013, 00:03
I also got this

Code:

 invoke GetDlgItemTextA, [hwnd], resultlengthypixelstextbox, bufferbufferf1, 100
cinvoke sscanf, bufferbufferf1, "%f", bufferf1

;read in MeasuredlengthYinpixelstextbox

invoke GetDlgItemTextA, [hwnd], measuredlengthypixelstextbox, bufferbufferf2, 100
cinvoke sscanf, bufferbufferf2, "%f", bufferf2

;resultlengthYpixels / MeasuredlengthYpixels

finit
fild qword [bufferf1]
fild qword [bufferf2]
fdivp
fstp qword [bufferf3]

cinvoke sprintf, addr bufferf1, "%.16lf", qword [bufferf3], qword [bufferf3+8]
invoke SetDlgItemTextA,[hwnd],resultlengthytextbox,addr bufferf1

    


it give me anywhere from 0.9513214 to 1.0184798 no matter what numbers I give it

the data are all dq
Post 20 Oct 2013, 00:03
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 20 Oct 2013, 14:44
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 19:41; edited 1 time in total
Post 20 Oct 2013, 14:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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 cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.