x86 Calculating AX given AH and AL?

て烟熏妆下的殇ゞ 提交于 2020-01-26 10:53:47

问题


I'm having trouble understanding registers in x86 Assembly, I know that EAX is the full 32 bits, AX is the lower 16 bits, and then AH and AL the higher and lower 8 bits of AX, But I'm doing a question.

If AL=10 and AH=10 what is the value in AX?

My thinking on this is to convert 10 into binary (1010) and then take that as the higher and lower bits of AX (0000 1010 0000 1010) and then converting this to decimal (2570) am I anywhere close to the right answer here, or way off?


回答1:


As suggested by Peter Cordes, I would imagine the data as hexadecimal values:

RR RR RR RR EE EE HH LL
|           |     || ||
|           |     || AL
|           |     AH  |
|           |     |___|
|           |     AX  |
|           |_________|
|           EAX       |
|_____________________|
RAX

...where RAX is the 64-bit register which exists in x86-64.

So if you had AH = 0x12 and AL = 0x34, like this:

00 00 00 00 00 00 12 34
|           |     || ||
|           |     || AL
|           |     AH  |
|           |     |___|
|           |     AX  |
|           |_________|
|           EAX       |
|_____________________|
RAX

...then you had AX = 0x1234 and EAX = 0x00001234 etc.

Note that, as shown in this chart, AH is the only "weird" register here which is not aligned with the lower bits. The others (AL, AX, EAX, RAX for 64-bit) are just different sizes but all aligned on the right. (For example, the two bytes marked EE EE in the chart don't have a register name on their own.)



来源:https://stackoverflow.com/questions/37243801/x86-calculating-ax-given-ah-and-al

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