显示字符串,在指定位置(dh-1,dl-1)显示指定颜色(cl)的指定字符串(db)
assume cs:code,ds:data,ss:stack
data segment
db 'welcome to masm!',0
data ends
stack segment
db 16 dup(0)
stack ends
code segment
start:
mov dh,2
mov dl,3
mov cl,3
mov ax, data
mov ds, ax
mov si,0
call fun
mov ax,4c00h
int 21h
fun:
mov ax,0b800h
mov es,ax
call getColor
push ax ;//颜色入栈
call getRow
push ax ;//行数入栈
call getCol
push dx ;//列数入栈
pop ax
pop bx
add bx,ax ;//行列数出栈,求和得到初始偏移位置
pop ax ;//颜色出栈
s2: mov cl,[si]
jcxz ret1
mov es:[bx],cl
mov es:[bx+1],ax
add bx,2
inc si
jmp short s2
ret1:ret
/*用cl求颜色,逻辑是00001000b除以2(红1绿2蓝3)次,
这里应该是我理解错误了,其实应该是(红4绿2蓝1),也就是直接赋值就行了*/
getColor:
mov bl,2
mov ch,0
mov ax,00001000b
s1: div bl
loop s1
ret
getRow: ;//行数=160*dh,最大是25*160,可以用8位乘法
mov al,dh
mov dh,160
mul dh
ret
getCol: ;//列数=2*(dl-1)
sub dl,1
add dl,dl
mov dh,0
ret
code ends
end start
不知道为什么dh不用-1,然后字符串在1到24行能显示,25行显示不了。