I have 2 questions:

1. Is there a way to use the same member name in different strucs?

2. Does assembly have something like the c++ reference (long x; long & y = x;)?
Posted on 2007-11-21 17:21:48 by atcl
Point 1: Yes, why, you can't? :?

Point 2: lea eax, [ x ] / mov , eax

lea can be replaced by mov when the address is absolute, but if it is a local stack variable then you use lea and it is later replaced to "lea eax, " if the stack frame is EBP based.
Posted on 2007-11-21 19:13:43 by LocoDelAssembly
#1: if you're talking about STRUCs in assembly, then iirc TASM doesn't support different structs with same member names, but MASM should.

#2: no, not directly. You can use an "EQU", but it's a very different thing even if it can achieve somewhat same goal.
Posted on 2007-11-22 07:21:17 by f0dder
#1: if you're talking about STRUCs in assembly, then iirc TASM doesn't support different structs with same member names, but MASM should.

TASM does support same names in different structs in IDEAL mode. I don't know if it supports that in MASM mode.

atcl, it's easier to 'comprehend' if you change references to pointers.
Posted on 2007-11-22 08:01:19 by ti_mo_n
ad1: I am using TASM not in IDEAL mode. Any other ideas? May be i can switch inside my source between MASM and IDEAL mode?

ad2: a dynamic equ would be perfect, like: x DD ?; y DD 4; lea eax,y; x equ ;

more info on 2: My problem is the folowing: in my main is a struc full of addresses of procs using them in main is easy: call struc.bla; In libraries i have to hand over a pointer to this struc making a call: call .bla ... this is the situation now. I want to use call strucx.bla from my library the same way i do in main. For that i would need a reference (c like). For easier coding.

Posted on 2007-11-22 10:03:32 by atcl
Drop TASM, grab an assembler that's still being worked on?
Posted on 2007-11-22 10:49:04 by f0dder
I definitely agree with f0dder. Of course you might face a little bit of challenge when porting your code from TASM to say, NASM? but believe it or not, using NASM or an assembler that is being frequently updated and developed is worth the effort. I didn't like NASM at first but I can't live without it now especially because of its preprocessor.
Posted on 2007-11-22 16:27:37 by XCHG
ok. Considering I change to NASM...would that solve both problems?

BTW: I can change at will between IDEAL and MASM mode...so only 1 problem to go....
Posted on 2007-11-22 16:40:58 by atcl
You need to grab more basics of assembly, to realize that your question #2 is quite pointless. I suggest using some assembler with NASM-like syntax, that is NASM / FASM / YASM. That syntax is way less confusing than MASM-like syntax (MASM, TASM, GoASM).
Posted on 2007-11-22 20:43:38 by vid
That syntax is way less confusing than MASM-like syntax (MASM, TASM, GoASM).

To be precise: TASM's native syntax is the so called "ideal" syntax. MASM syntax is there (probably) for compatibility.

Nevertheless, there is no such thing as "reference" - there are only pointers. References allow you to use a pointer in a 'reverse' way (assigning address to a pointer i like assigning value to a pointer. reading/writing from/to a value at a pointer is like reading/writing the reference -- or something like that, I hope you get the point). References somewhat reduce the typing in some situations. That's probably what they were introduced for.

So, like I said, change references to pointers. This will allow you to quickly understand 'what is going on'.
Posted on 2007-11-23 07:20:41 by ti_mo_n
timon: a thing to remember about references is that they're not just "pointers without the start" - if you have "int a; int& b = a;" then using b doesn't require indirection...
Posted on 2007-11-23 07:44:09 by f0dder
But it (a reference) is only an illusion, isn't it? In fact, it's compiled to
mov , offset a

So 'b' is treated like a pointer to 'a' and then both
int a;
int &b = a;

and
int a;
int *b = &a;

will produce same code.

Or am I mistaken?
Posted on 2007-11-23 11:48:00 by ti_mo_n
You are mistaken :)

Obviously references will act as "pointers without the star" in some situations, namely when they're used for function arguments and such.

But when used as an "alias", like the following code:

int a;
int &b = a;
b = 1000;


then 'b' is purely an alias for 'a', and no extra code will be generated (ie, it could emit "mov , 1000" assembly). And it's not possibly to reassign references in the way you can reassign a pointer, a reference is the same variable as it's a reference to, kinda.
Posted on 2007-11-23 17:55:39 by f0dder
OK, now I feel enlightened. Thank you ^^
Posted on 2007-11-24 17:25:11 by ti_mo_n

You are mistaken :)

Obviously references will act as "pointers without the star" in some situations, namely when they're used for function arguments and such.

But when used as an "alias", like the following code:

int a;
int &b = a;
b = 1000;


then 'b' is purely an alias for 'a', and no extra code will be generated (ie, it could emit "mov , 1000" assembly). And it's not possibly to reassign references in the way you can reassign a pointer, a reference is the same variable as it's a reference to, kinda.



I didn't know you could use aliases in C/C++. I can't see a use for it, maybe for readability.Thank you f0dder.
Posted on 2008-01-02 13:24:14 by ChaperonNoir
ChaperonNoir: readability indeed. When you don't particularly care you're dealing with a pointer (ie., you're not aiming for the last few cycles of speed), it's not that important to explicitly see that "this is a pointer" ("->"), the single "." is faster to type...

Also, when you're dealing with deeply nested structures, it's handy to set up a no-cost alias. Sure, any optimizer these days would optimize out a pointer variable, but a reference still gets rid of the indirection arrow in favor of a member-dot.
Posted on 2008-01-02 14:04:20 by f0dder