flat assembler
Message board for the users of flat assembler.

Index > Main > Register or Memory Operand

Author
Thread Post new topic Reply to topic
Hicel



Joined: 09 Sep 2004
Posts: 55
Hicel
I have a question, what is the difference between a Register and a Memory Operand.

I ask because of this:
r/m32 -- A doubleword general-purpose register, or a doubleword memory operand.

MOV r32,r/m32
Post 04 Sep 2007, 21:33
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Quote:
have a question, what is the difference


After 3 years and 35 posts ?

Quote:
between a Register and a Memory Operand.

I ask because of this:
r/m32 -- A doubleword general-purpose register, or a doubleword memory operand.


Code:
 mov [0],eax   ; memory <- register  
 mov [edi],eax ; memory <- register
 mov ebx,eax   ; register <- register
 mov eax,0     ; register <- imm ||see also XOR EAX,EAX thread Laughing
 
 ; mov eax,eax                      ; NOP Laughing

 ; movl %%eax,%%blah[junk]$$$      ; GAS only Laughing
 ; movntq blah,@!#$#               ; Risky, SSE only Laughing
 ; mov eax, dworld ptr edi         ; MA$M (+clones) only Laughing
    


See also FASM.TXT and 80386 manual.

And the problem is ? Question

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 04 Sep 2007, 22:09
View user's profile Send private message Reply with quote
Hicel



Joined: 09 Sep 2004
Posts: 55
Hicel
Hmm yes, lets call me a "if i'm forced to assembly, i try to figure it out, but end up asking stupid questions" person.. hehe.. sorry.. I was just reading some papers and sometimes get confused because of too much information.. and then i don't know anything.. anyway after you replied it was clear to me again so thank you.

I have another question.. does anyone know how to force the encoding

83 XOR r/m32,imm8

Code:
use32
xor [dword 0h], byte 0h ;encodes to: 80h 35h 0h 0h 0h 0h 0h    


is 80h = 80 XOR r/m8,imm8
but when does it encode to 83? isn't this m32,imm8? i don't understand that.
Post 07 Sep 2007, 01:25
View user's profile Send private message Reply with quote
Hicel



Joined: 09 Sep 2004
Posts: 55
Hicel
Thank you, I noticed this before I will try to avoid the byte.

but

Code:
use32 
xor [dword 0h], 0h

or

xor [0h], 0h     


does not work fasm wants this 'byte' or something else

Error: 'operand size not specified'

Confused
Post 07 Sep 2007, 02:44
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
yes, you forgot to specify memory operand size, you had just specified that you want the offset encoded as a dword.

Code:
xor <type>[{dword|nothing} address], imm

xor byte [dword 0], 0 ; Xor the byte at address 0. Offset encoded as dword
xor byte [0], 0 ; Xor the byte at address 0. Offset endoded as byte

xor dword [$FFFF], 0 ; Xor the dword at address 0xFFFF. Offset endoded as dword (because it doesn't fit in a byte)
    
Post 07 Sep 2007, 03:06
View user's profile Send private message Reply with quote
Hicel



Joined: 09 Sep 2004
Posts: 55
Hicel
Thanks! great help! worked just fine maybe i should really read more about the fasm syntax.
Post 07 Sep 2007, 06:57
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
.

Note FASM is different from NASM here and auto-defaults to 8-bit encoding of 32-bit operands whenever possible. Use dword to force 32-bit encoding.

Code:
use32
nop
xor dword [dword 0], 0 ; THIS one Idea
nop
xor dword [dword 0], dword 0 ; 1st dword operand size, 3rd dword for 32-bit encoding
nop
    
Post 07 Sep 2007, 22:27
View user's profile Send private message Reply with quote
xspeed



Joined: 16 Aug 2007
Posts: 22
xspeed
i guess i will answer this as easy and simple as i can

register=just number or a location of a memory
Memory Operand=stuff that you get when you get/put in a register

let say:

at 407004=11111

mov eax,407004

this virtually mean that eax=407004

mov eax,[eax]

now this mean that eax=11111


mov eax,407000
mov dword ptr [eax],10000

this mean that at 407000=10000

407000=10000
407004=11111

mov eax,408000
mov dword ptr[eax],10000
mean absolutely nothing and will generate an error because i have nothing at that memory
Post 09 Sep 2007, 21:41
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
.

Quote:
mov dword ptr [eax],10000


Seems to be TASM Ideal syntax, not FASM ... you are generating confusion Confused

Quote:

407000=10000
407004=11111


Confused

Quote:

mov eax,408000
mov dword ptr[eax],10000
mean absolutely nothing and will generate an error because i have nothing at that memory


Error when compiling or when running ? Confused

"I have nothing at that memory" Confused

But YES, in PM faulty memory accesses can run into a GPF or PF Laughing

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 09 Sep 2007, 23:40
View user's profile Send private message Reply with quote
xspeed



Joined: 16 Aug 2007
Posts: 22
xspeed
eax=register value (location of a memory)/immediate data value
[eax]=a value at that memory location

fasm is not cable of debugging an error, it just complies and check only syntax error, not cpu error.

and there is nothing wrong with dword ptr, i love that shit Cool
Post 10 Sep 2007, 15:06
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.