汇编简单的输入输出

上一篇博文介绍了linux下如何搭建汇编的环境,并且实现了现实hello world

博文地址:http://blog.csdn.net/odaynot/article/details/7952201

下面这个小程序实现从键盘输入字符串并显示你所输入的字符串

data segment
    hello db 100,?,100 dup('$')
data ends
code segment
    assume cs:code, ds:data
start:
    mov ax,data
    mov ds,ax
    lea dx,hello
;########################################
;       从键盘输入存入hello中
;########################################
    mov ah,10
    int 21h
;########################################
;    回车换行
;########################################
    mov dl,0ah
    mov ah,2
    int 21h
    mov dl,0dh
    mov ah,2
    int 21h
;########################################
;       输出存储在hello中的字符串
;因为缓存区的第一个字符记录的缓存区的最多存储数
;第二个字符是当前输入到缓存区的字符数,所以输出
;时,舍掉这两个数据
;########################################
    lea dx,hello[2]
    mov ah,9
    int 21h
    mov ah,4ch
    int 21h
code ends
    end start

运行如下: