简体   繁体   中英

How to print a DWord in assembly?

I'm learning Assembly, and it would be nice for me to be able to output a number to the screen instead of just a string of text. I know how to print a character using mov eax, 1 , but that doesn't work with DWords.

I am using 64-bit Ubuntu.

Makefile:

all:
    nasm -f elf64 asm.s -o asm.o
    ld asm.o -o asm
    rm asm.o

One easy way to print stuff would be just using printf , you're asking how to print a dword, that's easy:

extern _printf

SECTION .data
    msg:     db "Printing a dword: %d",10,0
    number:  dd  123456789

SECTION .text
    global start

start:
    push dword [number]
    push dword msg
    call _printf
    add esp, 8
    mov eax, 0
    ret

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM