换行一般由两个部分组成:
- 换行符(ascii码为10),输入后换行,但光标位置不在第二行起首
- 回车符(ascii码为13),输入后让光标位置回到第二行起首
加入这两部分即可实现换行。
DOS版
创建文件test.asm并复制粘贴以下代码
org 100h
jmp start
welcome: db 'HelloWorld',10,13,'$'
start: mov si, welcome
call printstr
ret
printstr:
mov al,[si]
cmp al,'$'
je discover
mov ah,0eh
int 10h
inc si
jmp printstr
discover:
ret
用NASM编译:
nasm (test.asm所在目录)\test.asm -o (任意一个目录)/test.com
一个DOS程序就出来了,可以用cmd调用。
映像版
创建文件test.asm并复制粘贴以下代码
org 7c00h
jmp start
welcome: db 'HelloWorld',10,13,'$'
start: mov ax, 0
mov ds, ax
mov si, welcome
call printst