;This program waits for user input. if the user inputs "drawline" a line will be drawn. otherwise the program will print an error. .model small .stack 100h .data p = 9 ;maximum string support: 49 chars startp = 32000 ;x=0,y=100 line = 256 ;the length of a line is 256 pixels st_msg db 'Enter your string: ',0dh,0ah,'> $' in_str db p,0, 8 dup (0dh), '$' err_msg db 'unknown command$' dlstr db 'drawline' strlen db ? .code init: mov ax,@data mov ds,ax mov es,ax mov ax,3 int 10h lea dx,st_msg ;prints out st_msg mov ah,9 ; int 21h ; lea dx,in_str ;reads in in_str mov ah,0ah ; int 21h ; call chrfix mov cx,8 ;check the full length of the word 'drawline' = 8 chars long lea si,in_str ;insert in_str to si lea di,dlstr ;insert dlstr to di rep cmpsb ;run a comparison between the two for 8 chars, if not equal, jump to err jne err call drawline jmp done err: call newl lea dx,err_msg ;prints out err_msg mov ah,9 ; int 21h ; done: mov ah,8 ;will cause the program to hang until the user presses any key int 21h mov ah,4ch ;return control to OS int 21h ;******************* drawline: ;method that draws a line starting at startp push cx ;register backup push ax ; push di ; mov ax,0013h ;set vga mode int 10h ; mov ax,0a000h ; mov ds,ax ; mov di,startp ;starting location mov al,1 ;starting color mov cx,line ;length of line line: mov [di],al ;draw a single pixel inc al ;increase color inc di ;move 1 pixel loop line pop di ;register restore pop ax ; pop cx ; ret ;******************* chrfix:push cx ;method that fixes extra chars that stick to the beginning of a string push si ;register backup push ax ; mov al,in_str[1] ;find the length of the string mov strlen,al mov cl,strlen mov ch,0 mov si,2 fix: mov al,in_str+si ;shift all characters 2 spaces left and fill in the remaining 2 with '0dh' mov in_str+si-2,al inc si loop fix sub si,2 mov in_str+si,0dh mov in_str+si+1,0dh pop ax ;register restore pop si ; pop cx ; ret ;******************* newl: mov ah,2 ;method that moves the cursor to the next line mov dl,10 ;drop 1 line int 21h ; mov dl,13 ;go to start of line int 21h ; ret end