Hi all,

I'm pretty new to ASM-Programming. I used to program in VC before but now I want to go deeper. As I tried to write my first ASM-Programms I realized that I miss the type-cast.

Does anyone know a good tutorial or a library on doing this. The best would be a documented sourcecode. So I can learn how it works.

Thanks for your help
Posted on 2002-05-15 12:53:49 by Compuholic
Type casting doesnt exist. Well it does, kinda, but only at a very primitive level.

Type casting is mainly to keep C++ from exploding from confusion ;) . In asm, you spell it all out for the compiler.

Tut? :
-------

Masm32 uses 32 bit registers by default.
you *can* use 16 and 8 bit as well no problem

to move data from "char" to "long", you can use:

mov al, "char"
movsx edx, al ; edx = long

now edx has the upper 24 bits set to the same bit as bit 8 of the 'char'. Effectively type casted.

Most often you will see things were memory is pointed by something like a structure.

lea edx, Memory
mov (MyStruct PTR ).StructField, eax

In essence MyStruct is being casted over the memory region that starts at edx. A cleaner way of doing this, is:

lea edx, memory
mov .MyStruct.StructField, eax

I like this better, but hides the PTR part, so it may not be so clear to the reader.

As well, when dealing with signed numbers, you need to 'cast' the assumption they are signed, or MASM will default to unsigned.

mov eax, 0FFFFFFFFh
.if( SDWORD PTR eax == -1 )
invoke Beep, NULL, NULL
endif

Here im telling the assembler that tread the DWORD (long) as a SIGNED (S) DWORD. Thus 0FFFFFFFFh is not the largest number, but rather -1 is 2's complement.

This is all the ways simular to casting that i can think of. The rest is up to you to think about and decide how data is manipulated..

Hope it helps
:alright:
NaN
Posted on 2002-05-15 13:19:21 by NaN
Wow, this was fast :-)

Thanks for your reply. Maybe I didn't express myself clearly (sorry). I tried to write a routine that converts floats to ints. I had no success. My Question: Is there some sourcecode available on the net, that deals with such conversion routines?

Sorry, that you had to write so much but maybe it will help other people (and me too).
Posted on 2002-05-15 13:37:44 by Compuholic
fld qword ptr
fist dword ptr


fld dword ptr
fist dword ptr
Posted on 2002-05-15 13:46:37 by bdjames
Compuholic,
at first i was going to answer "typecasts were invented to keep C++ (and Java) weenies from making mistakes", but then you posted your clarification :)

What you want are either macros or library functions. For macros, search the board for all of Bitrake's posts (that will give you some reading material :grin: ), or check the algorithm section. For libraries, the MASM package already comes with quite a few, check the doco.
Posted on 2002-05-15 22:05:58 by sluggy