|
主题 : : 自己写的关于实验9的程序(两种实现方式) [待解决] |
回复[ 1次 ]
点击[ 218次 ] | |
荣誉值:0
信誉值:0
注册日期:2010-05-25 22:09 |
程序一,实现思路是分三个独立循环,每个循环写一行的数据
;prog95.asm
;
;char attribute:
;bg color black front color green: 00000010
;bg color green front color red : 00100100
;bg color white front color blue : 01110001
;
;display position:
;row(1-25) 12/13/14
;row 12 --> b86e0-b877f
;row 13 --> b8780-b881f
;row 14 --> b8820-b88bf
;
;column(1-80) 32*2-47*2
assume cs:codesg, ds:datasg, ss:stacksg
datasg segment
;string for display
db 'welcome to masm!'
datasg ends
stacksg segment
db 16 dup (0)
stacksg ends
codesg segment
start: mov ax, datasg ;set ds
mov ds, ax
mov ax, 0b800h ;set display area segment to es
mov es, ax
;display bg color black front color green
mov cx, 16
mov bx, 0
mov si, 0
mov di, 06e0h
s: mov al, [si]
mov ah, 00000010b
mov es:[di+64], ax
inc si
add di, 2
loop s
;display bg color green front color red
mov cx, 16
mov bx, 0
mov si, 0
mov di, 0780h
s1: mov al, [si]
mov ah, 00100100b
mov es:[di+64], ax
inc si
add di, 2
loop s1
;bg color white front color blue
mov cx, 16
mov bx, 0
mov si, 0
mov di, 0820h
s2: mov al, [si]
mov ah, 01110001b
mov es:[di+64], ax
inc si
add di, 2
loop s2
mov ax, 4c00h
int 21h
codesg ends
end start
--------------------------------------------------------------------------
程序二,实现思路是用两个嵌套循环,内层循环控制显示每行的每个字符,外层循环控制行数
实际上就是合并程序一的三个循环,因为程序一的三个循环有大量代码重复(重构?)
;prog96.asm
;
;char attribute:
;bg color black front color green: 00000010
;bg color green front color red : 00100100
;bg color white front color blue : 01110001
;
;display position:
;row(1-25) 12/13/14
;row 12 --> b86e0-b877f
;row 13 --> b8780-b881f
;row 14 --> b8820-b88bf
;
;column(1-80) 32*2-47*2
assume cs:codesg, ds:datasg, ss:stacksg
datasg segment
;string for display
db 'welcome to masm!'
db 2h, 24h, 71h
dw 06e0h, 0780h, 0820h
datasg ends
stacksg segment
db 16 dup (0)
stacksg ends
codesg segment
start: mov ax, datasg ;set ds
mov ds, ax
mov ax, 0b800h ;set display area segment to es
mov es, ax
;display bg color black front color green
mov cx, 3
mov bp, 16 ;bp as color attribute data offset
mov bx, 19 ;bx as display area address data offset
s: mov di, ds:[bx]
push cx
mov cx, 16
mov si, 0
s1: mov al, [si] ;show char one by one, display one char per loop
mov ah, [bp]
mov es:[di+64], ax
inc si
add di, 2
loop s1
pop cx
add bp, 1
add bx, 2
loop s
mov ax, 4c00h
int 21h
codesg ends
end start
--------------------------------------------------------------------------
其实还有第三种解决方法,可以只用一个循环完成,即在每次循环中,分别在三行中相同的列写
相同的字母,这样一个16次的循环就能完成了,呵呵,时间问题就没有写了,大家可以试着写写看 | | |