Title Intro. to assembly programming
thecode segment para public 'code'
assume cs:thecode, ds:thedata, ss:thestack
start: mov ax,thedata
mov ds,ax ;set data segment
;**************************** Password **********************************
prompt1:lea dx,ask1 ;prompt user for
mov ah,9h ;first character
int 21h
read1: mov ah,1h ;read character
int 21h
copy1: mov valuea,al ;keep copy
mov dl,cr
mov ah,2h ;output return character
int 21h
mov dl,lf ;output line feed character
mov ah,2h
int 21h
prompt2:lea dx,ask2 ;prompt use for
mov ah,9h ;second character
int 21h
read2: mov ah,1h ;read character
int 21h
copy2: mov valueb,al ;keep copy
mov dl,cr
mov ah,2h ;output return character
int 21h
mov dl,lf ;output line feed
mov ah,2h
int 21h
mov dl,cr
mov ah,2h ;output return
int 21h
mov dl,lf ;output line feed
mov ah,2h
int 21h
mov al,valuea
check: cmp al,pass1
wrong: jne prompt1
check2: mov al,valueb
cmp al,pass2
wrong1: jne prompt1
clear: mov ax,clrscr ;clear screen
int 10h ;80x25 chars
answer: lea dx,answer1 ;output result
mov ah,9h
int 21h
;**************************** Main **********************************
;******* Heading *********
headin: mov dh,5 ;row
mov dl,27 ;column
mov bh,0 ;page
mov ah,poscur ;move
int 10h ;cursor
lea dx,head ;output heading
mov ah,outstr
int 21h
mov row,7
;******* Box Check *********
boxcheck:
mov dx,boxin ;get state of switches
in al,dx
mov state,al
and al,00110000b
;******* Off? *********
choff:
cmp al,00000000b ;Checks to see if both switches are off
je msgoff ;jumps to the off message section
jmp chdefrost
msgoff: mov dh,row ;row
mov dl,30 ;column
mov bh,0 ;page
mov ah,poscur ;move
int 10h ;cursor
lea dx,msgmicroff ;Outputs Off message
mov ah,outstr
int 21h
mov dx, boxout ;address of box
mov al,01001001b ;three lamps on
OUT dx, al ;send to lamps
jmp chdefrost
;******* Defrost? *********
chdefrost:
cmp al,00010000b ;Checks if spst2 is on
je msgdef ;Jumps to the defrost message section
jmp chlow
msgdef: mov dh,row ;row
mov dl,30 ;column
mov bh,0 ;page
mov ah,poscur ;move
int 10h ;cursor
lea dx,defrost ;Outputs defrost message
mov ah,outstr
int 21h
mov dx,boxout
mov al,0
out dx,al
mov al,20
call d120
mov dx, boxout ;address of box
mov al,10100100b ;three lamps on
OUT dx, al ;send to lamps
mov al,20 ;wait again
CALL d120
jmp chlow
;******* Low power? *********
chlow:
cmp al,00100000b ;Checks if spst1 is on
je msglow ;jumps to the low power messag section
jmp chmedium
msglow: mov dh,row ;row
mov dl,30 ;column
mov bh,0 ;page
mov ah,poscur ;move
int 10h ;cursor
lea dx,lowcook ;Outputs Low power message
mov ah,outstr
int 21h
mov dx,boxout
mov al,0
out dx,al
mov dx, boxout ;address of box
mov al,00000001b ;three lamps on
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al,00000010b
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al,00000100b
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al,00001000b
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al,00010000b
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al,00100000b
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al,01000000b
OUT dx, al
mov al,20
call d120
mov dx, boxout
mov al, 10000000b
OUT dx, al
jmp chmedium
;******* Medium power? *********
chmedium:
cmp al,00110000b
je msgmed
jmp akey
msgmed: mov dh,row ;row
mov dl,30 ;column
mov bh,0 ;page
mov ah,poscur ;move
int 10h ;cursor
lea dx,msgmedium ;Outputs medium message
mov ah,outstr
int 21h
mov dx,boxout
mov al,0
out dx,al
mov dx, boxout ;address of box
mov al, 00000011b ;6+7
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 00000110b
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 00001100b
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 00011000b
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 00110000b
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 01100000b
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 11000000b
OUT dx, al
mov al,10
call d120
mov dx, boxout ;address of box
mov al, 10000001b
OUT dx, al
mov al,10
call d120
jmp akey
;**************************** Check for keypress **********************************
akey: mov ah,keypres ;check if keypressed
mov dl,0ffh
int 21h
jnz exit
jmp boxcheck ;no key pressed
;**************************** Exit **********************************
exit: mov ax,4c00h ;return to DOS
int 21h ;gracefully
;**************************** Light Delay **********************************
d120 proc ; delay al * 1/20th second
push ax ; save registers
push bx
push cx
push dx
pushf
push ax
tock: mov ah,2ch ;get initial time
int 21h
mov bx, dx
tick: mov ah,2ch
int 21h ;get time again
cmp bx, dx
je tick ;clock not advanced 1/20th
pop ax
dec al ;one more 1/20th elapsed
push ax
jne tock
pop ax
popf
pop dx ;restore registers
pop cx
pop bx
pop ax
ret
d120 endp
thecode ends