views:

79

answers:

1

Hi,

I'm currently getting started with NASM and wanted to know, how to output the contents of a register with NASM in Hexadecimal. I can output the content of eax with

section .bss
    reg_buf: resb 4
.
.
.
print_register:
    mov [reg_buf], eax
    mov eax, SYS_WRITE
    mov ebx, SYS_OUT
    mov ecx, reg_buf
    mov edx, 4
    int 80h
    ret

Let's say eax contains 0x44444444 then the output would be "DDDD". Apparently each pair of "44" is interpreted as 'D'. My ASCII table approves this.

But how do I get my program to output the actual register content (0x44444444)?

A: 

You need to format your register as a text string first. The simplest to use API would likely be itoa, followed by your write call. You will need a string buffer allocated for this to work.

If you don't want to do it in assembly, you can make a quick C/Python/Perl/etc program to read from your program and make all output text.

Yann Ramin