将存储在EDX:EAX中的64位数字打印为标准输出 [英] Print 64 bit number stored in EDX:EAX to standard out
本文介绍了将存储在EDX:EAX中的64位数字打印为标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在EDX:EAX中分别存储了64位大数字,分别为21C3677C:82B40000。我试图将数字以小数点形式输出到控制台2432902008176640000是否有系统调用可以实现此目的?
I have large 64 bit number stored in EDX:EAX as 21C3677C:82B40000 respectively. I'm trying to print the number out to the console as a decimal 2432902008176640000 Is there a system call that will allow me to accomplish this?
推荐答案
这里是一个如何使用printf打印64位数字的示例。
Here is an example how to print the 64 bit number with printf. This code works with YASM.
segment .data
format db "Number %ld", 0x0a, 0 ; Format string for printf
result dq 0 ; Quad word to store the EDX:EAX result in
segment .text
global main
extern printf
main:
; Store the 64 bit number in the quad word "result"
mov edx, 0x21C3677C ; Store the EDX value
mov eax, 0x82B40000 ; Store the EAX value
mov [result], eax ; Lower half of "result" will be EAX
mov [result+4], edx ; Upper half of "result" will be EDX
; Print "result" with the printf function
xor eax, eax ; No float parameters for printf
lea rdi, [format] ; First parameter for printf (format string)
mov rsi, [result] ; Second parameter for printf ("result")
call printf ; Call printf
; End program
xor eax, eax ; Return 0
ret
使用以下命令构建二进制文件:
Build the binary with the following commands:
yasm -f elf64 example.asm
gcc -o example example.o
更新:不使用内存的示例
segment .data
format db "Number %ld", 0x0a, 0 ; Format string for printf
segment .text
global main
extern printf
main:
; Store the 64 bit number in register rsi
mov edx, 0x21C3677C ; Store the EDX value (upper half)
mov eax, 0x82B40000 ; Store the EAX value (lower half)
mov esi, edx ; Place upper half in esi
shl rsi, 32 ; Shift left 32 bits
or rsi, rax ; Place the lower half in rsi
; Print "result" with the printf function
xor eax, eax ; No float parameters for printf
lea rdi, [format] ; First parameter for printf (format string)
call printf ; Call printf
; End program
xor eax, eax ; Return 0
ret
这篇关于将存储在EDX:EAX中的64位数字打印为标准输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文