汇编获取键盘输入,及改变文本颜色

data segment
    pkey db "press (rgb) key to change color:$"
ends

stack segment
    dw   128  dup(0)
ends

code segment
start:    
    mov ax,data
    mov ds,ax   
    lea dx, pkey
    mov ah, 9
    int 21h        ; output string at ds:dx
    
    mov ah,0
    int 16h  ;wait key
    
    mov ah,1
    cmp al,'r'
    je red
    cmp al,'g'
    je green
    cmp al,'b'
    je blue
    jmp short sret
    
    red: 
    shl ah,1
    green: 
    shl ah,1
    blue:
    mov bx,0b800h
    mov es,bx
    mov bx,1
    mov cx,20
    s:
    and byte ptr es:[bx],11111000b
    or es:[bx],ah    ; change forecolor
    add bx,2
    loop s
       
    sret:   
    mov ax, 4c00h ; exit to operating system.
    int 21h    
ends  
end start ; set entry point and stop the assembler.
原文地址:https://www.cnblogs.com/wucg/p/4466218.html