[英]How to read a 64-bit number in assembly
I have to read a 64-bit number from the keyboard,but I do not know why it does not work. 我必须从键盘上读取一个64位数字,但是我不知道为什么它不起作用。 Could anyone give me an idea?I am working in masm.
有人可以给我一个主意吗? This is what i did:
这就是我所做的:
key dq 0
give_key db "Enter the encryption key (64-bit): " , 0
formatkey DB "%lld ", 0
procedure PROC NEAR
push offset give_key
call printf
add esp,4
push offset key
push offset formatkey
call scanf
add esp,8
ret
procedure ENDP
If you're using x86 assembly, you will have to do two mov
s, one for the lower 32 bits, and one for the upper. 如果您使用的是x86汇编,则必须执行两个
mov
,一个用于低32位,一个用于高位。 On x64, you can move it in one instruction, which means on 64-bit, the operation is atomic, whereas on x86, it's not. 在x64上,您可以在一条指令中移动它,这意味着在64位上,该操作是原子的,而在x86上则不是。
For instance, on x86: 例如,在x86上:
mov dword [eax], low32
mov dword [eax+4], high32
And on x64: 在x64上:
mov rax, 0xffffffffffffffff
The last space in formatkey
causes trouble. formatkey
的最后一个空格会引起麻烦。 Do you really need it? 您真的需要吗?
This works for me ( .lib
from Visual Studio 2010 Express): 这对我
.lib
(来自Visual Studio 2010 Express的.lib
):
includelib msvcrt.lib
.686
.MODEL flat
EXTERN _printf:proc, _scanf:proc, _exit:proc
.DATA
key dq 0
give_key db "Enter the encryption key (64-bit): " , 0
scanformat DB "%lld", 0
printformat DB 10, "Entered: %lld", 10, 0
.CODE
procedure PROC NEAR
push offset give_key
call _printf
add esp,4
push offset key
push offset scanformat
call _scanf
add esp,8
ret
procedure ENDP
_main PROC
call procedure
push dword ptr key + 4 ; High DWORD of 64-bit QWORD
push dword ptr key + 0 ; Low DWORD of 64-bit QWORD
push offset printformat
call _printf
add esp,12
push 0
call _exit
_main ENDP
END _main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.