汇编题目:在窗口上显示Welcome to masm!

 题目:在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串'welcome to masm!'.

该程序题目来自《王爽 汇编语言_第2版》的188页的说明。相关资料也在上面都有详细说明。

 题目很简单,然后从网上看了下其他人的程序,然后又根据自己的想法写了如下程序:

assume cs:codesg


data segment
db 'Welcome to masm!'
data ends

stack segment
db 100 dup(0)
stack ends

codesg segment
start:mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,100
mov ax,0b8a0h  ;0b800h 用于显示的缓存
mov es,ax

;B80000~BFFFF
;000-09f  第一行
;0a0-13f  第二行
;140-1df  第三行

;颜色属性数据
; 0 = Black       8 = Gray
; 1 = Blue        9 = Light Blue
; 2 = Green       A = Light Green
; 3 = Aqua        B = Light Aqua
; 4 = Red         C = Light Red
; 5 = Purple      D = Light Purple
; 6 = Yellow      E = Light Yellow
; 7 = White       F = Bright White

mov cx,3
mov dl,39h    ;第一位表示背景色,第二位表示前景色
mov bx,0    ;行控制

s:
push cx
mov ax,0
mov di,0    ;列控制

mov cx,32
s0:mov es:[bx+di],al
inc di
mov es:[bx+di],dl
inc di
loop s0

mov cx,16
mov si,0

s1:mov al,ds:[si]
mov es:[bx+di],al
inc di
mov es:[bx+di],dl
inc di
inc si
loop s1

mov cx,0a0h
sub cx,di
push dx
mov ax,cx
mov cx,2
div cl
mov cx,ax
pop dx
mov ax,0

s2:mov es:[bx+di],al
inc di
mov es:[bx+di],dl
inc di
loop s2

pop cx
add dl,11h
add bx,160
loop s

mov ax,4c00h
int 21h
codesg ends
end start

 

下面的程序是我从网上参考的,我试试了下,只显示一行,如果你要用下面的代码还需要自己修改修改

assume cs:code,ds:data
 data segment
     db 'welcome to masm!'
     db 02h,24h,71h
 data ends
 code segment
 start:
         mov ax,0b872H
         mov es,ax
         
         mov ax,data
         mov ds,ax
         
         mov bx,0
         mov cx,16
         mov di,0
     s:  
         mov al,ds:[bx]
         mov ah,ds:[18]
         mov es:[di],ax
         inc bx
         add di,2
         loop s
 
         mov ax,4c00h
         int 21h
 code ends
 end start

参考出处:http://www.tuicool.com/articles/3MJ3qi
以上两个程序请自己编译链接,本人亲自进行测试。

在来个升级版的,使用子程序输出字符串。

功能:循环三行输出'Welcome masm!',然后再输出一行'this is name!'

assume cs:codesg

data segment
db 'Welcome masm!',0
db 'this is name!',0
data ends

stack segment
db 100 dup(0)
stack ends

codesg segment
start:mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,100
mov cx,3


mov si,ds
mov dx,808h
s0:
mov di,0
call showStr
add dx,100h
loop s0


mov di,14    ;定义偏移
add dx,100h
and dl,0
call showStr




mov ax,4c00h
int 21h


;si表示数据首地址,di表示数据首地址的偏移,
;dh表示行,dl表示列,
showStr:
push ax
push bx
push cx
push dx
push es
mov ax,0b800h
mov es,ax
push ds
mov ds,si

xor ax,ax
mov al,dh
mov bx,160
mul bl
push si
mov si,di
push ax    ;
xor ax,ax
mov al,dl
mov bl,2
mul bl
;push al    ;列
mov di,ax    ;
pop bx    ;
;xor cx,cx
mov al,0ech    ;字体的颜色属性
showRead:
mov cl,ds:[si]
jcxz back
mov es:[bx+di],cl
inc di
mov es:[bx+di],al
inc si
inc di
jmp showRead
back:
pop si
pop ds
pop es
pop dx
pop cx
pop bx
pop ax
ret

codesg ends
end start

 

运行:编译链接后会产生一个exe文件,在cmd窗口用debug xxx.exe的方式载入程序,然后按p命令执行。

然后就会在屏幕中看到“welcome to masm!”

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值