Meaning of the [] and PTR operators??? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Meaning of the [] and PTR operators???

yaayaa Posts: 2Member
Hello,

I'm a newbie to assembler programming and looking at code samples I was wandering about the meaning of the square brackets and PTR operators. Can anyone confirm that the square bracket operator specifies a memory reference (of the contained register, label, etc) and that the PTR operator is used to do something like a C cast??? To what can the square brackets operator be applied to apart registers and labels???
Thx.

Regards,
YAA

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : Hello,
    :
    : I'm a newbie to assembler programming and looking at code samples I was wandering about the meaning of the square brackets and PTR operators. Can anyone confirm that the square bracket operator specifies a memory reference (of the contained register, label, etc) and that the PTR operator is used to do something like a C cast??? To what can the square brackets operator be applied to apart registers and labels???
    : Thx.
    :
    : Regards,
    : YAA
    :
    [blue]Square brackets specify the address expression, like:

    mov [ebx+4], eax

    This means: store the contents of EAX into memory location address of which is calculated as contents of EBX + 4 bytes.

    PTR is used as a cast, consider this:

    mov [ebx], 4

    that means: store value 4 at location in EBX, right? But you can represent value 4 as a byte, word or double word. Usually ASM compiler consider it an error if you set strict rules for compilation. With PTR you point out what is the type of operand at this location:

    mov byte ptr [ebx], 4
    mov word ptr [ebx], 4
    mov dword ptr [ebx], 4
    [/blue]
  • yaayaa Posts: 2Member
    : [blue]Square brackets specify the address expression, like:
    :
    : mov [ebx+4], eax
    :
    : This means: store the contents of EAX into memory location address of which is calculated as contents of EBX + 4 bytes.
    :
    : PTR is used as a cast, consider this:
    :
    : mov [ebx], 4
    :
    : that means: store value 4 at location in EBX, right? But you can represent value 4 as a byte, word or double word. Usually ASM compiler consider it an error if you set strict rules for compilation. With PTR you point out what is the type of operand at this location:
    :
    : mov byte ptr [ebx], 4
    : mov word ptr [ebx], 4
    : mov dword ptr [ebx], 4
    : [/blue]
    :

    Two questions:

    1) to what can the square bracket operator be applied apart registers and labels?

    2) what do you mean by "strict rules for compilation"?

    Thx.

    Regards,
    YAA

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : [blue]Square brackets specify the address expression, like:
    : :
    : : mov [ebx+4], eax
    : :
    : : This means: store the contents of EAX into memory location address of which is calculated as contents of EBX + 4 bytes.
    : :
    : : PTR is used as a cast, consider this:
    : :
    : : mov [ebx], 4
    : :
    : : that means: store value 4 at location in EBX, right? But you can represent value 4 as a byte, word or double word. Usually ASM compiler consider it an error if you set strict rules for compilation. With PTR you point out what is the type of operand at this location:
    : :
    : : mov byte ptr [ebx], 4
    : : mov word ptr [ebx], 4
    : : mov dword ptr [ebx], 4
    : : [/blue]
    : :
    :
    : Two questions:
    :
    : 1) to what can the square bracket operator be applied apart registers and labels?
    [blue]Basically, that's it. You can use any address expression, like:

    mov ax, offset [strData+4]
    lea bx, [bp+si]

    I am not sure you can mix REG + LABEL:

    mov bx, offset [strData+si] // PROBABLY, WRONG - I DO NOT HAVE TIME TO LOOK INTO MANUALS...

    [/blue]
    :
    : 2) what do you mean by "strict rules for compilation"?
    [blue]TASM compiler for example has a couple of options (-wx) to set a warning levels, like 3 of them. Some of the disputable code will be marked with a warning if you use high level and if not - TASM just assumes something and does not let you know what it is - unless you will look at the listing of your compiled OBJ file.[/blue]
    :
    : Thx.
    :
    : Regards,
    : YAA
    :
    :

  • eikedehlingeikedehling Posts: 123Member
    [b][red]This message was edited by eikedehling at 2002-9-12 8:8:17[/red][/b][hr]
    [b][red]This message was edited by eikedehling at 2002-9-12 8:5:52[/red][/b][hr]
    : : Two questions:
    : :
    : : 1) to what can the square bracket operator be applied apart registers and labels?
    : Basically, that's it. You can use any address expression, like:
    :
    : mov ax, offset [strData+4]
    : lea bx, [bp+si]
    :
    : I am not sure you can mix REG + LABEL:
    :
    : mov bx, offset [strData+si] // PROBABLY, WRONG - I DO NOT HAVE TIME TO LOOK INTO MANUALS...
    [blue]
    NOTE: i say stuff about adressing ... offset calculation is different.
    so u can use this like this:
    [code]
    mov (dword/word/byte) (adress expression), (immediate value/register)
    etc...
    [/code]
    general mixing for 32 bit (protected ??) mode:
    [/blue]
    [code]
    [base register] + [index register]*[scale] + [immediate value]
    where:
    [base register] -> any of eax,bcx,ecx,edx,ebp,esp,edi,esi
    [index register] -> any of eax,bcx,ecx,edx,ebp,edi,esi
    [scale] -> any of 1,2,4,8
    [immediate value] -> any of 8-bit-displacement, 32-bit-displacement
    [/code]
    [blue]
    general mixing for 16 bit mode (includes real mode):
    [/blue]
    [code]
    [base register] + [index register] + [immediate value]
    where:
    [base register] -> any of ax,cx,cx,dx,bp,sp,di,si
    [index register] -> any of di,si
    [immediate value] -> any of 8-bit-displacement, 16-bit-displacement
    [/code]
    [blue]
    any element can be omitted. the base is obviously the base of the data structure you are adressing, index is an index in the data structure relative to the base, in 32-bit mode you can multiply the index with 1,2,4,8 which is notpossible in 16 bit mode. the immediate is a number either 8 bit or 16/32 bit (depends on mode) - it might be usefull to look in the manuals :-) (that definitely does not mean that i know everything!)

    Eike.
    [/blue]


    SUSE LINUX 7.3 PRO - The world starts behind windows





Sign In or Register to comment.