Assembly difference between [var], and var

前端 未结 3 511
情书的邮戳
情书的邮戳 2020-12-06 03:33

I\'m learning Assembler and getting to the point where I actually have no clue about the difference between [variable] and variable. As the tutoria

3条回答
  •  一向
    一向 (楼主)
    2020-12-06 04:11

    Since you already know C++, I'm going to answer by showing you what the C equivalents of these expressions are.

    When you write

    [variable]
    

    in assembly, it's equivalent to

    *variable
    

    in C. That is, treat variable as a pointer and dereference that pointer — get the value the the pointer is pointing to.

    Similarly, the 'type identifiers' are like casting the pointer to a different type:

    ASM:
        dword ptr [variable]
    C:
        *((uint32_t*) variable)
    
    ASM:
        word ptr [variable]
    C:
        *((uint16_t*) variable)
    

    I hope this helps you understand the meaning of these expressions.


    (this section refers to an addendum that has since been deleted from the original question)

    I'm not entirely sure what problem you're experiencing with 'conversion to ascii', but I suspect you're just confused by how it's visually rendered in output or something.

    For example if you have code like this:

    myInteger db 41
    mov AL, byte ptr [myInteger]
    

    the mov will copy the value 41 from memory into the AL register. The number 41 happens to be the ascii representation for the ) character, but this doesn't change anything. Whether the value is interpreted as an ascii character or as an integer is up to you, because they are the same value.

提交回复
热议问题