News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

the [*register*] usage

Started by Ash_, January 17, 2005, 10:27:32 AM

Previous topic - Next topic

Ash_

in some source i've seen they use this code

mov eax, Something
sub Otherthing, [eax]

^^ its sometihng like that i dont have the source up at the moment, but i was just wondering why you cant just use eax, instead of [eax]?

thnaks in advance

Jibz

eax is the value in the register, whereas [eax] is the value stored at the memory location pointed to by the register.

Just to confuse everybody, in MASM the [] is optional for variables, and you have to use OFFSET or ADDR to get the address instead of what's stored there :U.

hutch--

 :bg

MASM uses square brackets as dereference operators which translates into the CONTENT of a memory address, not the memory address.

If you have the ADDRESS of a DWORD variable in EAX, by using the notation,


mov eax, [eax]


you copy the CONTENT of the memory address directly into the EAX register.

The method is known as the "complex addressing modes" which is standard notation for Intel x86 hardware.

In MASM a named variable "variable" can either be data in the .DATA(?) section or a local variable created on the stack. Some programmer continue to make the mistake of enclosing named variables in square brackets but fortunately MASM ignores the mistake.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jibz

.386
.model flat,stdcall

option casemap:none

.data

bar dd 42
baz equ 9

.code

foo:
    mov eax, foo   ; eax = offset of foo
    mov ebx, bar   ; ebx = value stored at/in bar
    mov ecx, baz   ; ecx = constant 9

    mov eax, [foo] ; eax = offset of foo
    mov ebx, [bar] ; ebx = value stored at/in bar
    mov ecx, [baz] ; ecx = constant 9

end


Well, perhaps it's just that I've been using NASM too much .. but a couple of those worry me a bit when thinking of an aspiring asm coder trying to figure out what some code is doing :eek.

thomasantony

Hi,
   I use NASM only for OS coding. Its syntax is pretty straightforward. In MASM, I don't use square brackets in MASM as a rule except when I really have to , like in the case of string functions etc. I have to use byte ptr [esi] etc. Or else I always use OFFSET or ADDR. :U

Thomas Antony :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Ash_

cheers guys. so say at  4FD428 there was like "hi"

i used

mov eax, 4FD428 <- thats probly not how youd do it but for example
mov eax, [eax]

then eax would contain "hi"

or am i still wrong?

Mirno

EAX would contain 0x00006968 (assuming that it was "hi", 0, 0), note that it's backwards because of the Endian-ness of the x86 architecture. But essentially yes.

"h" being 0x68 in hex, and "i" being 0x69.

Mirno