How can I prepend a `SS:` or `ES:` using AT&T Assembly Syntax
How c开发者_Python百科an I prepend a SS:
or ES:
using AT&T Assembly Syntax without adding in a .byte 0x36
or .byte 0x26
?
ie. How would I be able to convert mov dword ptr ss:[esp+0x10], offset foo
from Intel syntax to AT&T without using:
.byte 0x36
movl $foo, 0x10(%esp)
I have tried movl $foo, %ss:0x10(%esp)
which assembles without warnings but, looking through the binary, still does not add in SS:
An SS:
prefix is not required when used with the ESP
and EBP
registers. For those registers as a base, ss
is already the default segment.
This might be the reason why the assembler simply omits it to conserve space.
You don't want or need an actual SS prefix in the machine code (unless you want to make the instruction longer for alignment / padding reasons). The SS:
in the Intel-syntax disassembly is just there to remind you of the default segment implied by the addressing mode.
If for some strange reason you do want a redundant SS prefix in the machine code, you could manually emit the SS:
prefix with a .byte 0x36
directive. The assembler won't modify raw bytes.
Mainstream 32-bit OSes use a flat memory model where all the segment bases are 0 so it doesn't matter anyway; that's why you can copy ESP to another register like EAX to get the address of a stack var, and dereference it with (%eax)
aka %ds:(%eax)
to still address same stack memory. That's why compilers don't need to know where a pointer came from, and don't need to use %ss:(%eax)
.
Only FS or GS segment overrides (for thread-local storage) are useful in normal code, if you're not writing your own OS with a non-flat memory mode.
精彩评论