Elsewhere there are things that we all miss, yet it takes just one to notice...

X86_64 printf 64 bit assembler test

So, I wanted to start playing about with assembler again. Mainly so I could use it for data encryption over the internet. Here’s a simple sample of printing 64 bit numbers as hex.

section .text
global  main

extern  printf

; use printf to print 64 bit hex string

_test:  push    rbp

        mov     rsi,0x1234567890abcdef
        mov     rdi,pf_msg
        xor     rax,rax
        call    printf

        pop     rbp
        
        ret

main:   call    _test
        
        mov     edx,len
        mov     ecx,msg
        mov     eax,4
        int     128
        
        ;mov     eax,1
        ;int     128
        
        xor     rax,rax
        ret

section .data

msg     db      "Hello world!",10
len     equ     $ - msg

; some testing stuff

pf_msg  db      "Register = %016llx", 10, 0

I set up a simple script to build the executable.

#!/bin/bash
nasm -f elf64 test.asm
gcc -o test test.o

And the output is just…

Register = 1234567890abcdef
Hello world!
Scroll to top