8. Program to Color Matrix in Assembly Language using Visual Studio

Chapter 5

Procedures

Assembly Language Programming Exercise

Problem # 8:

Write a program that displays a single character in all possible combinations of foreground and background colors (16 16 256). The colors are numbered from 0 to 15, so you can use a nested loop to generate all possible combinations.

Solution:

INCLUDE Irvine32.inc

.data
count DWORD ?

.code
main PROC

    mov eax, 0 + (0 * 16)
    mov ecx, 16
    L1:
        mov count, ecx
        push eax
        mov ecx, 16
        L2:
            call SetTextColor
            push eax          
            mov al,'H'
            call WriteChar
            pop eax
            inc eax
        LOOP L2
        call crlf
        pop eax
        add eax, 16
        mov ecx, count
    LOOP L1

    call crlf
    call WaitMsg
    exit
main ENDP

END main