Sunteți pe pagina 1din 13

-1.model small .stack 100h .

code first proc mov dl,65 mov ah,02 int 21h mov dl,'b' int 21h mov ax,4c00h int 21h first endp end first ============================================= .model small .stack 100h .code main proc mov cx,26 mov dl, 65 mov ah,2 abc: int 21h inc dl loop abc mov ax,4c00h int 21h main endp end main ============================================= .model small .stack 100h .data xyz db "KUDCS",0dh,0ah,"$" .code main proc mov ax, @data mov ds, ax mov ah, 9 mov dx, offset xyz int 21h mov ax, 4c00h int 21h main endp end main ============================================= ;; This program displays the following sequence: ;; AaBbCcDdEe........Zz ;; .model small .stack 100h .code main proc mov cx,26 ; or mov cx,1ah mov bl,41h ; Code for 'A' mov bh,61h ; Code for 'a' mov ah,2 lbl1: mov dl,bl int 21h mov dl,bh int 21h inc bl inc bh loop lbl1 mov ax,4c00h int 21h main endp end main ============================================= ;; This program shows number on screen but single digit number ;; This program is not for multiple digit numbers .model small .stack 100h .data arr1 dw 2h,3h,4h,5h,9h .code main proc mov ax,@data mov ds,ax mov cx,5 mov si,0 zcopy: mov bx,offset arr1 mov dh,0 mov dl,[bx+si] add dl,30h mov ah,02 int 21h inc si inc si loop zcopy mov ax,4c00h int 21h main endp end main ============================================= title program to show decimal no. on screen .model small .stack 100h .code main proc mov cx,635 mov ax,cx mov bx,10 mov dx,0 mov cx,0 loop1: div bx push dx mov dx,0 inc cx cmp ax,0 jnz loop1 loop2: pop dx add dx,30h mov ah,2 int 21h loop loop2 mov ax,4c00h int 21h main endp end main ============================================= ;; Display the contents of a register in binary no. format ;; OR ;; Display the bit patterns of the contents of a register .model small .stack 100h .code main proc mov cx,16 ; cx contains how many bits in a register to process ; Suppose bx contains 21d or 15h or ; 00000000 00010101b mov ah,2 ; Service to display a character looplbl: mov dl,31h ; Move code of one in dl register shl bx,1 ; Shift left bx register, if carry jc disp ; flag is high it means the left most dec dl ; bit is one otherwise dl contains the ; ASCII code for zero which is 30h disp: int 21h loop looplbl mov ax,4c00h int 21h main endp end main ============================================= mov bx,21

-2Title macro and procedure .model small .stack 100h .data msg db "KUDCS",'$' .code show macro string mov dx,offset string mov ah,9 int 21h endm newline proc mov ah,2 mov dl,0ah int 21h mov dl,0dh int 21h ret newline endp main proc mov ax,@data mov ds,ax mov cx,10 abc: show msg call newline loop abc mov ax,4c00h int 21h main endp end main ============================================= .model small .stack 100h .data msg1 db 'Enter a number: $' msg2 db 0ah,0dh,'Its double is: $' wr db 0ah,0dh,'Invalid input$' .code main proc mov ax,@data mov ds,ax mov ah,9 mov dx,offset msg1 int 21h mov ax,0 mov bx,0 mov cx,0ah a1: mov ah,1 int 21h cmp al,0dh je done cmp al,30h jl warn1 cmp al,39h jg warn1 sub al,30h cbw xchg ax,bx mul cx xchg ax,bx add bx,ax jmp a1 warn1: mov ah,9 mov dx,offset wr int 21h jmp exit done: mov ah,9 mov dx,offset msg2 int 21h shl bx,1 mov ax,bx mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd exit: mov ax,4c00h int 21h main endp end main ============================================= ;; Use of include: just write code in a separate file and ;; write include to include it in another file Title takes any integer and count it .model small .stack 100h .data num1 db 0 msg db "Enter any integer: ",'$' crlf db 0ah,0dh,'$' .code include numbers.h main proc mov ax,@data mov ds,ax DispStr msg call NumRead dispstr crlf mov dl,01h mov dh,0 mov cx,bx label1: DispNum dx dispstr crlf inc dl loop label1 Exit main endp end main --------------------------------------------------------------------;; Name of this file is numbers.h ;; This file is used to be included in above program DispStr macro string push dx push ax mov dx,offset string mov ah,9 int 21h pop ax pop dx endm Exit macro mov ax,4c00h int 21h endm NumRead proc mov ax,0 mov bx,0 a1: mov ah,1 int 21h cmp al,0dh je done cmp al,30h jl warn1 cmp al,39h jg warn1 sub al,30h cbw xchg ax,bx mov cx,10d mul cx

-3xchg ax,bx add bx,ax jmp a1 warn1: mov ah,2 mov dl,0ah int 21h mov dl,0dh int 21h Exit done: ret NumRead endp DispNum macro numvar push ax push bx push cx push dx mov ax,numvar mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd pop dx pop cx pop bx pop ax endm ============================================= ;; This program totals all the odd nos. between 1 and 100 ;; and then display the sum .model small .stack 100h .code main proc mov ax,0 mov bx,1 ; First odd no. lbl: add ax,bx ; Add odd no. in ax to get the sum inc bx ; Get next odd no. by adding two inc bx ; in the previous one cmp bx,100 ; repeat this process upto 100th term jl lbl mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd exit: mov ax,4c00h int 21h main endp end main ============================================= ============================================= .model small .stack 100h .data firstparam dw 8 secondparam dw 12 addresult dw 0 .code main proc mov ax,@data mov ds,ax lea bx,addresult push bx lea bx,secondparam push bx lea bx,firstparam push bx call c_conv lea bx,addresult push bx call dispresult mov ax,4c00h int 21h main endp c_conv proc push bp mov bp,sp push ax push bx mov si,[bp+4] mov ax,[si] ;; mov ax,[[bp+4]] can be used but it will ;; collect data from stack segment not from ;; data segment because bp is a pointer ;; register in stack segment mov si,[bp+6] mov bx,[si] add ax,bx mov si,[bp+8] mov [si],ax pop bx pop ax pop bp ret 6 c_conv endp dispresult proc push bp mov bp,sp push ax push bx push cx push dx push si mov si,[bp+4] mov ax,[si] ;; mov ax,[[bp+4]] can be used but it will ;; collect data from stack segment not from ;; data segment because bp is a pointer ;; register in stack segment mov cx,0 mov si,0ah lbl1: mov dx,0 div si push dx inc cx cmp ax,0 jg lbl1 mov ah,2 lbl2: pop dx add dl,30h int 21h loop lbl2 pop si pop dx pop cx pop bx pop ax pop bp ret 2 dispresult endp end main

-4;; Program to display the factorial of a number stored in ax .model small .stack 100h .code main proc mov ax,3 push ax call factorial mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd exit: mov ax,4c00h int 21h main endp factorial proc push bp mov bp,sp mov ax,[bp+4] cmp ax,1 ja l1 mov ax,1 jmp l2 l1: dec ax push ax call factorial mov bx,[bp+4] mul bx l2: pop bp ret 2 factorial endp end main ============================================= ;; ;; This program takes input two numbers and then multiply ;; them without using the MUL instruction ;; .model small .stack 100h .data mssg1 db 0ah,0dh,'Enter first number : $' mssg2 db 0ah,0dh,'Enter Second number: $' mssg3 db 0ah,0dh,'Their product is : $' .code main proc mov ax,@data mov ds,ax mov ah,9 mov dx,offset mssg1 int 21h call NumRead ; Procdure to take input a number in bx push bx mov ah,9 mov dx,offset mssg2 int 21h call NumRead ; Procdure to take input a number in bx push bx mov ah,9 mov dx,offset mssg3 int 21h pop bx pop ax mov dx,0 ; dx is used to hold the product addloop: test bx,1 ; Test that last bit of bx is 0 or not jz shifting add dx,ax ; Add ax in the product shifting: shl ax,1 ; Shift ax by one bit to be added in ; dx to resemble multiplication shr bx,1 ; Shift bx to collect the last bit jnz addloop ; Check that all bits are processed or not mov ax,dx ; Now display the product mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd exitprog: mov ax,4c00h int 21h main endp NumRead proc mov ax,0 mov bx,0 a1: mov ah,1 int 21h cmp al,0dh je done cmp al,30h jl warn1 cmp al,39h jg warn1 sub al,30h cbw xchg ax,bx mov cx,10d mul cx xchg ax,bx add bx,ax jmp a1 warn1: mov ah,2 mov dl,0ah int 21h mov dl,0dh int 21h done: ret NumRead endp end main ============================================= .model small .stack 100h .data var1 dd 08ac392beh var2 dd 0fa3b9ec6h result dw 3 dup(0) dummy db 0 .code main proc mov ax,@data mov ds,ax mov si,offset var1 mov di,offset var2 mov bx,offset result mov cx,2 clc ; Clears carry flag ; CMC complements carry flag lbl1: mov ax,[si] adc ax,[di] pushf mov [bx],ax add si,2

-5add di,2 add bx,2 popf loop lbl1 adc word ptr [bx],0 mov cx,6 mov bx,offset dummy dec bx mov ah,2 lbl2: mov dl,[bx] mov dh,dl and dl,0f0h push cx mov cl,4 shr dl,cl pop cx add dl,30h cmp dl,3ah jl disp1 add dl,7 disp1: int 21h mov dl,dh and dl,0fh add dl,30h cmp dl,3ah jl disp2 add dl,7 disp2: int 21h dec bx loop lbl2 mov ax,4c00h int 21h main endp end main ============================================= ;; This program input a number and then test ;; is it prime or not .model small .stack 100h .data mssg db 'Enter a number: $' prime db 0ah,0dh,'It is a prime number $' notprime db 0ah,0dh,'It is not a prime number $' crlf db 0ah,0dh,'$' .code main proc mov ax,@data mov ds,ax mov ah,9 mov dx,offset mssg int 21h mov ax,0 mov bx,0 a1: mov ah,1 int 21h cmp al,0dh je done cmp al,30h jl warn1 cmp al,39h jg warn1 sub al,30h cbw xchg ax,bx mov cx,10d mul cx xchg ax,bx add bx,ax jmp a1 warn1: mov ah,2 mov dl,0ah int 21h mov dl,0dh int 21h done: mov di,1 ; 1 prime, 0 not prime mov cx,2 divlbl: ; Now continuously divide the given number mov dx,0 ; until range is reached or any remainder mov ax,bx ; becomes zero div cx cmp dx,0 je exitprog inc cx cmp cx,bx jl divlbl mov di,2 exitprog: ; Now display the nature of input number mov ah,9 mov dx,offset prime cmp di,2 je dispmssg mov dx,offset notprime dispmssg: int 21h mov ax,4c00h int 21h main endp end main ============================================= ;; This program sorts an array ;; .model small .stack 100h .data a db 5,4,9,2,6,3,8 ; Initialize array with 7 values min db 0 max db 0 .code main proc mov ax,@data ; Initialize .data as data and extra segment mov ds,ax mov es,ax mov dx,1 lbl1: ; Upper loop stores the maximum value at the lea si,a ; end of array and then process the array mov di,si ; upto one preceding element inc di mov cx,7 sub cx,dx lbl2: ; Inner loop compares two consecutive nos. mov al,[si] ; upto given no. of range if first no. is cmp al,[di] ; greater than the second then exchange them jl nextval xchg al,[di] ; The value of this range is provided by the xchg al,[si] ; upper loop which stores the maximum at the nextval: ; end of array inc si inc di loop lbl2 inc dx ; Upper loop executes six times i.e. no. of cmp dx,7 ; elements minus one jl lbl1 lea si,a mov al,[si] ; First element contains the minimum value mov min,al add si,6 mov al,[si] ; Last element contains the maximum value mov max,al mov cx,7 mov si,0 zcopy: mov bx,offset a mov dh,0 mov dl,[bx+si] add dl,30h mov ah,02 int 21h inc si loop zcopy mov ax,4c00h int 21h main endp end main ============================================= .model small

-6.stack 100h .data var1 db '0999' var2 db '0999' result db 4 dup(0) .code main proc mov ax,@data mov ds,ax mov cx,4 mov si,3 mov ax,0 nextdigit: mov al,var1[si] add al,ah mov ah,0 add al,var2[si] aaa or al,30h mov result[si],al dec si loop nextdigit mov bx,offset result mov cx,4 mov ah,2 disp: mov dl,[bx] int 21h inc bx loop disp mov ax,4c00h int 21h main endp end main ============================================= ============================================= .model small .stack 100h .data var1 dw 0017h var2 dw 0ff29h result dw 0 .code main proc mov ax,@data mov ds,ax mov cx,2 mov si,0 clc lbl1: mov al,byte ptr var1[si] sbb al,byte ptr var2[si] mov byte ptr result[si],al inc si loop lbl1 mov bx,result mov ch,4 mov ah,2 jnc lbl2 mov dl,'-' int 21h neg bx lbl2: mov cl,4 rol bx,cl mov al,bl and al,0fh add al,30h cmp al,3ah jl disp add al,7 disp: mov dl,al int 21h dec ch jnz lbl2 mov ax,4c00h int 21h main endp end main ============================================= ;; title Generating sound .model small .stack 100h speaker equ 61h timer equ 42h delay equ 0dfffh .code main proc in al,speaker push ax or al,00000011b out speaker,al mov al,200 l2: out timer,al mov cx,delay l3: loop l3 sub al,1 jnz l2 pop ax and al,11111100b out speaker,al mov ax,4c00h int 21h main endp end main ============================================= title to generate sound on speaker .model small .stack 100h .code main proc mov cx,0fffeh mov dx,8b40h in al,61h and al,11111100b sound: push cx xor al,2 out 61h,al add dx,9248h mov cl,3 ror dx,cl ;; This program multiplies two BCD nos. ;; .model small .stack 100h .code main proc mov ah,1 ; Take input first no. and check is it digit or not int 21h cmp al,30h jl exitprog cmp al,39h jg exitprog sub al,30h ; Convert entered digit into no. mov bl,al int 21h ; Take input second no. and check is it digit or not cmp al,30h jl exitprog cmp al,39h jg exitprog sub al,30h ; Convert entered digit into no. mul bl ; Multiply first no. with the second aam ; ASCII adjust after multiplication mov bx,ax mov dl,bh ; Now display adjusted BCD digits one by one add dl,30h mov ah,2 int 21h mov dl,bl add dl,30h int 21h exitprog: mov ax,4c00h int 21h main endp end main

-7mov cx,dx and cx,1ffh or cx,10 wt: loop wt pop cx loop sound mov ax,4c00h int 21h main endp end main ============================================= .model small .stack 100h .data arr1 db '$','S','C','D','U','K' arr2 db 6 dup(0) .code main proc mov ax,@data mov ds,ax mov es,ax mov di,offset arr2 mov si,offset arr2 dec si mov cx,6 call revcopy mov dx,offset arr2 mov ah,9 int 21h mov ax,4c00h int 21h main endp revcopy proc copyloop: mov al,byte ptr[si] mov byte ptr[di],al dec si inc di loop copyloop ret revcopy endp end main ============================================= .model small .stack 100h .data maxkey db 19 charkey db 0 str1 db 19 dup(?) msg1 db 'Type any string: ','$' msg2 db 'You have typed: ','$' crlf db 0ah,0dh,'$' .code main proc mov ax,@data mov ds,ax mov dx,offset msg1 mov ah,09h int 21h mov dx,offset maxkey mov ah,0ah int 21h mov dx,offset crlf mov ah,09h int 21h xor bx,bx mov bl,charkey mov str1[bx],'$' mov dx,offset msg2 mov ah,09h int 21h mov dx,offset str1 mov ah,09h int 21h mov ax,4c00h int 21h main endp end main ============================================= .model small .stack 100h .data str1a db 20 str1b db ? str1c db 20 dup(?) str2 db 20 dup(?) newline db 0dh,0ah,'$' msg1 db 'Type any string: ','$' msg2 db 'You have typed: ','$' .code main proc mov ax,@data mov ds,ax mov es,ax mov dx,offset msg1 mov ah,9 int 21h mov dx,offset str1a mov ah,0ah int 21h mov ch,0 mov cl,str1b push cx mov si,offset str1c mov di,offset str2 cld rep movsb pop cx mov bx,cx mov str2+[bx],'$' mov ah,9 mov dx,offset newline int 21h mov dx,offset msg2 int 21h mov dx,offset str2 int 21h mov ax,4c00h int 21h main endp end main ============================================= ;; This program takes input a string and then display its length ;; ;; It is not necessary that data segment always mentioned in ;; the beginning of a program. Data segment can be defined ;; at the end too. .model small .stack 100h .code main proc mov ax,@data mov ds,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a ; Takes input the string mov ah,0ah int 21h mov dx,offset newline ; Proceed to next line mov ah,9 int 21h mov dx,offset mssg2 ; Display message for next character int 21h mov ah,0 ; ax contains no. of characters entered mov al,str1b mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd:

-8pop dx add dx,30h mov ah,2 int 21h loop wd mov ax,4c00h int 21h main endp .data mssg1 db 'Please enter a string: $' mssg2 db 'Number of characters entered in the string: $' str1a db 20 ; Data structure for the string str1b db ? str1c db 20 dup(?) newline db 0dh,0ah,'$' ; New line string end main ============================================= .model small .stack 100h .data mssg1 db 'Enter a string: $' mssg2 db 'Now enter a character to search: $' mssg3 db 'Entered character is located at location: $' mssg4 db 'Entered Character is not found$' str1a db 20 str1b db ? str1c db 20 dup(?) newline db 0dh,0ah,'$' .code main proc mov ax,@data mov ds,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 int 21h mov ch,0 mov cl,str1b mov ah,1 int 21h mov ah,0 push ax mov dx,offset newline mov ah,9 int 21h mov bx,offset str1c pop ax mov dx,0 lbl1: mov ah,[bx] inc dx inc bx cmp al,ah je lbl2 loop lbl1 mov dx,offset mssg4 mov ah,9 int 21h jmp exit lbl2: mov di,dx mov dx,offset mssg3 mov ah,9 int 21h mov ax,di mov cx,0 mov si,0ah lbl3: mov dx,0 div si push dx inc cx cmp ax,0 jg lbl3 mov ah,2 lbl4: pop dx add dl,30h int 21h loop lbl4 exit: mov ax,4c00h int 21h main endp end main ============================================= .model small .stack 100h .data mssg1 db 'Enter a string: $' mssg2 db 'Now enter a character to search: $' mssg3 db 'Entered character is located at location: $' mssg4 db 'Entered Character is not found$' str1a db 20 str1b db ? str1c db 20 dup(?) newline db 0dh,0ah,'$' .code main proc mov ax,@data mov ds,ax mov es,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a mov ah,0ah int 21h mov ch,0 mov cl,str1b mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 int 21h mov ah,1 int 21h mov dx,offset mssg4 lea si,str1c lea di,str1c cld repne scasb jnz exit mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg3 int 21h sub di,si mov ax,di mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd mov dx,offset newline exit: mov ah,9 int 21h mov ax,4c00h int 21h main endp end main =============================================

-9mssg1 db 'Enter first string: $' mssg2 db 'Enter second string: $' mssg3 db 'Both string together are: $' str1a db 20 ; Data structure for first string str1b db ? str1c db 20 dup(?) str2a db 20 ; Data structure for second string str2b db ? str2c db 20 dup(?) str3 db 40 dup(?) ; Third string newline db 0dh,0ah,'$' ; New line string .code main proc mov ax,@data ; Make data and extra segment point mov ds,ax ; to same segment mov es,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a ; Takes input first string mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 int 21h mov dx,offset str2a ; Takes input the second string mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov ch,0 ; cx contains length of first string mov cl,str1b mov si,offset str1c ; si points to the first string and mov di,offset str3 ; di points to the resulting third string cld rep movsb ; Copy first string to the third one mov ch,0 mov cl,str2b ; Now cx contains length of the second mov si,offset str2c ; si points to the second string rep movsb ; Copy second string to the end of third ; one because di point to the end of third string mov str3+[di],'$' ; Append $ sign at the end of third string mov ah,9 ; to mark the end of string sign mov dx,offset newline int 21h mov dx,offset mssg3 int 21h mov dx,offset str3 int 21h mov ax,4c00h int 21h main endp end main ============================================= ;; This program takes input a string and then ;; display no. of vowels appear in the string ;; .model small .stack 100h .data mssg1 db 'Please enter a string: $' mssg2 db 'Number of vowels entered in the string: $' str1a db 20 ; Data structure for the string str1b db ? str1c db 20 dup(?) vowels db 'AEIOUaeiou' ; All possible vowels in a variable newline db 0dh,0ah,'$' ; New line string .code main proc mov ax,@data ; Initialize data and extra segment mov ds,ax mov es,ax cld ; Clear Direction Flag mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset str1a ; Takes input the string mov ah,0ah int 21h

.model small .stack 100h .data var1a db 20 var1b db ? var1c db 20 dup(?) var2a db 10 var2b db ? var2c db 10 dup(?) newline db 0dh,0ah,'$' mssg1 db 'Enter a string: $' mssg2 db 'Enter another string to be searched in first one: $' isfound db 'String is found $' isnotfound db 'String is not found $' .code main proc mov ax,@data mov ds,ax mov es,ax mov dx,offset mssg1 mov ah,9 int 21h mov dx,offset var1a mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h mov dx,offset mssg2 mov ah,9 int 21h mov dx,offset var2a mov ah,0ah int 21h mov dx,offset newline mov ah,9 int 21h cld lea si,var2c mov al,[si] mov cl,var1b mov ch,0 lea di,var1c lbl1: repne scasb mov dx,offset isnotfound cmp cx,0 je exit mov ax,cx mov bx,di mov cl,var2b mov ch,0 inc cx dec di mov si,di lea di,var2c repe cmpsb mov dx,offset isfound cmp cx,0 je exit mov di,bx mov cx,ax lea si,var2c mov al,[si] jmp lbl1 exit: mov ah,9 int 21h mov ax,4c00h int 21h main endp end main ============================================= ;; This program takes input two strings and then make another ;; string by concatenating them ;; .model small .stack 100h .data

- 10 mov dx,offset newline ; Proceed to next line mov ah,9 int 21h mov dx,offset mssg2 ; Display message for no. of vowels int 21h mov ch,0 ; cx contains no. of characters entered mov cl,str1b ; in the string which will be processed ; one by one mov ah,0 mov bx,0 ; ah register will be used to hold ; no. of vowels in the entered string ; bx will be used as base register to point ; to next available character in a string ; si points to the start of string mov cl,string1b mov ah,9 mov dx,offset newline int 21h mov ah,2 mov bx,0 mov si,1 trns: mov dl,string1c+[bx] cmp dl,20h jne cptl mov si,1 jmp dspl cptl: cmp si,1 jne dspl mov si,0 cmp dl,61h jl dspl cmp dl,7ah jg dspl sub dl,20h dspl: int 21h inc bx loop trns mov ax,4c00h int 21h main endp end main ================================== .model small extrn convert: proc .stack 100h .data msg db 'enter lower case letter:$' .code main proc mov ax,@data mov ds,ax mov ah,9 lea dx,msg int 21h mov ah,1 int 21h call convert mov ah,4ch int 21h main endp end main ------------------------------; This is the second program public convert .model small .data msg db 0dh,0ah,'in upper case' char db -20h,'$' .code convert proc near push bx push dx add char,al mov ah,9 lea dx,msg int 21h pop dx pop bx ret convert endp end =================== extrn get_time:near .modelsmall .stack 100h .data time_bufdb '00:00:00$' .code main proc mov ax,@data ; in cx register ; now proceed to the next line

; Starting position of string

; To transfer a character in dl

; If a character is space then store ; 1 in si and display it

mov si,offset str1c vowelcount: push cx mov cx,10

; Preserve old value of cx register which ; initially holds the total no. of characters ; entered in the string and then store 10 in ; it which represent total no. of characters ; in the variable named vowels

; If 1 is in si it means this character ; is the starting character or it is ; after space so then capitalize it if ; it is in small case

mov di,offset vowels ; di points to the start of variable vowels mov al,[si+bx] ; and al contains the character to be searched repne scasb ; in vowels if the character is found in the jne novowel ; string pointed by di register (ie vowels) it inc ah ; means it is a vowel, so increment ah by 1 novowel: pop cx ; Now extract old value of cx to represent ; remaining no. of characters to be processed inc bx ; bx register is incremented to point to the loop vowelcount ; next character in the entered string dispvalue: mov al,ah ; ax holds the total no. of vowels in string mov ah,0 mov bx,10 mov dx,0 mov cx,0 cd: div bx push dx mov dx,0 inc cx cmp ax,0 jnz cd wd: pop dx add dx,30h mov ah,2 int 21h loop wd mov ax,4c00h int 21h main endp end main ============================================= ;; Input a string and then display it in Title case i.e. first letter of ;; each word or sentence becomes capital ;; .model small .stack 100h .data string1a db 70 ; Define data structure for strin string1b db ? ; it can hold upto 70 characters string1c db 70 dup(?) newline db 0dh,0ah,'$' ; Carriage return and line feed ; with a dollar sign to proceed ; to the next line .code main proc mov ax,@data mov ds,ax mov dx, offset string1a mov ah,0ah int 21h mov ch,0 ; Now take input the string

; Display the character ; Increment bl to specify the next ; character

; Get the length of string

- 11 mov ds,ax lea bx,time_buf call get_time lea dx,time_buf mov ah,09h ;display time int 21h mov ah,4ch int 21h main endp end main ----------------------------------------public get_time .modelsmall .code get_time proc mov ah,2ch int 21h mov al,ch call convert mov [bx],ax mov al,cl call convert mov [bx+3],ax mov al,dh call convert mov [bx+6],ax ret get_time endp convert proc mov ah,0 mov dl,10 div dl or ax,3030h ret convert endp end ================================== .model small .stack 100h .data doscall equ 21h var1 label word var2 db 41h var3 db 44h var4 label byte var5 dw 464Ah .code main proc mov ax,@data mov ds,ax mov dx,var1 mov ah,2 int doscall mov dl,var4 int doscall mov dx,var5 int doscall mov dx,word ptr var4 int doscall mov dl,dh int doscall mov dx,word ptr var2 int doscall mov dl,byte ptr var5 int doscall mov dl,byte ptr var1 int doscall mov bx,offset var1 mov dl,[bx] int doscall mov dx,word ptr[bx] int doscall mov bx,offset var4 mov dx,word ptr[bx] int doscall mov bx,offset var5 mov dx,word ptr[bx] int doscall mov bx,offset var3 mov dx,word ptr[bx] int doscall mov dl,dh int doscall push var5 mov bp,sp mov dl,[bp] int doscall mov dx,word ptr[bp] int doscall mov dl,[bp+1] int doscall pop dx mov ax,4c00h int doscall main endp ================================== .model small .stack 100h .data var1 db 0 var2 db 0 msg1 db '1st is 5 $' msg2 db '2nd is -5 $' msg3 db '1st is -5 $' msg4 db '2nd is 5 $' msg5 db '1st is greater $' msg6 db '2nd is greater $' .code main proc mov ax,@data mov ds,ax mov ah,9 lea dx,msg1 int 21h lea dx,msg2 int 21h mov var1,5 mov var2,-5 call jproc lea dx,msg3 int 21h lea dx,msg4 int 21h mov var1,-5 mov var2,5 call jproc mov ax,4c00h int 21h main endp jproc proc mov al,var1 mov cl,var2 cmp al,cl ja lab lbl1: mov al,var1 mov cl,var2 cmp al,cl jb lbl lbl2: mov al,var1 mov cl,var2 cmp al,cl jg lgr lbl3: mov al,var1 mov cl,var2 cmp al,cl jl lls jmp exit lab: lea dx,msg5 int 21h jmp lbl1 lbl: lea dx,msg6 int 21h jmp lbl2 lgr: lea dx,msg5 int 21h jmp lbl3 lls: lea dx,msg6 int 21h exit: ret jproc endp

- 12 end main ================================== .model small .stack 100h .code dis_str macro string mov dx,offset string mov ah,9h int 21h endm cur_pos macro vpg,row,colum ;; For cursor position mov bx,vpg mov ah,2 mov dh,row mov dl,colum int 10h endm clrscr1 proc mov ax,0600h mov cx,0 mov dh,24 mov dl,79 mov bh,7 int 10h ret clrscr1 endp main proc mov ax,@data mov ds,ax call clrscr1 cur_pos 0,2,5 dis_str msg1 cur_pos 0,5,15 dis_str msg2 cur_pos 0,7,5 dis_str msg2 mov ax,4c00h int 21h main endp .data msg1 db 'Hello',0dh,0ah,'$' msg2 db 'Thank you',0dh,0ah,'$' end main ================================== .model small .stack 200 .code main proc mov ax , @data mov ds , ax mov ah , 00h mov al,03H int 10h mov ah , 09h mov al,0c4h mov bl,00001001b mov bh,00 mov cx,40 int 10h mov ah , 4ch int 21h main endp end main ================================== ;draws horizontal line in high res ;in row 100 from col 301 to col 600 .model small .stack 100h .code main proc ;set graphics mode movax,6 ;select mode 6, hi res int 10h ;draw line movah,0ch;write pixel moval,1 ;white movcx,301;beginning col movdx,100;row l1: int 10h inc cx ;next col cmpcx,600;more columns? jle l1 ;yes, repeat ;read keyboard movah,0 int 16h ;set to text mode movax,3 ;select mode 3, text mode int 10h ;return to dos movah,4ch;return int 21h ;to dos main endp end main ================================== .model small .stack 100h .data buffer db 4000 dup (?) .code main proc mov ax,@data mov ds,ax mov es,ax mov si,0 cld push ds mov ax,0b800h mov ds,ax mov di,offset buffer mov cx,4000 rep movsb mov ah,1 int 21h mov cx,2000 mov dl,'A' mov ah,2 ag1: int 21h loop ag1 mov ah,1 int 21h pop ds mov si,offset buffer mov ax,0b800h mov es,ax mov di,0 mov cx,4000 rep movsb mov ax,4c00h int 21h main endp end main ================================== .model small .stack 100h .code main proc ;set ds to active display page mov ah,0 mov al,3 int 10h mov ax,0b800h ;color active display page mov ds,ax mov cx,2000 ;80*25 = 2000 words mov di,0 ;initialize di ;fill active display page fill_buf: mov word ptr[di],1441h ;red a on blue add di,2 ;go to next word loop fill_buf ;loop until done mov ah,4ch int 21h main endp end main ================================== .model small .stack 100h .data mssg1 db 'Empty Command Tail$' mssg2 db 'Command tail is: $' buffer db 30 dup(?) .code main proc ;mov bx,es mov ax,@data mov ds,ax lea si,buffer ;mov es,bx ;mov si,dx

- 13 mov di,81h mov cx,0 mov cl,es:[di-1] cmp cx,0 je lb2 mov al,20h repz scasb jz lb2 dec di inc cx lb1: mov al,es:[di] mov [si],al inc si inc di loop lb1 mov al,'$' mov [si],al lea dx,mssg2 mov ah,9 int 21h lea dx,buffer int 21h jmp exit lb2: lea dx,mssg1 mov ah,9 int 21h exit: mov ax,4c00h int 21h main endp end main ========================== .model small .stack 100h .code main proc mov ax,0 int 33h mov ax,1 int 33h mov bh,00010111b disp: mov ah,6 mov al,0 mov ch,8 mov cl,30 mov dh,16 mov dl,50 int 10h mov bl,0 push bx press: mov ax,3 int 33h cmp bx,2 je exit cmp bx,1 jne press chk: mov ax,5 mov bx,0 int 33h and ax,1 cmp ax,1 je chk pop bx cmp bh,00010111b je red mov bh,00010111b jmp disp red: mov bh,01000111b jmp disp exit: pop bx mov ax,4c00h int 21h main endp end main end

S-ar putea să vă placă și