Вы находитесь на странице: 1из 22

;1.

substring

.model small

.data

msg1 db "Enter mainstring: $"

buff1 db 20 dup("$")

msg2 db "Enter substring: $"

buff2 db 20 dup("$")

len1 dw 0

len2 dw 0

msg db 0dh, 0ah, "Found$"

emsg db 0dh, 0ah, "Not found$"

.code

mov ax, @data

mov ds, ax

mov es, ax

mov ax, 0

mov cx, 0

lea dx, msg1

call disp

lea si, buff1

call read

mov len1, cx

lea dx, msg2

call disp

lea si, buff2

call read

mov len2, cx

mov bx, len1

sub bx, len2

inc bx

lea si, buff1


next: mov cx, len2

lea di, buff2

push si

repz cmpsb

jz found

pop si

inc si

dec bx

jnz next

lea dx, emsg

call disp

jmp ed

found: lea dx, msg

call disp

ed: mov ah, 4ch

int 21h

read proc

mov cx, 0

nxt: mov ah, 01h

int 21h

cmp al, 0dh

je done

mov [si], al

inc si

inc cx

jmp nxt

done: ret

read endp

disp proc

mov ah, 09h

int 21h
ret

disp endp

end

;2. password

.model small

.data

msg1 db "enter password: $"

buff1 db "password$"

buff2 db 20 dup("$")

len1 dw 08h

len dw 0

emsg db 0dh, 0ah, "Wrong password! try again!$"

msg db "you are authorized person$"

.code

mov ax, @data

mov ds, ax

mov es, ax

mov ax, 0

lea dx, msg1

call disp

again: lea si, buff2

call read

mov len, cx

cmp cx, len1

jnz l1

lea si, buff1

lea di, buff2

repz cmpsb

jnz l1

lea dx, msg

call disp
jmp ed

l1: lea dx, emsg

call disp

jmp again

ed: mov ah, 4ch

int 21h

read proc

mov cx, 0

next: mov ah, 01h

int 21h

cmp al, 0dh

jz done

mov [si], al

inc si

inc cx

jmp next

done: ret

read endp

disp proc

mov ah, 09h

int 21h

ret

disp endp

end

;3.Two string

.model small

.data

msg1 db "enter string1: $"


buff1 db 20 dup("$")

msg2 db "ENter string2: $"

buff2 db 20 dup("$")

len1 dw 0

len2 dw 0

msg3 db "Length1 = $"

msg4 db 0dh, 0ah, "Length2 = $"

emsg db 0dh, 0ah, "Strings are not equal$"

msg db 0dh, 0ah, "strings are equal$"

.code

mov ax, @data

mov ds, ax

mov es, ax

mov ax, 0

lea dx, msg1

call disp

lea si, buff1

call read

mov len1, cx

lea dx, msg2

call disp

lea si, buff2

call read

mov len2, cx

lea dx, msg3

call disp

mov ax, len1

call displen

lea dx, msg4

call disp

mov ax, len2


call displen

mov cx, 0

mov cx, len1

cmp cx, len2

jnz l1

lea si, buff1

lea di, buff2

repz cmpsb

jnz l1

lea dx, msg

call disp

jmp ed

l1: lea dx, emsg

call disp

ed: mov ah, 4ch

int 21h

displen proc

aam

add ax, 3030h

push ax

mov dl, ah

mov ah, 02h

int 21h

pop ax

mov dl, al

mov ah, 02h

int 21h

ret

displen endp
read proc

mov cx, 0

next: mov ah, 01h

int 21h

cmp al, 0dh

jz done

mov [si], al

inc si

inc cx

jmp next

done: ret

read endp

disp proc

mov ah, 09h

int 21h

ret

disp endp

end

;5. systime

.model small

.code

call clear

call setcur

mov ah, 2ch

int 21h

mov al, ch ; hours

call convert
mov dl, ":"

call dispch

mov al, cl ; minutes

call convert

mov dl, ":"

call dispch

mov al, dh ; seconds

call convert

mov ah, 4ch

int 21h

clear proc

mov ah, 06h

mov bh, 07h

mov cx, 0

mov dx, 0fff

int 10h

ret

clear endp

setcur proc

mov ah, 02h

mov bh, 00

mov dl, 30

mov dh, 12

int 10h

ret

setcur endp

convert proc

push cx
push dx

aam

add ax, 3030h

push ax

mov dl, ah

mov ah, 02h

int 21h

pop ax

mov dl, al

mov ah, 02h

int 21h

pop dx

pop cx

ret

convert endp

dispch proc

mov ah, 02h

int 21h

ret

dispch endp

end

;6. sysdate

.model small

.data

year dw 00

month db 0

day db 0

dweek db 0

msg db 0dh, 0ah, "$"

msg1 db "MON$"
msg2 db "TUE$"

msg3 db "WED$"

msg4 db "THUR$"

msg5 db "FRI$"

msg6 db "SAT$"

msg7 db "SUN$"

.code

mov ax, @data

mov ds, ax

mov ah, 2ah

int 21h

mov year, cx

mov month, dh

mov day, dl

mov dweek, al

mov al, day

call convert

call pslash

mov al, month

call convert

call pslash

mov ax, year

mov cl, 64h;100d

div cl; quo--al<-20; rem--ah<-19

push ax

call convert

pop ax

mov al, ah

call convert

lea dx, msg

call disp
mov al, dweek

cmp al, 01

jne l1

lea dx, msg1

jmp ed

l1: cmp al, 02

jne l2

lea dx, msg2

jmp ed

l2: cmp al, 03

jne l3

lea dx, msg3

jmp ed

l3: cmp al, 04

jne l4

lea dx, msg4

jmp ed

l4: cmp al, 05

jne l5

lea dx, msg5

jmp ed

l5: cmp al, 06

jne l6

lea dx, msg6

jmp ed

l6: lea dx, msg7

ed: call disp

mov ah, 4ch

int 21h

convert proc
aam

add ax, 3030h

push ax

mov dl, ah

mov ah, 02h

int 21h

pop ax

mov dl, al

mov ah, 02h

int 21h

ret

convert endp

pslash proc

mov dl, "/"

mov ah, 02h

int 21h

ret

pslash endp

disp proc

mov ah, 09h

int 21h

ret

disp endp

end

;7. updown counter

.model small

.code

call clear

call setcur
mov ax, 00

repeat: add ax, 01

cmp ax, 100

jz l1

push ax

call dispcnt

mov ah, 0bh

int 21h

cmp al, 0f

jz exit

call delay

call setcur

pop ax

jmp repeat

l1: sub ax, 01

cmp ax, 00

jz exit

push ax

call dispcnt

mov ah, 0bh

int 21h

cmp al, 0f

jz exit

call delay

call setcur

pop ax

jmp l1

exit: mov ah, 4ch

int 21h

clear proc
mov ah, 06

mov bh, 07

mov cx, 00

mov dx, 0fff

int 10h

ret

clear endp

setcur proc

mov ah, 02h

mov bh, 0

mov dl, 40

mov dh, 12

int 10h

ret

setcur endp

dispcnt proc

aam

add ax, 3030h

push ax

mov dl, ah

mov ah, 02h

int 21h

pop ax

mov dl, al

mov ah, 02h

int 21h

ret

dispcnt endp
delay proc

mov cx, 0fff

l2: mov dx, 0f

l: dec dx

jnz l

loop l2

ret

delay endp

end

;8. name

.model small

.data

msg1 db "Enter your name: $"

buff1 db 20 dup("$")

msg2 db "x-coordinate[0-79] : $"

msg3 db 0dh, 0ah, "y-coordinate[0-24] : $"

hex_x db 0

hex_y db 0

bcd_x dw 0

bcd_y dw 0

.code

mov ax, @data

mov ds, ax

mov es, ax

mov ax, 0

lea dx, msg1

mov ah, 09h

int 21h

lea si, buff1

call readstr
lea dx, msg2

call disp

call read

mov bcd_x, bx

mov hex_x, al

lea dx, msg3

call disp

call read

mov bcd_y, bx

mov hex_y, al

call clear

call clear

call setcur

lea dx, buff1

call disp

mov ah, 4ch

int 21h

clear proc

mov ah, 06h

mov bh, 07h

mov cx, 0

mov dx, 0fff

int 10h

ret

clear endp

setcur proc

mov ah, 02h

mov bh, 0

mov dl, hex_x


mov dh, hex_y

int 10h

ret

setcur endp

read proc

mov ah, 01h

int 21h ;al=34{4}

mov dh, al ;dh=34

mov ah, 01h

int 21h ;al=31{1}

mov ah, dh ;ax=3431{41}

mov bx, ax ;bx=3431

sub ax, 3030h ;ax=0401

aad ;al=[41]base16

ret

read endp

readstr proc

mov cx, 0

next: mov ah, 01h

int 21h

cmp al, 0dh

jz done

mov [si], al

inc si

jmp next

done: ret

readstr endp

disp proc
mov ah, 09h

int 21h

ret

disp endp

end

;9. xy coordinates

.model small

.data

msg1 db "x-coordinate[0-79] : $"

msg2 db 0dh, 0ah, "y-coordinate[0-24] : $"

hex_x db 0

hex_y db 0

bcd_x dw 0

bcd_y dw 0

.code

mov ax, @data

mov ds, ax

mov ax, 0

lea dx, msg1

call disp

call read

mov bcd_x, bx

mov hex_x, al

lea dx, msg2

call disp

call read

mov bcd_y, bx

mov hex_y, al

call clear

call clear
call setcur

mov ax, bcd_x

call dispxy

mov dl, ","

mov ah, 02h

int 21h

mov ax, bcd_y

call dispxy

mov ah, 4ch

int 21h

dispxy proc

push ax

mov dl, ah

mov ah, 02h

int 21h

pop ax

mov dl, al

mov ah, 02h

int 21h

ret

dispxy endp

clear proc

mov ah, 06h

mov bh, 07h

mov cx, 0

mov dx, 0fff

int 10h

ret

clear endp
setcur proc

mov ah, 02h

mov bh, 0

mov dl, hex_x

mov dh, hex_y

int 10h

ret

setcur endp

read proc

mov ah, 01h

int 21h ;al=34{4}

mov dh, al ;dh=34

mov ah, 01h

int 21h ;al=31{1}

mov ah, dh ;ax=3431{41}

mov bx, ax ;bx=3431

sub ax, 3030h ;ax=0401

aad ;al=[41]base16

ret

read endp

disp proc

mov ah, 09h

int 21h

ret

disp endp
end

;10. modular

displ macro m

lea dx, m

mov ah, 09h

int 21h

endm

.model small

.data

msg1 db "Enter string: $"

buff1 db 20 dup("$")

msg2 db "String is :$"

.code

include C:\Tasm\f1.mac

include C:\Tasm\f2.mac

mov ax, @data

mov ds, ax

displ msg1

lea si, buff1

mov cx, 0

next: read_ch

cmp al, 0dh

je done

mov [si], al

inc si

inc cx

jmp next

done: displ msg2

lea si, buff1

l1: mov dl, [si]


dispch

inc si

loop l1

mov ah, 4ch

int 21h

end

Вам также может понравиться