Pages

Friday, March 25, 2011

Sample program in assembly language using a86.com (4)

A program that will print ASCII characters on screen w/ the ff. conditions:
--if the cursor passes letter R or r; the ascii will become red
--if the cursor passes letter B or b; the ascii will become blue
--if the cursor passes letter G or g; the ascii will become green
--if the cursor passes letter L or l; the ascii will blink
and the color will be combined if the cursor passes another letter with the corresponding color above....( the cursor will be set at the center of the screen; it will move using letters w-up;s-down;d-right;a-left)


.model small
.code
org 100h
jmp main


asc db 00,'$'
row db 08
col db 39
temp db 00


main proc near
call clr
mov ah, 03h
int 10h


ascii:
mov dx, 0100h
call setcur


mov cx, 1024
lea dx, asc


again:
mov ah, 09h
int 21h
inc asc
loop again


center:
mov dh, row
mov dl, col
call setcur


key:
mov dh, 07h
int 21h
cmp al, 'w'
if e jmp up
cmp al, 's'
if e jmp down
cmp al, 'd'
if e jmp right
cmp al, 'a'
if e jmp left
cmp al, 'x'
if e jmp exit
jmp key


up:
dec row
cmp row, 00
if e jmp down
call read
jmp center


down:
inc row
cmp row, 24
if e jmp up
call read
jmp center


right:
inc col
cmp col, 79
if e jmp left
call read
jmp center


left:
dec col
cmp col, 00
if e jmp right
call read
jmp center


terminate:
int 20h


setcur proc near
mov ah, 02
mov bh, 00
int 10h
ret
setcur endp


read proc near
mov ah, 08h
mov bh, 00
int 10h


cmp al, 'r'
if e jmp red
cmp al, 'R'
if e jmp red
cmp al, 'b'
if e jmp blue
cmp al, 'B'
if e jmp blue
cmp al, 'g'
if e jmp green
cmp al, 'G'
if e jmp green
cmp al, 'l'
if e jmp blink
cmp al, 'L'
if e jmp blink


red:
add temp, 04
call color
jmp ascii


blue:
add temp, 01
call color
jmp ascii


green:
add temp, 02
call color
jmp ascii


blink:
add temp, 80h
call color
jmp ascii


read endp


color proc near
mov ah, 06
mov al, 00
mov bh, temp
mov cx, 0000h
mov dx, 184fh
int 10h
ret
color endp


clr proc near
mov ah, 06h
mov al, 00
movbh, 07h
mov cx, 0000h
mov dx, 184fh
int 10h
ret
clr endp

1 comments:

Anonymous said...

????

Post a Comment