实验10
1.在屏幕8行3列,用绿色显示data段中的字符串
assume cs:code data segment db'Welcome to masm!',0 data ends code segment start: mov dh,8 ;行 mov dl,3 ;列 mov cl,2 ;颜色 mov ax,data mov ds,ax mov si,0 ;字符串首地址 call show_str mov ax,4c00h int 21h show_str: push ax ;用到的寄存器入栈 push bx push cx push dx push es push di mov ax,0B800h ;定义显示缓冲区的段地址 mov es,ax ;N为行,M为列 ;计算写入首地址的偏移地址 公式:1) 0A0H*(N)+M*2 mov al,dh mov ah,0 mov bl,0A0h ;每行偏移A0H mul bl mov bl,dl mov bh,0 add ax,bx add ax,bx mov di,ax ;ax为首地址的偏移地址 mov dl,cl ;dl存颜色 mov ch,0 nx: mov cl,ds:[si] ;判断字符是否为00 jcxz over mov bl,cl mov bh,dl mov es:[di],bx ;赋值 add si,1 add di,2 jmp short nx over: pop di pop es pop dx pop cx pop bx pop ax ret code ends end start
2.解决除法溢出
参数:ax=被除数的低16位,dx=被除数的高16位,cx=除数
返回值:dx=结果的高16位,ad=结果的低16位,cx=余数
assume cs:code code segment start: mov ax,4240h mov dx,000fh mov cx,0Ah call divdw mov ax,4c00h int 21h divdw: push ax mov ax,dx mov dx,0 div cx mov bx,ax pop ax div cx mov cx,dx mov dx,bx ret code ends end start
3.数值显示
将data段中的数据以十进制形式显示出来
assume cs:code data segment dw 123,12666,1,8,3,38 dw 0,0,0,0,0,0,0,0 data ends code segment start: mov ax,data mov ds,ax mov ax,20h mov ax,0 mov ax,0B800h mov es,ax mov si,0 ;si为数据段的偏移 mov di,0 ;di为显示缓冲区的偏移 mov cx,6 call dioffset ;计算di值 s:push cx mov ax,[si] ;取数据 mov dx,[0] mov bx,0 ;bx为数字的位数 mov bp,0ch call dtoc mov cx,bx s5:call display loop s5 add si,2 pop cx loop s mov ax,4c00h int 21h ;把数字转为字符串 dtoc: mov cx,10 ;除数10 call divdw jcxz s6 add cx,30h mov ds:[bp],cx ;数字入栈 add bp,2 inc bx ;数字位数加1 jmp short dtoc s6:ret ;把字符存入显示缓冲区中 display: push dx mov dx,ds:[bp-2] sub bp,2 mov dh,02 mov es:[di],dx ;赋值 add di,2 pop dx ret ;求显示缓冲区偏移地址 dioffset: push bx push dx mov dh,8 ;行 mov dl,3 ;列 mov al,dh mov ah,0 mov bl,0A0h ;每行偏移A0H mul bl mov bl,dl mov bh,0 add ax,bx add ax,bx mov di,ax ;ax为首地址的偏移地址 pop dx pop bx ret ;防溢出除法 divdw: push bx push ax mov ax,dx mov dx,0 div cx mov bx,ax pop ax div cx mov cx,dx mov dx,bx pop bx ret code ends end start