Saturday, February 19, 2011

Cursor operations-Change size and Move

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm .model small .stack 100h .data msg1 db 10,13,'Press 1 to increase and 0 to decrease
     the size of cursor (only 4 sizes, initially minimum) $'
msg2 db 10,13,'Press 8,2,4 and 6 to move the cursor
     up,down,left and right respectively $'
msg3 db 10,13,'Press ENTER to finish $' .code main proc mov ax,@data mov ds,ax mov cl,8 mov ch,8 ;clear screen mov ah,0 mov al,03 int 10h print msg1 print msg2 print msg3 loop1:; wait key press: xor ax, ax int 16h cmp al,0dh je exit cmp al,31h je incr cmp al,30h je decr cmp al,38h je up cmp al,32h je down cmp al,36h je right cmp al,34h jne loop1 call getcursor dec dl call putcursor jmp loop1 up: call getcursor dec dh call putcursor jmp loop1 down:call getcursor inc dh call putcursor jmp loop1 right:call getcursor inc dl call putcursor jmp loop1 decr:cmp ch,08 je loop1 rol ch,1 call chgcursor jmp loop1 incr:cmp ch,01 je loop1 ror ch,1 call chgcursor jmp loop1 exit:mov ah,4ch int 21h main endp chgcursor proc ;change cursor size mov ah, 1 int 10h ret chgcursor endp getcursor proc ;get cursor position and size mov ah,03h int 10h ret getcursor endp putcursor proc ;show the cursor mov ah,02h int 10h ret putcursor endp end

Wednesday, February 16, 2011

Reverse each words in a sentance

Share Orkut
;to print a string print macro msg lea dx,msg mov ah,09h int 21h endm ;goes to next line newline macro mov ah,02h mov dl,0ah int 21h endm .model small .stack 100h .data s1 db 'Enter the sentance:- $' s2 db 'Sentance after reversing the word:- $' s3 db 50 dup('$') .code mov ax,@data mov ds,ax print s1 mov di,00h ;read s3 loop1:mov ah,01 int 21h cmp al,0dh jz j1 mov s3[di],al inc di jmp loop1 ;length of s3 is stored in cx j1:mov cx,di mov di,00 mov bx,sp newline print s2 ;while cx!=0 ;{ ; if s3[di]==' ' ; { while stack not empty ; pop and display ; display space ; } ; else push s3[di] ; increment di ; decrement cx ;} loop2:cmp cx,00 jz loop4 mov al,s3[di] cmp al,32d jnz j4 loop3:cmp sp,bx jz j3 pop dx mov ah,02h int 21h jmp loop3 j3:mov ah,02h mov dl,32d int 21h jmp j5 j4:mov ax,00 mov al,s3[di] push ax j5:inc di dec cx jmp loop2 ;while stack not empty ; pop and display loop4:cmp sp,bx jz stp pop dx mov ah,02h int 21h jmp loop4 stp:mov ah,4ch int 21h end

Factorial of a number

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm read macro n,j1,j2 mov cx,0ah j1:mov ah,01h int 21h cmp al,0dh je j2 sub al,30h mov bl,al mov ax,n mul cx xor bh,bh add ax,bx mov n,ax jmp j1 j2 :nop endm .model small .stack 100h .data msg1 db 10,13,'Enter the number: $' msg2 db 10,13,'Factorial: $' n dw 0 .code main proc mov ax,@data mov ds,ax print msg1 ;reading 1st multidigit number read n,jump1,jump2 print msg2 ;Find factorial of 'n' mov ax,01 loop1:cmp n,00 je jump3 mul n dec n jmp loop1 jump3:call printmul mov ah,4ch int 21h main endp printmul proc mov bx,000ah xor cx,cx ;push into stack l2:xor dx,dx div bx push dx inc cx cmp ax,0000h jne l2 ;pop from stack l3:pop dx add dl,30h mov ah,02h int 21h loop l3 ret printmul endp end

Fibonacci Series

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm read macro n,j1,j2 mov cx,0ah j1:mov ah,01h int 21h cmp al,0dh je j2 sub al,30h mov bl,al mov ax,n mul cx xor bh,bh add ax,bx mov n,ax jmp j1 j2 :nop endm .model small .stack 100h .data msg1 db 10,13,'Enter the number: $' msg2 db 10,13,'Fibonacci Series: $' space db ' $' n dw 0 a dw 0 b dw 1 fib dw 0 .code main proc mov ax,@data mov ds,ax print msg1 ;reading 1st multidigit number read n,jump1,jump2 print msg2 jump3:print space mov ax,fib call printmul mov ax,b mov a,ax mov dx,fib mov b,dx add ax,dx mov fib,ax cmp n,ax jnc jump3 mov ah,4ch int 21h main endp printmul proc mov bx,000ah xor cx,cx ;push into stack l2:xor dx,dx div bx push dx inc cx cmp ax,0000h jne l2 ;pop from stack l3:pop dx add dl,30h mov ah,02h int 21h loop l3 ret printmul endp end

Tuesday, February 15, 2011

No. of vowels in a string

Share Orkut
.model small .stack 100h .data s1 db 'Enter a string $' vowl db 'AEIOUaeiou $' s3 db 10,13,'No of vowels are-> $' s2 db 50 dup('$') count dw ? .code mov ax,@data mov ds,ax mov es,ax ;display 'enter the string' lea dx,s1 mov ah,09h int 21h ;read the string lea di,s2 xor cl,cl cld loop1: mov ah,01 int 21h cmp al,0dh jz endinpt stosb inc cl jmp loop1 endinpt:;checking vowel mov bl,cl cmp cl,00 jnz jump1 xor ax,ax jmp pr jump1: cld lea si,s2 next: mov cx,000bh lodsb lea di,vowl repne scasb cmp cx,00 jz novowl inc count novowl: dec bl jnz next ;jump to nextline mov dl,0ah mov ah,02h int 21h ;print count of vowels mov ax,count pr: mov bx,000ah xor cx,cx ;printing multi digit number ;push into stack print: xor dx,dx div bx push dx inc cx cmp ax,0000h jne print ;display 'No of vowels are-> ' lea dx,s3 mov ah,09h int 21h ;pop from stack display:pop dx add dl,30h mov ah,02h int 21h loop display mov ah,4ch int 21h end

Insert a string in another string

Share Orkut
.model small .stack 100h .data msg1 db 'Enter 1st string $' msg2 db 'Enter 2nd string $' msg3 db 'Enter the position $' msg4 db 'Result string is-> $' s1 db 50 dup('$') s2 db 50 dup('$') s3 db 50 dup('$') len1 db ? len2 db ? pos db 0 .code main proc mov ax,@data mov ds,ax mov es,ax ;display 'enter 1st string' lea dx,msg1 call display ;read the 1st string lea di,s1 call readstr endinpt:mov len1,cl ;jump to nextline call newline ;display 'enter 2nd string' lea dx,msg2 call display ;read the 2nd string lea di,s2 call readstr endinp1:mov len2,cl ;jump to nextline call newline ;display 'enter the position' lea dx,msg3 call display ;enter the position mov cx,000ah inppos: mov ah,01h int 21h cmp al,0dh je endpos and al,0fh mov bl,al mov ah,00 mov al,pos mul cx add al,bl mov pos,al jmp inppos ;insert a string into another string endpos: xor ch,ch lea si,s1 lea di,s3 cld mov cl,pos rep movsb mov dx,si lea si,s2 mov cl,len2 rep movsb mov cl,len1 sub cl,pos mov si,dx rep movsb ;jump to nextline call newline ;display 'Result string is-> ' lea dx,msg4 call display ;print result string lea dx,s3 call display mov ah,4ch int 21h main endp display proc mov ah,09h int 21h ret display endp newline proc mov dl,0ah mov ah,02h int 21h ret newline endp readstr proc xor cl,cl cld loop1: mov ah,01 int 21h cmp al,0dh je endread stosb inc cl jmp loop1 endread:ret readstr endp end

GCD of two numbers

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm read macro msg,r1,loo r1:mov ah,01h int 21h cmp al,0dh jz loo sub al,30h mov cl,al mov ax,msg mov dx,10 mul dx mov ch,00 add ax,cx mov msg,ax jmp r1 loo:mov f,00 endm .model small .stack 100h .data s1 db 10,13,'GCD $' s2 db 10,13,'Enter the number $' data1 dw 0 data2 dw 0 sm dw 0 rem dw 0 count dw 2 gcd dw 1 f dw 0 .code mov ax,@data mov ds,ax print s2 read data1,l1,l2 print s2 read data2,l3,l4 mov bx,data1 mov cx,data2 cmp bx,cx jc l5 je l6 mov sm,cx jmp l7 l5:mov sm,bx l7:mov dx,00 mov ax,data1 mov bx,count div bx mov rem,dx mov dx,00 mov ax,data2 mov bx,count div bx mov ax,rem or ax,dx jnz l8 mov bx,count mov gcd,bx l8:inc count mov cx,sm cmp cx,count jnc l7 jmp l9 l6:mov cx,data1 mov gcd,cx l9:mov cx,00 mov dx,00 loo:mov ax,gcd mov bx,10 div bx mov gcd,ax push dx inc cx mov dx,00 cmp gcd,dx jnz loo print s1 lo2:pop dx add dl,30h mov ah,02 int 21h loop lo2 stop:mov ah,4ch int 21h end

Change the string to upper or lower case

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm .model small .stack 100h .data s1 db 10,13,'1.to upper $' s2 db 10,13,'2.to lower $' msg1 db 10,13,'Enter the string $' msg2 db 10,13,'Enter your option(1 or 2): $' msg3 db 10,13,'Case converted string $' msg4 db 10,13,'Invalid option $' s3 db 50 dup('$') .code mov ax,@data mov ds,ax print msg1 mov cl,00 lea si,s3 loop1:mov ah,01h int 21h cmp al,0dh jz loop2 mov [si],al inc si inc cl jmp loop1 loop2:mov bl,cl lea si,s3 print s1 print s2 print msg2 mov ah,01h int 21h sub al,30h cmp al,01 je upper cmp al,02 je lower print msg4 jmp stop upper:mov al,[si] cmp al,61h jc loop7 cmp al,7ah jnc loop7 sub al,20h loop7:mov [si],al inc si dec cl jnz upper jmp loop6 lower:mov al,[si] cmp al,41h jc loop8 cmp al,5ah jnc loop8 add al,20h loop8:mov [si],al inc si dec cl jnz lower loop6:print msg3 print s3 stop:mov ah,4ch int 21h end

No. of words in a sentance

Share Orkut
print macro msg lea dx,msg mov ah,09h int 21h endm .model small .stack 100h .data s1 db 10,13,'Enter a sentance $' s2 db 10,13,'The no of words in the string is $' s3 db 50 dup('$') .code mov ax,@data mov ds,ax print s1 mov dx,offset s3 mov bx,00h mov ah,3fh int 21h sub ax,02 mov si,00h mov cx,ax xor dx,dx mov bl,32d cmp cx,00 je prin labl:cmp bl,s3[si] jnz labl1 inc dx labl1:inc si loop labl dec si cmp bl,s3[si] jz prin inc dx prin: mov bx,000ah mov ax,dx xor cx,cx print1: xor dx,dx div bx push dx inc cx cmp ax,0000h jne print1 print s2 display:pop dx add dl,30h mov ah,02h int 21h loop display mov ah,4ch int 21h end