王爽汇编实验11解答

这道题比较简单,直接上代码吧。

data segment
    db "Beginner's All-purpose Symbolic Instruction Code.",0
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:
; set segment registers:
    mov ax, data
    mov ds, ax    
    
    mov ax,stack
    mov ss,ax
    mov sp,256

    ; add your code here        
    mov si,0
    call ltou  
    
    mov dh,8 ; line=8   
    mov dl,3 ; column=3
    mov bl,7 ;color=white/black    
    call show_str              
     
    mov ax, 4c00h ; exit to operating system.
    int 21h     
    
;
;str:[ds:si]
;

ltou: 
   push si        
   push ax        
   mov ah,0
L40:                  
   ;get next char
   mov al,[si]    
   cmp al,0
   jz  end 
   cmp al,97
   jb  skip_trans
   cmp al,122 
   ja  skip_trans
   and al,11011111b  
   mov [si],al
skip_trans:    
   inc si
   jmp short L40     
end:    
   pop ax
   pop si
   ret     
   
;show string
;dh:line(0-24) dl:column(0,79),bl:color  ds:si string start addr
;es:bx->0b800:offset   

show_str:     
    ;save registers      
    push cx
    push ax
    push es             
    push bx
    push dx      
    push bx  ;save color
  
    ;init es
    mov ax,0b800h
    mov es,ax
    ;calc display memory offset according to line and columm
    mov al,dh   
    mov cl,160
    mul cl; 160 bytes per line    
    mov dh,0
    add ax,dx  ;offset = 160*line + 2*column
    add ax,dx 
    mov bx,ax  
    
    pop ax          ;restore color
    mov ah,al           
l:  
    ;string end?
    mov cl,[si]   
    mov ch,0
    jcxz ok   
    ;begin write 
    mov al,cl
    mov es:[bx],al
    ;write color   
    mov es:[bx+1],ah            
    ;update indexs
    inc bx
    inc bx
    inc si  
    jmp short l  

ok:   
    ;recover registers     
    pop dx
    pop bx
    pop es
    pop ax        
    pop cx
    ret       
             
ends

end start ; set entry point and stop the assembler.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值