Vous êtes sur la page 1sur 13

FACULTY OF ENGINEERING,

UNIVERSITI MALAYSIA SABAH

HK20: ELECTRONIC (COMPUTER) ENGINEERING

KS21604: MICROPROCESSOR

SEMESTER 2(2018/2019)

LAB 6
Name of lecturer: Dr. Jamal Ahmed Dargham
Group 10

Group Members:
Name Matric No.
Mark Irwin Goh BK16160277
Zur Ain Mohd Arsad BK16110216
Experiment #1

FLOW CHART:

START

Display “Enter
your string“

Input string1

Display “The number of times


the letter ‘a’ in the string is”

X=0

Num1=0

no yes
Is string[x] Is string1[x] Num1=
enter key? have ‘a’? Num1+1

yes no

X=x+1
Output num1

END
SOURCE CODE:

.model small

.stack 200h

.data

string1 db 200,201 dup(?)

msg1 db 10,13, "Enter your string $"

answer1 db 3 dup('$')

msg2 db 10,13, "The number of times the letter 'a' in the string: $"

.code

start:

mov ax, seg msg1

mov es, ax

mov ds, ax

mov ah, 09

mov dx, offset msg1

int 21h

mov ah, 0ah

mov dx, offset string1

int 21h

mov ah, 09

mov dx, offset msg2

int 21h

mov cl, string1[1]

mov ch, 0
inc cx

mov al, 'a'

cld

mov di, offset string1

mov di, 2

mov bx, 0

again:

repne scasb

cmp cx, 0

je done

inc bx

jmp again

done:

mov ax, bx

aam

add ax, 3030h

mov answer1, ah

mov answer1[1], al

mov ah, 09

mov dx, offset answer1

int 21h

done1:

.exit

end start
OUTPUT:
Experiment #2

FLOW CHART

START

Display “Enter your letter to find how many of it in the string“

Input char1

Display “Enter your string”

Input string1

yes
If no Display “Error:no string”
string1

no
yes
If no
Display “Error:no letter”
char1

no

yes
If char1
Display “Error:wrong letter”
letter

yes

Input char1

Display “in the string is”

x=0

Num1=0
no yes

Is string1[2] Is string1[2]
Num1=
enter key? have char1?
Num1+1

Output num1
X=x+1
yes

END
SOURCE CODE:

.model small

.stack 200h

.data

string1 db 200,201 dup(?)

msg0 db 10,13, "Enter your letter to find how many of it in the string $"

char1 db 2,3 dup(?)

msg1 db 10,13, "Enter your string $"

answer1 db 3 dup('$')

msg3 db 10,13, "Error: no string $"

msg4 db 10,13, "Error: no letter $"

msg5 db 10,13, "Error: wrong letter $"

msg2 db 10,13, "The number of times the letter -$"

msg6 db "- in the string is: $"

new1 db " "

.code

start:

mov ax, seg msg0

mov es, ax

mov ds, ax

mov ah,09

mov dx, offset msg0

int 21h
mov ah, 0ah

mov dx, offset char1

int 21h

mov ah,09

mov dx, offset msg1

int 21h

mov ah, 0ah

mov dx, offset string1

int 21h

cmp string1[2],0dh

je fin2

none1:

cmp char1[2],0dh

je fin3

none2:

cmp string1[2],0dh

je fin4

cmp char1[2],0dh

je fin5

cmp char1[2],41h
jb fin6

cmp char1[2],5Ah

ja may1

jmp begin1

may1:

cmp char1[2],61h

jb fin6

cmp char1[2],7Ah

ja fin6

jmp begin1

fin2:

mov ah,09

mov dx,offset msg3

int 21h

jmp none1

fin3:

mov ah,09

mov dx,offset msg4

int 21h

jmp none2

fin4:

jmp done1
fin5:

jmp done1

fin6:

mov ah,09

mov dx,offset msg5

int 21h

jmp done1

begin1:

mov cl,string1[1]

mov ch,0

inc cx

mov al, char1[2]

cld

mov di, offset string1

mov di,2

mov bx,0

again:

repne scasb

cmp cx,0

je done

inc bx

jmp again
done:

mov ah,09

mov dx, offset msg2

int 21h

mov ah,06

mov dl,char1[2]

int 21h

mov ax,bx

aam

add ax,3030h

mov answer1, ah

mov answer1[1],al

mov ah,09h

mov dx, offset msg6

int 21h

mov dx, offset answer1

int 21h

done1:

.exit

End start
OUTPUT:

Vous aimerez peut-être aussi