35baiASM-13...25
;phamtuan_hp89
;bai 13; tim so lon hon
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'tim so lon hon$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap 2 so tu nhien:$'
tb2 db 10,13,'n1 = $'
n1 dw 0
tb3 db 10,13,'n2 = $'
n2 dw 0
tb4 db 10,13,'so lon nhat : $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
printst tb2
call scannum
mov n1,ax
printst tb3
call scannum
mov n2,ax
printst xdong
printst tb4
mov ax,n1
cmp ax,n2
ja inn1
jmp inn2
inn1:
mov ax,n1
call printnum
jmp endin
inn2:
mov ax,n2
call printnum
jmp endin
endin:
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
ret
scannum endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
ret
printnum endp
;phamtuan_hp89
;bai 14: kiem tra hieu 2 so, tri tuyet doi < 10 thi in ra man hinh
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
n1 dw ?
n2 dw ?
h dw ?
tenct db 10,13,'kiem tra hieu 2 so, tri tuyet doi < 10 thi in ra man hinh$'
xdong db 10,13,'$'
pkey db 10,13,'Press any key to exit ... $'
tb1 db 0ah,0dh,'Nhap a = $'
tb2 db 0ah,0dh,'Nhap b = $'
tb3 db 0ah,0dh,'a - b = $'
tb4 db 0ah,0dh,'tri tuyet doi cua hieu > 9$'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
call scannum
mov n1,ax
printst tb2
call scannum
mov n2,ax
printst xdong
;kiem tra hieu
mov ax,n1
cmp ax,n2
jb n2lon
jmp n1lon
n1lon:
mov ax,n1
sub ax,n2
mov h,ax
jmp endss
n2lon:
mov ax,n2
sub ax,n1
mov h,ax
jmp endss
endss:
mov ax,h
cmp ax,9
ja koinhieu
printst tb4
mov ax,h
add ax,'0'
mov dx,ax
mov ah,2
int 21h
jmp endhieu
koinhieu:
printst tb4
endhieu:
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
ret
scannum endp
;phamtuan_hp89
;bai 15,16,17,18: nhap n < 65536, in n ra man hinh o dang 10,2,16,8
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
printnum macro n,coso,pushstack,popstack,af,endd
mov ax,n
mov cx,0
pushstack:
xor dx,dx
mov bx,coso
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
cmp dx,9
ja AF
add dl,'0'
int 21h
jmp endd
AF:
add dl,55
int 21h
endd:
loop popstack
endm
.data
tenct db 10,13,'nhap n < 65536, in n ra man hinh$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap n = $'
n dw 0
tb2 db 10,13,'Co so 10:',9,'$'
tb3 db 10,13,'Co so 2: ',9,'$'
tb4 db 10,13,'Co so 16:',9,'$'
tb5 db 10,13,'Co so 8: ',9,'$'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
call scannum
mov n,ax
printst xdong
printst tb2
mov ax,n
printnum n,10,pus10,pos10,af10,endd10
printst xdong
printst tb3
printnum n,2,pus2,pos2,af2,endd2
printst xdong
printst tb4
printnum n,16,pus16,pos16,af16,endd16
printst xdong
printst tb5
printnum n,8,pus8,pos8,af8,endd8
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
ret
scannum endp
;phamtuan_hp89
;bai 19 + 20 :Co xau s1, xau s2 chua chu in hoa cua s1, s3 la s1 dao nguoc
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'Co xau s1, xau s2 chua chu in hoa cua s1, s3 la s1 dao nguoc$'
xdong db 10,13,'$'
tb1 db db 10,13,'nhap s1:$'
s1 db 70 dup(70)
l dw 0
tb2 db 10,13,'s2:$'
s2 db 70 dup(70)
tb3 db 10,13,'s3:$'
s3 db 70 dup(70)
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s1
printst tb1
lea bx,s1
dockt:
mov ah,1
int 21h
cmp al,13
je enddockt
cmp al,8
je xoa
mov [bx],al
inc bx
inc l
mov ax,l
cmp ax,69
je enddockt
jmp dockt
xoa:
dec bx
mov [bx],0
dec l
jmp dockt
enddockt:
mov [bx],'$'
printst xdong
printst s1
;xu ly s2
lea si,s1
lea di,s2
naps2:
cmp [si],'$'
je endnaps2
cmp [si],'a'
jb naptiep
cmp [si],'z'
ja naptiep
mov al,[si]
sub al,32
mov [di],al
inc si
inc di
jmp naps2
naptiep:
mov al,[si]
mov [di],al
inc si
inc di
jmp naps2
endnaps2:
mov [di],'$'
printst tb2
printst xdong
printst s2
;xu ly s3
lea si,s1
lea di,s3
mov ax,l
add di,ax
mov [di],'$'
dec di
naps3:
cmp [si],'$'
je endnaps3
mov al,[si]
mov [di],al
inc si
dec di
jmp naps3
endnaps3:
printst tb3
printst xdong
printst s3
printst xdong
;press any key
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 21 + 22 : cho 2 xau s1,s2. kiem tra s1,s2 co bang nhau khong, co doi xung ko
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'kiem tra s1,s2 co bang nhau or doi xung ko$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap 2 xau$'
tb2 db 10,13,'s1:$'
s1 db 70 dup(0)
l1 dw 0
tb3 db 10,13,'s2:$'
s2 db 70 dup(0)
l2 dw 0
cobang db 10,13,'s1,s2 bang nhau$'
kobang db 10,13,'s1,s2 khong bang nhau$'
codoi db 10,13,'s1,s2 doi xung nhau$'
kodoi db 10,13,'s1,s2 khong doi xung nhau$'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
printst tb1
;nap s1
printst tb2
lea si,s1
naps1:
mov ah,1
int 21h
cmp al,13
je endnaps1
mov [si],al
inc l1
inc si
mov ax,l1
cmp ax,69
je endnaps1
jmp naps1
endnaps1:
mov [si],'$'
printst xdong
printst s1
;nap s2
printst tb3
lea si,s2
naps2:
mov ah,1
int 21h
cmp al,13
je endnaps2
mov [si],al
inc l2
inc si
mov ax,l2
cmp ax,69
je endnaps2
jmp naps2
endnaps2:
mov [si],'$'
printst xdong
printst s2
printst xdong
;kiem tra bang nhau
mov ax,l1
cmp ax,l2
jne kbang
cmp ax,l2
jne kdoi
lea si,s1
lea di,s2
ktbang:
mov al,[si]
cmp al,'$'
je bang
cmp al,[di]
jne kbang
inc si
inc di
jmp ktbang
bang:
printst cobang
jmp endktbang
kbang:
printst kobang
jmp endktbang
endktbang:
;kiem tra doi xung
lea si,s1
lea di,s2
add di,l2
dec di
ktdoi:
mov al,[si]
cmp al,'$'
je doi
cmp al,[di]
jne kdoi
inc si
dec di
jmp ktdoi
doi:
printst codoi
jmp endktdoi
kdoi:
printst kodoi
jmp endktdoi
endktdoi:
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
;phamtuan_hp89
;bai 23 + 24 + 25 : nhap xau s,in do dai, den chu so trong s, lay xau con tu vi tri i, n ky tu
.model small
.stack 100h
printst macro tb
lea dx,tb
mov ah,9
int 21h
endm
.data
tenct db 10,13,'nhap xau s,in do dai, den chu so trong s, lay xau con tu vi tri i, n ky tu$'
xdong db 10,13,'$'
tb1 db 10,13,'nhap s:$'
s db 70 dup(0)
l dw 0
tb2 db 10,13,'do dai:$'
tb3 db 10,13,'so ky tu so trong s:$'
d dw 0
tb4 db 10,13,'Nhap vi tri bat dau i= $'
i dw 0
tb5 db 10,13,'Nhap do dai xau con n= $'
n dw 0
sc db 50 dup(0)
tb6 db 10,13,'Xau con : $'
pkey db 10,13,'Press any key to exit ... $'
.code
main proc
mov ax,@data
mov ds,ax
mov es,ax
printst tenct
printst xdong
;nhap s
printst tb1
lea bx,s ;
dockt:
mov ah,1
int 21h
cmp al,13
je enddockt
mov [bx],al
inc bx
inc l
mov ax,l
cmp ax,69
je enddockt
jmp dockt
enddockt:
mov [bx],'$'
printst xdong
printst s
printst xdong
printst tb2
mov ax,l
call printnum
printst xdong
;den ky tu so trong s
lea si,s
dec si
dem:
inc si
mov al,[si]
cmp al,'$'
je enddem
cmp al,'0'
jb dem
cmp al,'9'
ja dem
inc d
jmp dem
enddem:
;in so ky tu so
printst tb3
mov ax,d
call printnum
printst xdong
;nhap i,n
nhapi:
printst tb4
call scannum
cmp ax,l
ja nhapi
mov i,ax
nhapn:
printst tb5
call scannum
mov bx,l
sub bx,i
cmp ax,bx
ja nhapn
mov n,ax
;lay xau con
lea si,s
lea di,sc
add si,i
mov cx,n
rep movsb
mov [di],'$'
printst xdong
printst tb6
printst sc
;press any key
printst xdong
lea dx,pkey
mov ah,9
int 21h
mov ah,1
int 21h
mov ah,4ch
int 21h
main endp
printnum proc
mov cx,0
pushstack:
xor dx,dx
mov bx,10
div bx ;thuong luu vao ax,du luu vao dx
push dx
inc cx
cmp ax,0
jne pushstack
mov ah,2
popstack:
pop dx
add dl,'0'
int 21h
loop popstack
ret
printnum endp
scannum proc
xor bx,bx
xor cx,cx
xor dx,dx
nhap:
mov ah,1
int 21h
cmp al,13
je endnhap
cmp al,'0'
jb endnhap
cmp al,'9'
ja endnhap
sub al,'0'
mov bl,al
mov ax,cx
mov dx,10
mul dx
add ax,bx
mov cx,ax
jmp nhap
endnhap:
mov ax,cx
ret
scannum endp
Bạn đang đọc truyện trên: Truyen247.Pro