8086 assembly language program to split the screen into two colors left green right blue edit button Edit

Murugan Andezuthu Dharmaratnam | calendar 10 July 2021 | 1578

Write an assembly language program to color the entire screen into two halves. upon running the program the left half of the screen will become green when the space bar key is pressed. when the space bar key is released the right side becomes blue. The program terminates when enter key is pressed.

8086 Assembly Language Program

.model tiny  		  		; com program
.code			  		; code segment
org 100h		  		; code starts at offset 100h	

main proc near

  mov ah,00h  ; function to Read character from keyboard
  int 16h     ; keyboard interrupt 16h, output stored in al

  cmp al,0dh  ; check if enter key is pressed
  je exit   

  cmp al,20h  ; check if space bar is pressed
  jne loopmain   
  cmp leftright,0   
  je left

  mov leftcolor,0
  mov rightcolor,1
  call splitscreen 
  mov leftright,0
  jmp loopmain
  mov leftcolor,2
  mov rightcolor,0
  call splitscreen 
  inc leftright

  jmp loopmain

  mov ah,4ch               		; function to terminate
  mov al,00
  int 21h  		   		; Dos Interrupt 

splitscreen proc near
  mov ax,0xb800h
  mov es,ax
  mov di,0                              ; Make Destination Index point to B800:0000
  mov cx,50
  mov bx,0 
  mov al,0xdbh				
  mov es:[di],al                        ; Write to Video
  inc di
  cmp bx,39d
  jg right 
  mov dl,leftcolor
  mov es:[di],dl
  jmp next

  mov dl,rightcolor 
  mov es:[di],dl
  cmp bx,79d
  jl next:
  mov bx,00h
  jmp next2:
  inc bx
  inc di                                ; Next Display Area
  loop loop1

leftcolor db  0
rightcolor db 0
leftright db 0

end main

The program works by writing the character 0xdbh which is the full white block from the character table to the memory. Here we write directly to the video memory b800h. when you write to b800h the first is the character to write the second is the color code of the character. Try this sample code

.model tiny  		  		; com program
.code			  		; code segment
org 100h		  		; code starts at offset 100h	

main proc near
    mov ax,0xb800h
    mov es,ax
    mov es:00,'A'
    mov es:01,3   
    mov es:02,'B'
    mov es:03,4   
    mov ah,4ch
    mov al,00
    int 21h

end main

In the above sample code we are displaying only two characters A followed by B. We are doing this by directly writing to the video segment 0xb800h. offset 00 we are writing character A, then 01 we are writing the color of the character. followed by B and color or B. This is the same technique I am using in the above code.