Sunday, January 9, 2011

2s Compliment of a number

Share Orkut
        print macro msg         lea dx,msg         mov ah,09h         int 21h     endm     read macro n,j1,j2,error         mov cx,08h     j1:mov ah,01h         int 21h         cmp al,0dh         je j2         cmp al,2fh         jc error         cmp al,32h         jnc error         sub al,30h         mov dl,n         xor dh,dh         rcl dx,01         add dl,al         mov n,dl         loop j1         jmp j2     error:mov cl,01h         mov er,cl     j2 :nop     endm     .model small     .stack 100h     .data         msg1 db 10,13,'Enter the number in binary: $'         msg2 db 10,13,'The Number= $'         msg3 db 10,13,'2s compliment= $'         err db 10,13,'Error$'         num1 db 0         er db 0     .code     main proc         mov ax,@data         mov ds,ax         print msg1         ;reading 1st multidigit number         read num1,jump1,jump2,errr         mov al,er         cmp al,01h         jne jup         print err         jmp stop         ;printing input no in binary     jup:print msg2         mov bl,num1         call binary         ;finding 2s compliment         mov bl,num1         xor bl,0ffh         inc bl         ;printing 2s compliment in binary         print msg3         call binary     stop:mov ah,4ch         int 21h     main endp     binary proc         mov cx,08h     loop1:rcl bl,01         jc one         mov dl,30h         jmp jump3     one:mov dl,31h     jump3:mov ah,02h         int 21h         loop loop1         ret     binary endp     end

Compare Two Strings

Share Orkut
        print macro msg         lea dx,msg         mov ah,09h         int 21h     endm     read macro msg1         mov dx,offset msg1         mov bx,00h         mov ah,3fh         int 21h     endm     .model small     .stack 100h     .data         s1 db 10,13,'Enter a string $'         s2 db 10,13,'Strings are equal $'         s4 db 10,13,'String1 is less than String2 $'         s5 db 10,13,'String2 is less than String1 $'         s3 db 50 dup('$')         s6 db 50 dup('$')         len1 dw 0         len2 dw 0         fl db 0     .code         mov ax,@data         mov ds,ax         print s1         ;reading 1st string         read s3         ;finding the length of 1st string         sub ax,02         mov len1,ax         print s1         ;reading 2nd string         read s6         ;finding the length of 1st string         sub ax,02         mov len2,ax         ;Assign cx(count) as smallest length         mov cx,ax         cmp ax,len1         jc jump1         mov cx,len1         ;comparing each characters     jump1:mov si,00h     loop1:mov al,s3[si]         cmp al,s6[si]         jc fir         jnz notp         inc si         loop loop1         mov ax,len1         cmp ax,len2         jc fir         jnz notp         print s2         jmp stop     fir:print s4         jmp stop     notp:print s5     stop:mov ah,4ch         int 21h     end

Multiplication Table

Share Orkut
        print macro msg         lea dx,msg         mov ah,09h         int 21h     endm     read macro n,j1,j2     j1:mov ah,01h         int 21h         cmp al,0dh         je j2         sub al,30h         mov bl,al         mov ax,n         mov dx,0ah         mul dx         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,'Enter the limit: $'         msg4 db 10,13,'$'         msg5 db ' * $'         msg6 db ' = $'         msg7 db 10,13,'Multiplication table$'         num dw 0         limit dw 0         pro dw 0         m dw 1     .code     main proc         mov ax,@data         mov ds,ax         print msg1         ;reading 1st multidigit number         read num,jump1,jump2         print msg2         ;reading 2nd multidigit number         read limit,jump3,jump4         ;printing multiplication table         mov cx,limit         print msg7     loop1:mov bx,m         mov ax,num         mul bx         push cx         mov pro,ax         print msg4         mov ax,num         call printmul         print msg5         mov ax,m         call printmul         print msg6         mov ax,pro         call printmul         inc m         pop cx         loop loop1         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

Matrix Addition

Share Orkut
        print macro msg         lea dx,msg         mov ah,09h         int 21h     endm     reads macro m         mov ah,01h         int 21h         sub al,30h         mov m,al     endm     read macro n,j1,j2     j1:mov ah,01h         int 21h         cmp al,0dh         je j2         sub al,30h         mov bl,al         mov ax,n         mov dx,0ah         mul dx         xor bh,bh         add ax,bx         mov n,ax         jmp j1     j2 :nop     endm     readmat macro mat,l1,j3,j4,newmsg         mov cx,noe         mov si,00h         print msg6     l1:print newmsg         ;read a multidigit number         read mat[si],j3,j4         add si,02         loop l1     endm     printmul macro n1,l2,l3         mov bx,000ah         mov ax,n1         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     endm     printmat macro mat1,l4,l5,l6,j5         mov cx,noe         mov si,00h     l4: push cx         print msg7         printmul mat1[si],l5,l6         add si,02h         inc f         mov bl,f         cmp bl,colum         jne j5         print msg6         mov f,00h     j5: pop cx         loop l4     endm     .model small     .stack 100h     .data         msg1 db 10,13,'Enter the no of rows: $'         msg2 db 10,13,'Enter the no of column: $'         msg3 db 10,13,'Enter the element of matrix1 : $'         msg4 db 10,13,'Enter the element of matrix2 : $'         msg5 db 10,13,' Sum Matrix $'         msg6 db 10,13,' $'         msg7 db ' $'         msg8 db 10,13,' 1st Matrix$'         msg9 db 10,13,' 2nd Matrix$'         row db 0         colum db 0         matrix1 dw 100 dup(0)         matrix2 dw 100 dup(0)         matrix3 dw 100 dup(0)         sum dw 0         f db 0         noe dw 0     .code     main proc         mov ax,@data         mov ds,ax         ;read no of rows         print msg1         reads row         ;read no of column         print msg2         reads colum         ;calculating total no of elements         mov al,row         mov bl,colum         mul bl         mov noe,ax         ;read 1st matrix elements         readmat matrix1,loop1,jump1,jump2,msg3         ;read 2nd matrix elements         readmat matrix2,loop2,jump3,jump4,msg4         ;matrix addition         mov cx,noe         mov si,00h     loop3:mov ax,matrix1[si]         add ax,matrix2[si]         mov matrix3[si],ax         add si,02h         loop loop3         ;print 1st matrix         print msg8         print msg6         printmat matrix1,loop4,loop5,loop6,jump5         ;print 2nd matrix         print msg9         print msg6         printmat matrix2,loop7,loop8,loop9,jump6         ;print Sum matrix         print msg5         print msg6         printmat matrix3,loop10,loop11,loop12,jump7         mov ah,4ch         int 21h     main endp     end

Sunday, December 12, 2010

LCM of two numbers

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 1st number: $'         msg2 db 10,13,'Enter the 2nd number: $'         msg3 db 10,13,'The LCM= $'         data1 dw 0         data2 dw 0         dat1 dw 0         dat2 dw 0     .code     main proc         mov ax,@data         mov ds,ax         print msg1         ;reading 1st multidigit number         read data1,jump1,jump2         print msg2         ;reading 2nd multidigit number         read data2,jump3,jump4         ;copy the data1 and data2 to dat1& dat2         mov bx,data1         mov dat1,bx         mov cx,data2         mov dat2,cx         ;Algorithm for finding lcm         ;if(dat1=dat2) then finish, lcm=dat1 or dat2         ;elseif(dat1<dat2) then dat1=dat1+data1         ;else dat2=dat2+data2         ;repeat     loop1:mov ax,dat1         cmp ax,dat2         je jump5         jc jump6         mov ax,dat2         add ax,cx         mov dat2,ax         jmp loop1     jump6:mov ax,dat1         add ax,bx         mov dat1,ax         jmp loop1         ;printing LCM     jump5:mov bx,0ah         xor cx,cx         ;push into stack     p1:xor dx,dx         div bx         push dx         inc cx         cmp ax,00h         jne p1         print msg3         ;pop from stack     display:pop dx         add dl,30h         mov ah,02h         int 21h         loop display         mov ah,4ch         int 21h     main endp     end

Saturday, December 11, 2010

Largest of 10 numbers

Share Orkut
        print macro msg         lea dx,msg         mov ah,09h         int 21h     endm     read macro n,j1,j2     j1:mov ah,01h         int 21h         cmp al,0dh         je j2         sub al,30h         mov bl,al         mov ax,n         mov dx,0ah         mul dx         xor bh,bh         add ax,bx         mov n,ax         jmp j1     j2 :nop     endm     .model small     .stack 100h     .data         msg1 db 10,13,'Enter a number: $'         msg2 db 10,13,'Largest= $'         num dw 10 dup(0)         larg dw 0     .code     main proc         mov ax,@data         mov ds,ax         ;read 10 elements         mov cx,0ah         lea si,num     loop1:print msg1         ;read a multidigit number         read [si],jump1,jump2         add si,02         loop loop1         ;asign 1st element as largest         lea si,num         mov ax,[si]         mov larg,ax         mov cx,09h     ;compare larg with other elements     loop2:add si,02         mov ax,[si]         cmp larg,ax         jnc notlarg         mov larg,ax     notlarg:loop loop2         ;printing largest         mov bx,000ah         mov ax,larg         xor cx,cx         ;push into stack     p1:xor dx,dx         div bx         push dx         inc cx         cmp ax,0000h         jne p1         print msg2         ;pop from stack     display:pop dx         add dl,30h         mov ah,02h         int 21h         loop display         mov ah,4ch         int 21h     main endp     end