Lab 05: ‘Assembly’ Application Programs
OBJECTIVE
To learn to write the following application codes:
1. Password protected application, used to sign-in to a computer.
2. Count the capital characters in a defined string.
3. Display the characters in a string in diagonal form.
4. Count the ‘Even’ numbers in an entered string.
1. Code 01: ‘Password protected application’, used to sign-in to a computer.
Hints:
· Initialize a 5-digit password e.g. ‘12345$’ in a db. (.data)
· Use function # 8, to hide password input on run time.
· Use function # 2, to display ‘*’ or ‘.’ In place of password.
· Take a string at input and ‘cmp’ both strings location by location.
· Two ways of termination when a wring password is entered.
i) Any key mismatch (terminate). ii) At the end of string input
Code:
include 'emu8086.inc'
.model small
.stack 100h
.data
password db 'A$'
entered db '?'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
lea si,password
lea di,entered
mov cl,4 ;limit 4 character password only
mov dl,0
print 'Enter password'
mov ah,2
mov dl,0ah
int 21h
mov dl,0dh
int 21h
input:
mov ah,8 ;mov ah,8 hides character input at run time
int 21h
cmp al,[si] ;compare input to stored password
jne end ;terminate if not equal
je login ;if password match go to login
mov [di],al ;store the input password to DI
inc si ;to compare to new character
inc di ;to input new character
loop input ;run the for password input
jmp login
end:
mov dl,'*' ;display '*' as password input
mov ah,2
int 21h
mov ah,2 ;new line code
mov dl,0ah
int 21h
mov dl,0dh
int 21h
print 'Wrong password'
jmp finish
login:
mov dl,'*' ;display '*' as password input
mov ah,2
int 21h
mov ah,2 ;new line code
mov dl,0ah
int 21h
mov dl,0dh
int 21h
print 'Login succesful'
finish:
main endp
end main
2. Code 02: Count the ‘Capital characters’ in a defined string.
Hints: (see flowchart below)
· E.g. the string ‘BDEFg$’
· ‘cmp’ to check if a letter falls in range of capital letters
· From A to Z (true) if ‘A = 41h to Z = 5Ah’.
· Use ‘Jge’ & ‘Jle’ if in range.
Flowchart for Code-2:


Code:
.model small
.stack 100h
.data
msg db 'BDEFg$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,msg
mov cl,5 ;length of string except $
mov bl,0 ;set character count to zero
inrange: ;check if character falls in-ragne
mov al,[si]
inc si ;next character in string
cmp al,41h ;code for 'A'
jge range ;if character is >= 41h
; end ;else end
range: ;check if character falls above ‘Z’
cmp al,5ah ;value for 'Z'
jg end ;end if value is greater than Z
inc bl ;both conditions Ok the increment
loop inrange
end:
mov ah,2
mov dl,bl
add dl,30h
int 21h
mov ah,4ch
int 21h
main endp
end main
3. Code 03: Display the characters in a string in diagonal form.
Flowchart:

Code:
.model small
.stack 100h
.data
msg db 'abcde$'
.code
main proc
mov ax,@data
mov ds,ax
lea si,msg
mov cx,5
label1:
mov ah,2
mov dl,[si]
int 21h
inc si
mov dl,0ah ;new line
int 21h
; mov dl,0dh ;backspace
int 21h
loop label1
main endp
end main
4. Code 04: Count the ‘Even’ numbers in an entered string.
.model small
.stack 100h
.data
.code
main proc
mov cl,0
even:
mov ah,1
int 21h
cmp al,0dh ;enter key
je display
cmp al,30h ;'0'
je counter
cmp al,32h ;'2'
je counter
cmp al,34h ;'4'
je counter
cmp al,36h ;'6'
je counter
cmp al,38h ;'8'
je counter
jne even
counter:
inc cl
jmp even:
display:
mov ah,2
mov dl,0ah ;new line
int 21h
mov dl,0dh
int 21h
mov ah,2
mov dl,cl
add dl,30h
int 21h
main endp end main
Lab 06: Logical Operations
OBJECTIVE
To learn the basic ‘logic commands’ and their use.
|
Command
|
Addressing Format
|
Description
|
|
AND
|
REG, memory
memory, REG REG, REG memory, immediate REG, immediate |
Logical AND between all bits of two operands. Result is stored in operand1.
Example:
mov al,'a'
AND al,11011111b ;=223d
mov ah,2
mov dl,al ;ASCII for 'A' is 65d=41h
|
|
OR
|
REG, memory
memory, REG REG, REG memory, immediate REG, immediate |
Logical OR between all bits of two operands. Result is stored in first operand.
Example:
mov al,'A'
OR al,00100000b ;=32d
mov ah,2
mov dl,al ;ASCII for 'a' is 97d=61h
int 21h
|
|
XOR
|
REG, memory
memory, REG REG, REG memory, immediate REG, immediate |
Logical XOR (Exclusive OR) between all bits of two operands. Result is stored in first operand.
Example:
mov al,00000111b
XOR al, 00000010b
mov ah,2
mov dl,al ;AL = 00000101b = 5d
add dl,30h
int 21h
|
< The End >