用汇编语言在屏幕中间分别显示绿色,绿底红色的字符串“welcome to masm!"
程序如下:
;----------------------------------
DATA SEGMENT
x DB 'welcome to masm!', 0
DATA ENDS
;----------------------------------
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV BX, OFFSET x
MOV DX, 0C1EH ;第12行、30列.
;--------------------------
NEXT:
MOV AL, [BX] ;取来字符.
CMP AL, 0 ;为0吗?
JZ EXIT ;为0就结束.
MOV AH, 2 ;设定光标位置.
INC DX
INT 10H
;--------------------------
PUSH BX
MOV AH, 9 ;显示字符.
; ;AL为字符的ASCII
; MOV BL, 1EH ;蓝色背景、黄色字符.
MOV BL, 2CH ; 绿底红色的字符.
MOV CX, 1 ;显示一个字符.
INT 10H ;显示吧.
POP BX
;--------------------------
INC BX
JMP NEXT
EXIT:
MOV AH, 4CH
INT 21H ;返回DOS
CODE ENDS
END START
;===============
上述程序运行的显示效果如下图所示。
DATA SEGMENT
DW 'ABCDEF'
DATA ENDS
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
MOV AX,0B800H
MOV ES,AX
MOV DI,0
MOV BX,0
MOV CX,6
S:MOV AL,[BX]
MOV AH,02
MOV ES:[DI],AL
MOV ES:[DI+1],AH
INC BX
INC DI
INC DI
LOOP S
MOV AX,DATA
MOV DS,AX
MOV AX,0B800H
MOV ES,AX
MOV DI,0
MOV BX,0
MOV CX,6
S1:MOV AL,[BX]
MOV AH,04
MOV ES:[DI+160],AL
MOV ES:[DI+161],AH
INC BX
INC DI
INC DI
LOOP S1
MOV AX,4C00H
INT 21H
CODE ENDS
END START