Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer Science: Assembly Language for x86 Processors Ch5 VS 2017 [C++] Color M

ID: 3587975 • Letter: C

Question

Computer Science: Assembly Language for x86 Processors

Ch5

VS 2017 [C++]

Color Matrix

Write a program that displays a single character in all possible combinations of foreground and background colors (16 x16 = 256) with AL: BKGD|FRGD. The colors are numbered from 0 to 15, so you can use a nested loop to generate all possible combinations. Hint: for foreground (00h to 0Fh) and background (0Xh to FXh). Notice AH must be zero all the time. Use SetTextColor and WriteChar.

C:Windows system321cmd.exe xX XxXXXX XX XXXXXX XXXxXX Press any key to continue..

Explanation / Answer

INCLUDE Irvine32.inc

DELAY_TIME = 1000

.data

charVal BYTE 'A'

greeting BYTE "DEMO program for Color Matrix",0dh,0ah,0

rowCol LABEL WORD

column BYTE 0

row BYTE 0

.code

main PROC

;-------- display opening header ---------------------------

mov eax,white

call SetTextColor

call Clrscr

mov edx,offset greeting

call WriteString

call WaitMsg

call Clrscr

;-------- begin color display ---------------------------

mov ecx,6 ; loop 6 times

L0: push ecx ; save loop counter

mov rowCol,0 ; initialize row/column variable

mov dx,0 ; set cursor at 0,0

call Gotoxy

mov eax,0 ; starting color: black on black

mov ecx,16 ; 16 possible background colors

L1: push ecx ; save loop counter

mov dx,rowCol ; get ready for a new row

call Gotoxy

mov ecx,16 ; 16 possible foreground colors

L2: call SetTextColor ; set the color

push eax

mov al,charVal ; character to be displayed

call WriteChar ; write it to the console

pop eax

inc al ; next foreground color

loop L2 ; finished with the row

; The first time this line is reached, the color byte equals 10h,

; which gives us the next background color (and resets the foreground

; to black)

inc row ; go to next row

pop ecx ; restore loop counter

loop L1

mov eax,DELAY_TIME ; delay for a while

call Delay

inc charVal ; next character

pop ecx ; restore loop counter

loop L0 ; go to next character

mov eax,lightGray ; restore screen to normal color

call SetTextColor

exit

main ENDP

END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote