Calculate Segment:Offset from absolute address

醉酒当歌 提交于 2019-12-02 03:29:15

问题


I can calculate an address Segment:Offset as Segment * 0x10 + Offset. But how do I calculate the opposite?

E.g. how do I get from 0xF4170 to F400:0170 and from 0xACF04 to ABCD:1234?


回答1:


You would be required to have either the base or the offset to start with, along with the linear address, as multiple Segment:Offset pairs can map to the same linear address.

so if we have the segment 0xF400 and the linear address 0xF4170, we get the offset being 0xF4170 - (0xF400 << 4) which is 0x170.


Doing this with only knowing the linear address doesn't have a unique solution, so you have to choose a convention for splitting a 20-bit address into a 16-byte-aligned seg part and a byte offset. One possible function is this:

  • Segement = linear >> 4 (top 16 bits)
  • offset = linear & 0x0F (low 4 bits)

You might choose a canonical form with 12:8 bits, leaving room for future expansion with wider linear addresses.



来源:https://stackoverflow.com/questions/9464574/calculate-segmentoffset-from-absolute-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!