Hello


   message db "Asm Community$"
   number dw 1234

   mov ah,  message   ;mov ah, [00011h]
   mov ah,  ;mov ah, [00011h]
   
   mov ax, number   ;mov ah, [0001fh]
   mov ax, ;;mov ah, [0001fh]


Emu8086 generates same code both message and or number or , so i couldn't be sure.
What is the specification?
Are message and number, address(pointer) or value(of the first element in the array)?

Thanks.
Posted on 2009-09-06 17:20:08 by sawer
Try this:

message db "Asm Community$"
    number dw 1234,777,444 ; // short number[3]={1234,777,444};
    numx dw 6 dup (?) ; // short numx[6];

    mov ah,  message
    mov ah,
   
    mov ax, number  ; // ax = number[0] =  1234
    mov ax, ; // ax = number[1] = 777 .  Notice how we specify byte-offset as "+2" instead of array-offset "+1"
Posted on 2009-09-06 17:32:50 by Ultrano
Sorry , i don't understand what you mean.
Posted on 2009-09-06 18:00:19 by sawer
The square braces indicate that data is being moved to or from an address in memory.
This has nothing to do with arrays... not when used this way.

The assembler has noticed that the data variables you declared have names, and it can therefore treat those names as pointers (or offsets to) your data in the executable file.
So it knows that when you typed


mov ah,  message

you really meant

mov ah,  


The latter version is "more correct", but both mean the same thing, and both are accepted by your assember.



However, to make things clearer, look at this:

mov ax, dx ;just copies the data from register dx into register ax

but

mov ax, ;this time, dx is a Pointer, it contains the address to get data from



Hope that helps :)
Posted on 2009-09-07 03:57:23 by Homer
Yes it helped.
Thanks.
Posted on 2009-09-07 07:41:02 by sawer
Hey Homer,

Can't you turn that "assuming" off?
That's highly annoying.
message and are clearly different things and that difference is very useful e.g. for traversing strings while maintaining a readable code.
I'm using MASM from the MASM32 package, do you know how to turn that off, i.e. assuming that by "mov eax, message" I mean "mov eax, "?

Because that being the case I'll never be able to traverse a string by counting the offset in ecx and doing
lea eax,
mov eax,
to have the next character in eax.

EDIT: just a bit of a rant:
to me it's really upsetting to be able to do
mov wc.cbSize,sizeof WNDCLASSEX
When it really should be
mov ,sizeof WNDCLASSEX
This takes control away from me and the only reason I'm learning assembly is to have MORE control, not LESS.
I'm very good with pointers in C but since MASM is doing things behind my back I get lost very easily.
I looked at some FASM sample codes and apparently it does not assume things. Maybe my only option is to switch to a less hand-holding assembler?
Thanks.
Posted on 2009-09-10 23:25:40 by Cyborg
You are looking for a LESS FLEXIBLE assembler? :D

Seriously - if you don't like the mov eax, Label syntax, use a syntax you DO like - MASM won't care which you choose to use. Just code it how you prefer to look at it - but don't expect everyone else to follow that particular convention, it's really a personal preference.

I find mov eax, MyStruct.MySubStruct.MyField quite easy to interpret.
And when using register indirection, you're FORCED to use the square braces, so I'm very much used to using whatever I feel like, when I like... and I don't expect people to port my asm source to other assemblers.. if they want to, they can do the fixups themselves, there will ALWAYS be syntax nuances that are incompatible between different assemblers, there simply is no universal syntax.


And no, as far as I am aware, there is no way to disable this COMPLETELY OPTIONAL behavior.


Posted on 2009-09-11 00:00:31 by Homer
Thanks for the reply, Homer.

I should make myself clearer.
I don't want to force anyone to do what I "think" is right.

I'd just like for
mov eax, message
to put the address of the message in EAX, not the first byte(s).
Having to write
mov eax, addr message
is not "flexible", it's only flexible if you can turn that off. ;)
So as you see, it's not really optional. I don't have the option to make "mov eax, message" work as it should: moving the pointer, not the content.
Posted on 2009-09-11 00:36:05 by Cyborg
How about using NASM/FASM etc ? I think they were quite strict in not allowing you that flexibility (which is extremely useful when you make big projects, btw - but is still a preference) .
Posted on 2009-09-11 06:52:51 by Ultrano
For addresses, you should be using LEA rather than MOV, as you already mentioned :)
There's no problem in doing that.

I think what you are looking for is this:

mov eax, OFFSET message

which is exactly the same as

lea eax, message

except it will ONLY work for variables declared in the DATA segment... whereas LEA will work in all cases, including LOCAL variables.


Posted on 2009-09-11 09:19:04 by Homer
Thanks Ultrano, I was really thinking about trying FASM.
I'll look into NASM.

Homer, that makes perfect sense.
I guess if I stick with MASM then I can just use lea all the time.
I shouldn't be MOVing anyway because that resolves at compile time only,
whereas LEA resolves at runtime and therefore will always work.

Cool, thanks!

EDIT: in other words, MOV with ADDR/OFFSET is a hardcoded pointer, and LEA is the actual C pointer, or a soft pointer, that resolves at runtime.
Please correct me if I'm wrong, I'm still converting from C to ASM. :)
Posted on 2009-09-12 05:47:53 by Cyborg
Basically, yes, that's right.

Posted on 2009-09-12 07:30:38 by Homer