News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

dq arrays usage

Started by Joao Batista, November 08, 2012, 09:54:46 AM

Previous topic - Next topic

Joao Batista

ok so this worked:


array dq 5 dup(1.5)
i dd 8
result dq 2.5
pos dd ?
avalue dq 0.0
sum dq 1.0

.code
start:

mov ebx,offset array
add ebx, i

FLD qword ptr [ebx]
FSTP avalue
FLD avalue
FLD sum
FADD
FSTP qword ptr[ebx]

mov ebx,offset array
add ebx, i

FLD qword ptr [ebx]
FSTP avalue
FLD avalue


FLD result
FCOM
fstsw ax
sahf
JE PRINTOK
JMP PRINTNAK



i'm still not sure if i can get i as a dd from the user (cause it may be double result from another arithmetic expression) .. so .. in case i can't .. is there a way i can use a dq as a dd ?

something like dword ptr[dqvar] ?

qWord

Quote from: Joao Batista on November 29, 2012, 11:04:40 AM(cause it may be double result from another arithmetic expression) .. so .. in case i can't .. is there a way i can use a dq as a dd ?
you can convert the double value to an integer using FIST[P] (as long as the value is in range of an integer).
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

the ADD EBX,1 doesn't look right
and - if you did want that, you could just use MOV EBX,offset Array+1
but - you don't - lol

this part looks ok, but i would suggest REAL8 PTR
FLD qword ptr [ebx]

FLD real8 ptr [ebx]
it helps the readability - now, you know at a glance that you are loading a REAL8

generally, i might use QWORD PTR if i were loading an integer
FILD qword ptr [ebx]
loads an 8-byte integer

Joao Batista

mm yeah.. apparently i can't scape of the fact that i need a dd at some point, so i'll just modify my java code, i think it will be easier.

Thanks again guys.. thanks for your help!