简体   繁体   中英

Pass offset from stack/frame pointer to variable to GCC inline assembly

In all flavors of GCC, local variables that don't fit into registers are stored on the stack. For accessing them, one uses constructs like [ESP+n] or [EBP-n], where n might involve an offset within the variable.

When passing such variables to GCC inline assembly as operands, a spare register is used to store the calculated address. Is there a way to designate operands as "the base register of this variable" and/or "the offset of this variable relative to the base register"?

If you do something like

int stackvar; ... asm ("...":"r"(stackvar))

you force GCC to load stackvar into register. If you add m constraint, you don't:

int stackvar; ... asm ("...":"rm"(stackvar))

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