How to print colored string in DOS?

后端 未结 3 1876
挽巷
挽巷 2020-12-02 01:52

I want to print the below set of datablock(s) in a different color other than the usual white text color which can be achieved by using another DOS interrupt (dx:string-addr

3条回答
  •  醉话见心
    2020-12-02 02:16

    Code For All combinations of foreground and background colors:

    Include Irvine32.inc
    
    .data
    
    str1 byte "F",0dh,0ah,0          ;character initialized (0dh,0ah for next line)
    
    foreground Dword ?               ;variable declaration
    background Dword ?
    counter Dword ?
    
    .code
    
    main PROC
    
    mov ecx,16                     ; initializing ecx with 16
    
    l1:                             ;outer loop
    mov counter,ecx
    mov foreground,ecx
    dec foreground
    mov ecx,16
    
    
    
    l2:                            ;inner loop
    
    mov background , ecx
    dec background
    
    mov eax,background      ; Set EAX = background
    shl eax,4               ; Shift left, equivalent to multiplying EAX by 16
    add eax,foreground      ; Add foreground to EAX
    
    call settextcolor       ;set foreground and background color
    
    
    mov edx, offset str1    ; string is moved to edx for writing
    call writestring
    
    
    loop l2                  ;calling loop
    
    mov ecx,counter
    
    loop l1
        exit
    main ENDP
    END main
    

提交回复
热议问题