;先把输入的字符存入char中 ;连续输入两个回车退出循环 ;然后显示输入的字符串 ;要求以空格间隔 ;每16个字符换行 ;si记录输入字符的个数 ;di指向保存的字符串地址 ;temp记录当前行已经输出的字符的个数 ; M_IN macro ;接受一个字符并存储 mov ah,01h mov [di],al inc di ;存储的地址加1 inc si ; 计数器加1 cmp al ,0dh;判断是不是回车 endm M_out macro ;格式化输出,记间隔输出字符 mov dl,[di] mov ah,02h int 21h
mov dl,0ah mov ah,02h int 21h mov dl,20h mov ah,02h int 21h int di dec si ;每输出一个字符,记述器减一 int temp endm data segment char db 100 dup (?) N equ $-char temp db 0; data ends
code segment assume cs:code ,ds:data start: mov ax,data mov ds,ax mov si,0 ;初始化输入字符的个数计数器为0 mov di,offset char main: M_IN jz next1 jmp short main next1: M_IN JZ exit1 jmp short main exit1: cmp si,N ;取(si)和N的较小值,作为需要输出的个数 jbe short next2 mov si,N next2: again: cmp temp,10h; jz next3 M_out cmp si,0 jz exit2 jmp again next3: M_out cmp si,0 ;如果输出记数器0,结束输出 jz exit2 mov temp,0 ;恢复行输出字符个数的记数 jmp short again exit2: mov ah,4ch; int 21h code ends end start