问题
How can I go about moving two words into a double word variable? Specifically, I would like one word to go in the top-half of this variable, and the other to go in the bottom half.
回答1:
Next code does the job (explanation comes right after) :
.stack 100h
.data
upper dw 195
lower dw 22
.code
mov ax, @data
mov ds, ax
;MOVE TWO WORDS TO ONE DWORD.
mov ax, upper
mov cl, 16
shl eax, cl
mov ax, lower
mov ax, 4c00h
int 21h
Using register EAX, you assign the upper word to AX. AX is the lower word of EAX, then you push it 16 bits to the left (SHL), now the upper word is no longer in AX, now it is in the upper word of EAX. Finally, you assign the lower word to AX. With two words in EAX, you can move the value from EAX to any variable.
回答2:
A clean way to do this is by using the stack.
NASM:
push word [wHigh]
push word [wLow]
pop dword [dwResult]
MASM:
push wHigh
push wLow
pop dwResult
回答3:
// Here is some PSEUDO-code, assuming 16-bit word size:
word lowWord = ?;
word highWord = ?;
dword combined = ((dword)lowWord & 0xFFFF) | (((dword)highWord << 16) & 0xFFFF0000);
// note: the masking with 0xFFFF and 0xFFFF0000 may not be required
来源:https://stackoverflow.com/questions/29159561/how-can-i-move-two-words-into-a-double-word-variable