Tuesday, November 18, 2014

Occurrence of Letter(CASE SENSITIVE)

This is Microprocessor code for Displaying the Number of times that letter repeated the string is read from keyboard using BIOS function...
Algorithm is:

  1. Initialize Data segment
  2. read string from keyboard
  3. point 2 pointer SI and DI to starting of string.
  4. One is used for checking individual character of string with other (DI)
  5. If any Character is repeated Increment BL
  6. After Checking with all the character display the result...


The code is as follows...

;Finding The Occurance of Letter
;Author:AKSHATH KUMAR
;------------------------------------------
;---MACRO FOR DISPLAYING MSG---
printf macro msg
        lea dx,msg
        mov ah,09h
        int 21h
endm
;---------------------------------------------
data segment
msg1 db 10,13,"Enter the String:",10,13,"$"
str1 db 10h,?,10h dup(' ')
len dw 01h dup(0)
msg2 db 10,13,"$"
data ends
;--------------------
code segment
assume cs:code,ds:data
start:
        mov ax,data
        mov ds,ax
        printf msg1
        lea dx,str1
        mov ah,10
        int 21h
        printf msg2
        mov bx,0h
        mov cx,0h
        mov bl,str1[1]
        mov str1[bx+2],"$"
        lea di,str1+2
        mov cl,bl
        mov len,cx
again:
        mov al,ds:[di]
        push cx
        mov cx,len
        mov bl,0h
        lea si,str1+2
up:
   
        cmp al,ds:[si]
        jnz skip
        inc bl
skip:
        inc si
        loop up
        pop cx
        inc di
        add bl,30h
        mov dl,bl
        mov ah,02h
        int 21h
        loop again
        int 3h
code ends
end start

Occurrence of Letter(CASE INSENSITIVE)

This is Microprocessor code for Displaying the Number of times that letter repeated the string is read from keyboard using BIOS function...
Algorithm is:

  1. Initialize Data segment
  2. read string from keyboard
  3. point 2 pointer SI and DI to starting of string.
  4. One is used for checking individual character of string with other (DI)
  5. the concept used is case conversion logic
  6. If any Character is repeated Increment BL
  7. After Checking with all the character display the result...


The code is as follows...

;Finding The Occurrence of Letter(CASE INSENSITIVE)
;Author: AKSHATH KUMAR
;------------------------------------------
printf macro msg
        lea dx,msg
        mov ah,09h
        int 21h
endm
;---------------------------------------------
data segment
msg1 db 10,13,"Enter the String:",10,13,"$"
str1 db 10h,?,10h dup(' ')
len dw 01h dup(0)
msg2 db 10,13,"$"
data ends
;------------------
code segment
assume cs:code,ds:data
start:
        mov ax,data
        mov ds,ax
        printf msg1
        lea dx,str1
        mov ah,10
        int 21h
        printf msg2
        mov bx,0h
        mov cx,0h
        mov bl,str1[1]
        mov str1[bx+2],"$"
        lea di,str1+2
        mov cl,bl
        mov len,cx
        lea si,str1+2
change:
        mov al,[si]
        cmp al,5bh
        ja next
        add al,20h
next:
        mov [si],al
        inc si
        loop change

        mov cx,len
again:
        mov al,ds:[di]
        push cx
        mov cx,len
        mov bl,0h
        lea si,str1+2
up:
   
        cmp al,ds:[si]
        jnz skip
        inc bl
skip:
        inc si
        loop up
        pop cx
        inc di
        add bl,30h
        mov dl,bl
        mov ah,02h
        int 21h
        loop again
        int 3h
code ends
end start



CASE CONVERSION

This is Microprocessor code for Converting Lower Case  letter to upper Case and Vice versa string is read from keyboard using BIOS function...
Algorithm is:

  1. Initialize Data segment
  2. read string from keyboard
  3. point SI to start of string
  4. Check Whether ASCII  value is less than 5Bh if yes add 20h
  5. if ASCII value is greater than 60h then subtract 20h
  6. Store the result in same location
  7. repeat above steps for entire string length
  8. After Checking with all the character display the result...

The code is:


;conversion of lower case to upper case
;Author: Akshath Kumar
;----------------------------------
data segment
msg1 db 10,13,"Enter string:",10,13,"$"
str1 db 10h,?,10h dup(' ')
len db 01h dup(0)
msg2 db 10,13,"Result is:",10,13,"$" 
data ends
;----------------------------------------
code segment
assume cs:code,ds:data
start:
        mov ax,data
        mov ds,ax
        mov bx,0h
        lea dx,msg1
        mov ah,09h
        int 21h
        lea dx,str1
        mov ah,10
        int 21h
        mov bl,str1[1]
        mov str1[bx+2],"$"
        mov len,bl
        mov bl,60h
        mov bh,20h
        lea si,str1+2
        mov cx,0h
        mov cl,len
up:     
        cmp [si],bl
        jae upper
        jb lower
upper:
        sub [si],bh
        jmp skip
lower:  add [si],bh
        jmp skip
skip:   inc si
        loop up
        lea dx,msg2
        mov ah,09h
        int 21h
        lea dx,str1+2
        mov ah,09h
        int 21h
        int 3h
        code ends
        end start