1

So I want to print out the ascii value of what is stored in an address with a system call. Lets say i want to print the letter Z in hex this is 0x5a, so lets say in my preamble there I have a pointer ptr point to a element of an array, I transfer the value at the address into cl by:

mov edx, ptr
mov cl, [edx]

Now lets say the value 0x5a is in cl, how do I print this to STDOUT? I have tried (amoung other things):

mov eax, 4 ; SYS_WRITE
mov ebx, 1 ; STDOUT
;value to be prininted is in cl so it is in ecx
mov edx, 4 ; size of the item (tried 4 and 1)
int 80h ;interrupt

This prints absolutely nothing, what am I doing wrong? Do I need to declare something in .data / .bss? I want it to print Z

Thanks

EDIT:

So I can print Z by declaring in .data:

num db 90

Then using mov ecx, num in the system call. but how can I take the hex value in the register and do the same?

Michael Petch
  • 42,023
  • 8
  • 87
  • 158
liamod
  • 188
  • 7
  • 1
    The system call only takes pointers to data to print. So move the address of `ptr` to ecx with `mov ecx, ptr` and then tell it to print a single character so EDX should be 1. If you have a situation where you have a character in a register and want to display it, you have to write it to a memory location (buffer) or even on the stack and then pass the address of that buffer in ECX to sys_write system call. – Michael Petch Nov 10 '20 at 17:30
  • @MichaelPetch thanks it worked :) – liamod Nov 10 '20 at 17:37
  • Related: [How to convert a binary integer number to a hex string?](https://stackoverflow.com/q/53823756) – Peter Cordes Nov 11 '20 at 03:28

0 Answers0