Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Direct addressing without segment in x86?

The encoding of memory operands with the SIB-byte allows a ›none register‹ for index as well as base. So this should be a valid instruction:

03 04 25 10 32 54 76add eax, dword [ 0x76543210 ]

The address should be calculated like this: 1·0+0+0x76543210 and is not based on any segment register.
In a flat memory this should not change anything, but is this different from add eax, dword ds:0x76543210, if ds is not zero?

like image 940
sivizius Avatar asked Jan 25 '26 22:01

sivizius


1 Answers

In 16 and 32 bit operation modes, a SIB byte indicating no base and no index (ie. 04 +r 25) simply encodes a 32 bit address, just as the modr/m byte 05 +r does. This does not affect segmentation, ds is used to add a segment base address in both cases.

In long mode (64 bit mode), the modr/m byte 05 +r indicates a rip (resp. eip) relative address whereas 04 +r 25 indicates an absolute address. For example:

8b 05 XX XX XX XX       is mov eax, [rip+XXXXXXXX]
8b 04 25 XX XX XX XX    is mov eax, [XXXXXXXX]
like image 86
fuz Avatar answered Jan 28 '26 19:01

fuz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!