문제

I want to form a PCI address. How can I write 16-bit to the EAX (not to AX) in assembly language?? Example: write 0b1000000000000001

EAX before
|_____16-bit_____||_______AX_______|
EAX after:
|1000000000000001||_______AX_______|

Thanks!

도움이 되었습니까?

해결책 2

It's not possible to access the higher 16 bits, but you can use a little trick:

push    ax
mov     ax, 1000000000000001b
shl     eax, 16
pop     ax

This sets the higher 16 bits to any value you want without destroying the lower 16 bits.

다른 팁

There are many ways to do it, here are some.

Using the stack, doesn't modify any flags:

push eax
mov  [esp+2],word 0b1000000000000001 ; some assemblers want word ptr
pop  eax

Rotating to left or right, doesn't need stack, but modifies flags:

rol  eax,16                ; rol / ror
mov  ax,0b1000000000000001
rol  eax,16                ; rol / ror

For hardcoded values (as in the question), you can also use and with or/xor/add. For non-hardcoded values you would need to shift the value in some other register or in memory to use this method:

and  eax,0x0000ffff
or   eax,0x80010000       ; or / xor / add
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top