************************************************************
************************************************************
***							 ***
***		    BLUE-SCREEN-OF-DEATH		 ***
***							 ***
***		   (C) September 30, 2006		 ***
***		    Dr. William T. Verts		 ***
***							 ***
************************************************************
************************************************************

        Here are four solutions to the  Blue-Screen-Of_Death
        (BSOD)   assignment.    Each  of  the  solutions  is
        represented by four files, the .ASM source, two .BAT
        files    for   assembly   and   linking,   and   the
        corresponding  .EXE  executable.   Each   executable
        switches  the screen into VGA 320x200 graphics mode,
        paints the screen blue with  a  white  1-pixel  wide
        border,  waits  for the user to enter an ESCAPE key,
        switches back to text mode, and exits to DOS.

------------------------------------------------------------

BSOD0 and BSOD1:

        Minimal   solutions   that   use   the   REP   STOSW
        instructions  to  paint  the blue screen and the top
        and bottom white  horizontal  lines,  and  the  LOOP
        instruction in painting the vertical lines.  The REP
        STOSW dumps two pixels at a time (from AX) into  the
        screen  buffer.   The  only  difference  between the
        programs is how two-pixel colors are generated.   In
        BSOD1  the  color  in  AX  is generated from a value
        loaded into AL and  then  copied  into  AH  (forming
        two-pixel AX).  In BSOD0 the colors are defined with
        EQU statements as two-pixel values at assembly  time
        and  can  be  loaded  into AX in **one** instruction
        instead of two:

	BSOD0				BSOD1
	--------------------		--------------------
	BLUE EQU 0F0FH			BLUE EQU 15
	...				...
	MOV AX,BLUE			MOV AL,BLUE
					MOV AH,AL

        Once AX contains two copies of the pixel  value,  it
        is  copied  into  video  memory  with  the REP STOSW
        instruction (REPeat Store AX into memory at [ES:DI],
        increment DI by 2, and decrement CX until it becomes
        zero).

		MOV	CX,32000	; Paint Screen
		MOV	DI,0		; From Pixel(0,0)
		REP STOSW		; (32000 words)

        This same instruction block  can  also  be  done  as
        follows,  although I did not include a complete copy
        of a program that uses it.   This  version  is  less
        efficient  than  the  previous version, as it copies
        one byte at a  time  into  memory,  instead  of  two
        (REPeat  Store  AL into memory at [ES:DI], increment
        DI by 1, and decrement CX until it becomes zero).

		MOV	CX,64000	; Paint Screen
		MOV	DI,0		; From Pixel(0,0)
		REP STOSB		; (64000 bytes)

------------------------------------------------------------

BSOD2 and BSOD3:

        These form more  "traditional"  solutions  that  use
        explicit loops to control storing of two pixels at a
        time (BSOD2) or one pixel at  a  time  (BSOD3)  into
        memory.   In  both  versions, REPEAT-UNTIL loops are
        used, with a count value in CX that decreases  until
        it   reaches  zero.   Here  are  snippets  from  two
        versions that paints  the  entire  screen  blue;  in
        BSOD2  two pixels are copied at a time, 32000 times,
        and in BSOD3 one pixel is copied  64000  times.   In
        both  cases,  the  SUB CX,1 instruction has the side
        effect of setting or  clearing  the  Z  bit  in  the
        status  register,  so  the following JNE instruction
        has the information it needs to  know  if  the  jump
        should  or should not be taken.  To make the program
        more efficient, the  SUB  CX,1  instruction  can  be
        replaced  with  DEC CX, and the ADD BX,1 instruction
        in BSOD3 can be replaced with INC BX.

	BSOD2 (two pixels at a time)
	----------------------------

		MOV	AL,BLUE		; AX := BLUE-BLUE
		MOV	AH,AL		;

		MOV	CX,32000	;
		MOV	BX,0		;
	Blue_Loop:
		MOV	[ES:BX],AX	;
		ADD	BX,2		;
		SUB	CX,1		;
		JNE	Blue_Loop	;

	BSOD3 (one pixel at a time)
	---------------------------

		MOV	AL,BLUE		; AL := BLUE

		MOV	CX,64000	;
		MOV	BX,0		;
	Blue_Loop:
		MOV	[ES:BX],AL	;
		ADD	BX,1		;
		SUB	CX,1		;
		JNE	Blue_Loop	;

------------------------------------------------------------

        The major lesson here is that there are many correct
        solutions  to  this  assignment, some more efficient
        than others (in memory, running time, or both),  but
        all are fairly short.

------------------------------------------------------------
