hi folks
im a asm newbie so i thought this could be the right place to ask some things....
through these days using asm i had a doubt....
when im reading some asm codes i can see a INTENSIVE usage of :
push,eax,cl,cx,mul,div
going deep in math..
for me (a newbie) sounds hard to reach that kind of code...
is there any hint,logic, or tut teaching how to use those math based codes ? :?:
ie:


fmul [vEnd_z]
faddp st(1),st(0)
faddp st(1),st(0)
fld [esi.BSP_PLANE.d]
fadd _offset
fsubp st(1),st(0)
fstp endDistance

:?
the code above is from a opengl BSP loader, but the hard thing (for me) is this :


fld [esi.BSP_PLANE.d]

calling a function from esi or eax or ecx whatever... and some calcs with cl,cx,lowword, highword and stuff...
anyone can help me out ?
thx 8)
Posted on 2004-12-29 09:18:37 by GR33d
Well, to break down the line of code your having a problem with you have to understand structures. Each element in a structure follows the previous one in memory, the distance in bytes from the start of the structure is called the element's offset. A structure is simply a holder for a grouping of data, for example a RECT structure describes a rectangle...

RECT Struct

left DD ?
right DD ?
top DD ?
bottom DD?
RECT ends


This structure holds 4 DWORDs or 16 bytes of data. You can address the individual elements of the structure with the name followed by a . (dot). So to get the DWORD that is held in the top element you would use RECT.top which is equivalent to 8 since RECT.left is 0, RECT.right is 4 etc...

The x86 family of microprocessors allows you to use a general purpose register to address memory. To do this in assembler you enclose the register name in square brackets [] to indicate that you want the data at the address held in the register. You can also perform simple math on the address like adding to it. For example mov eax, .

In MASM the . (dot) is synonomous with + so in the example you gave it is adding the offset of the d element of the DSP_PLANE structure to esi and using the result as an address. Since I don't have the actual structure definition handy I will demonstrate with our RECT structure...

mov eax,

This takes the address in esi and adds 8 to it then moves the data contained at that address into the EAX register. You can also use a much clearer syntax...

mov eax,

This is absolutely equivalent to the first example but is perhaps a bit easier to understand.

fld simply instructs the processor to move the data pointed to into the floating point register (st(0)). Generally though not necessarily the value would be a REAL number, that is a non-integer (it has a fractional part).

Hope this helps :)
Posted on 2004-12-29 21:33:13 by donkey
thx man
that really helped meh :)

another thing...
floating number....

wot are they ? where we can use them ? :?:
Posted on 2004-12-30 09:39:53 by GR33d
Read the floating point tutorial by Ray on www.masmforum.com/website
Posted on 2004-12-30 10:25:10 by roticv
trully helpfull
fpu ..... im learning much more than before... ( sorry my crap english ... im from Brazil )

i know there is a a game forum here..
but they really didnt helped me out....

so the last question is ...
is there any opengl tut on asm out there ? for a real opengl begginer ?
thx all 8)
Posted on 2004-12-30 14:23:07 by GR33d