1

In DOS Assembly we can do this:

mov dl, 41h
mov ah, 02h
int 21h

But how about Linux nasm x86 Assembly?

nrz
  • 10,435
  • 4
  • 39
  • 71
user2972135
  • 1,361
  • 2
  • 8
  • 10
  • Use the `sys_write` system call with `fd` == 1 (`stdout`) and `count` == 1. How you'd go about doing that depends on whether you're writing 32-bit or 64-bit code. See [this page](http://asm.sourceforge.net/intro/hello.html) for a 32-bit example. – Michael Dec 09 '13 at 08:56
  • No, I want to print a SINGLE character not a string.. – user2972135 Dec 09 '13 at 09:00
  • 5
    Then make the string consist of one char. – icbytes Dec 09 '13 at 09:06
  • What you can't do in Linux is print a single character from a register - it has to be in a buffer. `push 41h` will do. – Frank Kotler Dec 09 '13 at 09:30
  • Related: http://stackoverflow.com/questions/15596688/gcc-putcharchar-in-inline-assembly/15597769 (in Linux x86-64 assembly, you can convert it to Linux x86 assembly). – nrz Dec 09 '13 at 09:59

1 Answers1

2
section     .data

msg     db  'H'
len     equ $ - msg


section     .text
global      _start

_start:

mov     edx,len
mov     ecx,msg
mov     ebx,1    ;file descriptor (stdout)
mov     eax,4    ;system call number (sys_write)
int     0x80

mov     eax,1    ;system call number (sys_exit)
int     0x80

Writing a single character may not produce the desired output, because depending on the terminal settings, it may be cached, so you may need to flush the output, to make sure that it appears wherever you write to.

Here is a list of linux 32 Bit system calls.

Devolus
  • 21,661
  • 13
  • 66
  • 113
  • `sys_write` is never buffered I/O. I think you're talking about C stdio functions like `printf` and write buffers, but that's all user-space inside the library. `write()` is never "cached", and is only delayed if the terminal is blocked (e.g. by xon/xoff flow control: `^S` and `^Q`) – Peter Cordes Nov 07 '17 at 21:09