s

8086 print string by writing directly to video memory edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 07 September 2020 | 3592

You would be familiar with dos interrupt 21h function 09h to write a string to standard output which is your monitor. In this article, we will write an 8086 assembly language program to write directly to video memory b800h.

To write directly to the screen without using an interrupt you have to write to segment 0xb800h and offset 0. There are two bytes for every character on the screen. Character to display followed by the character attributes.

To display a character 'a' on the screen top, left

0xb800:0x0000 :  0x41         ; 0x41 is hex for ascii character 'a'
0xb800:0x0001 :  0x40         ; Red background, black foreground              
                    

check this article for ASCII character set table. 8086 ascii table

8086 code to write 'Hello World' directly to memory

----------------------------------------
Program  : Write Directly to Video Memory 
FileName : DisplayText.asm
I/P 	 : Nill
O/P 	 : Displays Hello Mem
By       : Murugan AD 
----------------------------------------

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

main proc near
  mov ax,b800h
  mov es,ax
  mov mov ax,offset message 		; offset ofMessage string terminating with $
  mov si,ax                             ; Make Si point to string address
  mov di,0                              ; Make Destination Index point to B800:0000
loop1:
  mov al,[si]				; Read First Character
  mov es:[di],al                        ; Write to Video
  inc si                                ; Point to next character
  inc di
  inc di                                ; Next Display Area
  cmp al,'$'
  jne loop1                             ; if not '$' jump to loop1 				
 
  mov ah,4ch               		; function to terminate
  mov al,00
  int 21h  		   		; Dos Interrupt 
endp 
message db "Hello World $"		; Message to be displayed terminating with a $
end main
            
                    

Generate executable using

tasm filename.asm
tlink /t filename