BITS 16 ORG 100h ; This program will draw a multi-colored diagonal line in VGA mode ; It also illustrates procedure CALL and RET. ; I've also used BIOS interrupt 15h to insert a real time delay ; of approximately 1/10 sec. before drawing each point. ; Press a key at the start and end. START MOV AX,0x0013 ;1 start VGA mode with BIOS interrupt 10h INT 10h ;1 CALL KEYD ; keydelay before starting MOV DI,0xA000 ;2 set video memory location MOV ES,DI ; ES can't be stored to with immediate values XOR DI,DI ;2 (resets di to 0) MOV CX,40 ; init X cordinate MOV DX,5 ; init Y cord. LOOP0 MOV AL,DL ; set color according to y cord AND AL,0x0F ; only 16 colors are used (256 are valid) CALL PLOT ; plot point CALL DELAY ; real time delay between points INC DX ;2a change x and y cords. INC CX ;2a CMP DX,170 ; end when y cord = 170 JNE LOOP0 ; Jump if not equal JMP ENDPROG ; The ENDPROG procedure waits for a keystroke, restores text mode ; 03h and quits: ENDPROG CALL KEYD MOV AX,0x0003 ;3 reset to text mode INT 10h ;3 INT 20h ; end program ; The KEYD procedure waits for user to press a key KEYD push ax ; save ax register mov ah,1 ; DOS int 21h function for keyboad input int 21h pop ax ; restore ax register before return ret ; return (restores old IP) ; the PLOT procedure plots a point in VGA mode 13h ; It takes y cord in dx, x cord in cx and color in al as args. ; It assumes ES=a000h. The DX register needs to be saved ; because it's used in 16-bit multiplication: PLOT push di ;4 save registers push dx push ax ;4 mov ax,320 ;5 compute y cord (320=vga horizontal resolution) mul dx ;5 mov di,ax ;6 compute x cord add di,cx ;6 pop ax ; color in al register stosb ; write to video RAM pop dx pop di ret ; The DELAY procedure uses BIOS interrupt 15h, function 86h to ; allow the process to suspend itself for a number of ; microseconds (approx) as determined by cx:dx (the registers are ; used as one 32 bit value). After the time has expired, the ; process will be resumed (assuming the operating system is not doing ; something else of higher priority). The value for cx:dx is ; stored in the Hitime and Lowtime locations. DELAY push ax ;6a save registers to be used push cx push dx ;6a mov cx,[Hitime] ;7 cx:dx = # of microseconds mov dx,[Lotime] ;7 mov ah,86h ; indicates 86h function of int 15h int 15h ; BIOS interrupt, suspends current process pop dx ;8 restore registers and return pop cx pop ax ret ;8 Hitime dw 0x0001 ;9 Hitime:Lotime = 1/10 seconds (approx). Lotime dw 0x8000 ;9