将存储在 EDX:EAX 中的 64 位数字打印到标准输出 [英] Print 64 bit number stored in EDX:EAX to standard out

查看:28
本文介绍了将存储在 EDX:EAX 中的 64 位数字打印到标准输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的 64 位数字存储在 EDX:EAX 中,分别为 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 位数字的例子.此代码适用于 YASM.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆