王爽彙編實驗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.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章