如何将两个dword移到一个qword中? [英] How can I move two dword into one qword?
问题描述
我在此处找到了类似的答案,但仅适用于32位.如何在64位处理器的NASM中做到这一点?
I found similiar anwser here, but it works only for 32bit. How can I do it in NASM in 64bit processor?
推荐答案
您可以使用两个双字连续变量(一个接一个),分别给它们分配值,然后将两个值都作为一个值四字.我在此在线编译器中测试了下一个代码:
You can use two double-word consecutive variables (one after another), assign them values separatedly, then get both values as one quad-word. I tested next code in this online compiler :
section .data
dw1 : dd 0 ;◄■■ FIRST DOUBLE-WORD.
dw2 : dd 0 ;◄■■ SECOND DOUBLE-WORD.
section .text
global _start
_start:
mov dword [dw2], 12345678h ;◄■■ ONE DOUBLE-WORD.
mov dword [dw1], 90ABCDEFh ;◄■■ ANOTHER DOUBLE-WORD.
mov rax, [dw1] ;◄■■ GET ONE QUAD-WORD (1234567890ABCDEFh).
请注意第二双字(dw2
)如何获得更高的值以及第一双字(rax
的大小而到达第二个变量.
Notice how the second double-word (dw2
) gets the higher value, and the first double-word (dw1
) gets the lower value. Also notice how the quad-word is extracted from the first variable but it reaches the second variable because of the size of rax
.
先前的代码不显示任何内容来了解RAX
中发生的事情,所以这是我的原始代码:它将RAX
中的值移动到字符串中,然后显示字符串(垃圾字符):
Previous code doesn't display anything to know what is going on in RAX
, so this is my original code: it moves the value from RAX
into a string, then displays the string (garbage chars) :
section .data
str1 : db '12345678',10
len : equ $-str1
dw1 : dd 0
dw2 : dd 0
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, str1
mov edx, len
int 80h ;◄■■ DISPLAY STRING = "12345678".
mov rax, 01234567890ABCDEFh ;◄■■ MOVE ONE QUAD-WORD DIRECTLY.
mov [str1], rax
mov eax, 4
mov ebx, 1
mov ecx, str1
mov edx, len
int 80h ;◄■■ DISPLAY STRING = "�ͫ�xV4"
mov dword [dw2], 12345678h ;◄■■ MOVE ONE DOUBLE-WORD.
mov dword [dw1], 90ABCDEFh ;◄■■ MOVE ANOTHER DOUBLE-WORD.
mov rax, [dw1]
mov [str1], rax
mov eax, 4
mov ebx, 1
mov ecx, str1
mov edx, len
int 80h ;◄■■ DISPLAY STRING = "�ͫ�xV4" AGAIN!!!
mov eax,1
mov ebx,0
int 80h
上一个是"int 80h"版本,下一个是"syscall版本"(感谢@MichaelPetch告诉我必须使用的寄存器),也在同一在线编译器:
EDIT : previous is the "int 80h" version, next is the "syscall version" (thanks @MichaelPetch for telling me what registers I had to use), also tested in the same online compiler :
section .data
str1 : db '12345678',10
len : equ $-str1
dw1 : dd 0
dw2 : dd 0
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, str1
mov rdx, len
syscall ;◄■■ DISPLAY STRING = "12345678".
mov rax, 01234567890ABCDEFh ;◄■■ MOVE ONE QUAD-WORD DIRECTLY.
mov [str1], rax
mov rax, 1
mov rdi, 1
mov rsi, str1
mov rdx, len
syscall ;◄■■ DISPLAY STRING = "�ͫ�xV4"
mov dword [dw2], 12345678h ;◄■■ MOVE ONE DOUBLE-WORD.
mov dword [dw1], 90ABCDEFh ;◄■■ MOVE ANOTHER DOUBLE-WORD.
mov rax, [dw1]
mov [str1], rax
mov rax, 1
mov rdi, 1
mov rsi, str1
mov rdx, len
syscall ;◄■■ DISPLAY STRING = "�ͫ�xV4" AGAIN!!!
mov rax,60
mov rdi,0
syscall
这篇关于如何将两个dword移到一个qword中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!