2013-12-09 95 views
0

在DOS大会,我们可以这样做:如何打印一个ASCII字符?

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

但如何对Linux的NASM x86汇编?

+0

使用带有'fd' == 1('stdout')和'count' == 1的'sys_write'系统调用。你会怎么做取决于你是写32位还是64位位代码。有关32位示例,请参见[本页](http://asm.sourceforge.net/intro/hello.html)。 – Michael

+0

不,我想打印单个字符而不是字符串.. – user2972135

+5

然后让字符串包含一个字符。 – icbytes

回答

1
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 

写的单个字符可能不会产生所需的输出,因为这取决于终端设置,它可以被缓存,所以你可能需要刷新输出,以确保它无论你写出现。

以下是linux 32 Bit system calls的列表。

+0

'sys_write'永远不会被缓冲的I/O。我认为你正在讨论像'printf'这样的C stdio函数和写入缓冲区,但这就是库中的所有用户空间。 write()永远不会被“缓存”,并且只有在终端被阻塞时(例如通过xon/xoff流量控制:'^ S'和'^ Q')才会延迟。 –