MASM: using the current location counter ($) in the .data declaration

I met a problem with the current location counter in MASM.

Here is my build code, and I used Visual Studio 2013 Express to build

.386
.model flat,stdcall
.stack 8192
ExitProcess proto,dwExitCode:dword

.data
ptr1 DWORD $
ptr2 DWORD $
ptr5 DWORD $


.code
main proc
    mov eax, $
    mov eax, $
    invoke ExitProcess,0
main endp
end main

In my opinion, I think ptr1, ptr2 and ptr5 should have their own location value.

But this is not really correct.

In debug mode, variables show the same result.

ptr1, ptr2, ptr5 have the same address, and there is no bias between them.

What is the problem when using $ for declaration?

+4
source share
2 answers

, , ​​MASM (, , Microsoft, "" ). , DWORD . , , , .

, MASM ( ) $ . , , ( ):

        .386
        PUBLIC  ptr1, ptr2, ptr5, ptr6, len

_DATA   SEGMENT
        mov     eax, $
        mov     eax, $
ptr1    DWORD   $
ptr2    DWORD   $
ptr5    DWORD   OFFSET $
ptr6    DWORD   ptr6
len     DWORD   $ - ptr1
        mov     eax, $
_DATA   ENDS

        END

, IDA , MASM :

.data:00000000 $$000000:
.data:00000000                 mov     eax, offset $$000000
.data:00000005 $$000005:
.data:00000005                 mov     eax, offset $$000005
.data:0000000A ptr1            dd offset $$000000
.data:0000000E ptr2            dd offset $$000000
.data:00000012 ptr5            dd offset $$000000
.data:00000016 ptr6            dd offset ptr6
.data:0000001A len             dd 16
.data:0000001E $$00001E:
.data:0000001E                 mov     eax, offset $$00001E

, mov eax, $ , DWORD. , ptr1, ptr2 ptr5 $$000000, , , MOV DWORD .

, MASM $ - ptr1. ptr1 , 16, DWORD. , MASM $.

, , . $, ptr6 DWORD ptr6. , , .

+4

MASM $ . - , . , . , , , .

. , .

MSDN . , Randall Hyde ( 8, 2, 16- DOS):

, 80x86 . , , . - , .

, (. ), . . ( ), . MASM , . , MASM mov ax, bx, .

. , . " " - .

, , .

$, . , ...

+3

Source: https://habr.com/ru/post/1664913/


All Articles