简体   繁体   中英

How to dereference a pointer in ASM data section?

I have a C code that declares a global pointer and initializes it. Something like this:

my_type* var = malloc(...)

When I declare var as an extern symbol in ASM x86 I get a reference to the pointer, ie a double pointer, which is really inconvenient because whenever I want to access the content I have to do something like this:

extern var
mov ax, [var]
mov dx, [ax]

I want to get a symbol in ASM that holds the value returned by malloc, ie a pointer to my_type as I have in the C code.

Is there a way to do this?

That's how variables work. The value of a symbol (ie its address) cannot change at runtime, which is why symbols generally resolve to the address of a datum and not the datum itself. There is no way to get the exact behaviour you desire because the address malloc returns cannot be known at link time.

If you want to avoid dealing with variables containing pointers, consider creating an array in static storage instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM