So I have the following code, which allocates memory using the mmap linux system call. After executing these instructions, the pointer to the allocated memory is stored in eax. How can I print this pointer in a human readable form such as “00ffbfff”.
I understand how to print to stdout using the write system call, but I was wondering how to convert the value stored in eax to its hexidecimal representation.
section .text
global _start
_start:
; mmap struct
push 0 ;
push -1 ; set the file dsc to -1 for MAP_ANONYMOUS
push 0x20 ; set MAP_ANONYMOUS
push 0x07 ; set Protections WRX
push 0x04 ; size to allocate
push 0 ; geuss - Not Applicable
;; syscall
push eax, 90 ; mmap opcode
push ebx, esp ; mmap struct
int 0x80 ; execute the system call
; allocated address in in eax
Either you’ll need to write your own int-to-text routine, or you can just link the standard runtime library and call the
printf()system call. You’ll have to read up on how your assembler handles linked library functions and importing their symbols and the calling convention, but any C function can be called from assembly if you know what you’re doing.