In the following tutorial:
http://www.friedspace.com/assembly/moving.php
, could you tell me the differences and the effects of the differences between the following statements?
http://www.friedspace.com/assembly/moving.php
, could you tell me the differences and the effects of the differences between the following statements?
MOV ,CH
MOV myvar1,CH
First one is using a pointer, the second one is not!
Means that in:
case 1: ch is being copied to the location pointed to by var1
case 2: ch is being copied directly to var1
Having said that, although its essential to use with some compilers,
it can sometimes be ignored by others (masm for example) at least in this particular case
[] will be discarded.
Point being that I think its always good practice to test what you read.
Means that in:
case 1: ch is being copied to the location pointed to by var1
case 2: ch is being copied directly to var1
Having said that, although its essential to use with some compilers,
it can sometimes be ignored by others (masm for example) at least in this particular case
[] will be discarded.
Point being that I think its always good practice to test what you read.
In MASM-like assemblers it's the same. In other assemblers AFAIK it's the same (maybe some raise an error for case 2 about bracket requirement) - there is no double dereferencing in asm! The difference is (AFAIK) in "mov eax,var" where one would take offset of a var in some assemblers and contents of a var in others. Furthermore, some assemblers have type checking, so "mov eax,var" for dword var is ok but for byte var is not.
The page says: "If we want to move the data at a byte memory location"
Thought I'd clarify what I said! To access memory we have to use pointers, No comment on other compilers but in masm this is an example of what would happen:
I always add the sq brackets just to make the code more infomative...
Thought I'd clarify what I said! To access memory we have to use pointers, No comment on other compilers but in masm this is an example of what would happen:
.data
myVar db "abc",0
.code
mov al, myVar
mov al, BYTE PTR myVar
mov al, BYTE PTR
Either of above will compile as: mov al, BYTE PTR ds:
For a dword just keep the sizes right
.data
myVar dd 10
.code
mov eax, myVar
mov eax, DWORD PTR myVar
mov eax, DWORD PTR
either of above will compile as: mov eax, DWORD PTR ds:
I always add the sq brackets just to make the code more infomative...
Just out of curiosity I downloaded fasm and tried it:
With fasmW the sq brackets appear to hold the command of the appropriate size pointer! ie brackets must be used, or "BYTE PTR" etc
mov al, _message ;no
mov al,BYTE PTR [_message] ;no
mov al,BYTE PTR ds:[_message] ;no
mov al, [_message] ;yes
mov al,BYTE PTR _message ;yes
With fasmW the sq brackets appear to hold the command of the appropriate size pointer! ie brackets must be used, or "BYTE PTR" etc
fasm has one more you skipped: mov al, byte [_message]. Also, notice that fasm requires "ds:" (or any other segment register) to be inside the square brackets: mov al, byte .
FWIW, Nasm is more like Fasm. An unadorned "myvar" means "address of myvar"... like "offset myvar" in Masm-like assemblers. Nasm requires "" to mean "contents", while Masm (etc) would treat either "myvar" or "" the same (contents). Gas uses "$" like "offset".
Nasm syntax:
Best,
Frank
Nasm syntax:
mov al, ;
mov eax, myvar ; address (offset) of myvar
mov al, myvar ; error - won't fit!
mov , al
mov myvar, al ; error!
Best,
Frank