Sie sind auf Seite 1von 7

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 wrong 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

1
lea si,password
lea di,entered
mov cl,4 ;limit cx=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 ;Function # 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

2
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:

True

Code:
.model small
.stack 100h

3
.data
msg db 'BDEFg$'

.code
main proc
mov ax,@data
mov ds,ax
lea si,msg

mov cx,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, no increment
inc bl ;both conditions Ok the increment

end:
loop inrange
mov ah,2
mov dl,bl
add dl,30h
int 21h
mov ah,4ch
int 21h
main endp
end main

4
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,‘ ‘ ;spacebar
int 21h
loop label1

main endp
end main

5
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

6
Lab 06: Logical Operations

OBJECTIVE
To learn the basic ‘logic commands’ and their use.
Command Addressing Description
Format
Logical AND between all bits of two operands.
REG, memory
Result is stored in operand1.
memory, REG
Example:
REG, REG
AND mov al,'a' ;61h=97d =01100001b
memory,
AND al,11011111b ;=223d
immediate mov ah,2
REG, immediate mov dl,al ;ASCII for 'A' is 65d=41h=01000001b
int 21h

Logical OR between all bits of two operands. Result


REG, memory is stored in first operand.
memory, REG Example:
REG, REG mov al,'A' ; ASCII for 'A' is 65d=41h=01000001b
OR
memory, OR al,00100000b ;=32d
mov ah,2
immediate
mov dl,al ;ASCII for 'a' is 97d=61h=01100001b
REG, immediate int 21h

Logical XOR (Exclusive OR) between all bits of


two operands. Result is stored in first operand.
REG, memory
memory, REG Example:
mov al,00000111b
REG, REG
XOR XOR al, 00000010b
memory, mov ah,2
immediate mov dl,al ;AL = 0000_0101b = 5d
REG, immediate add dl,30h
int 21h

< The End >

Das könnte Ihnen auch gefallen