Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to remove leading, trailing or internal spaces in a string

Posted By: Audris Schmidt     Category: Assembly Language     Views: 4269

Write an assembly program to remove leading, trailing or
internal spaces in a string.

Code for Program to remove leading, trailing or internal spaces in a string in Assembly Language

.model small

.data
        str1 db ' a   b c   ','$'
        len equ $-str1
        cntr dw ?

.code
        mov ax,@data
        mov ds,ax

        mov ah,09h
        LEA DX,str1
        int 21h

        LEA DI,str1
        mov BX,0000
        mov SI,0000
        mov cntr,len
        sub cntr,1
        L1:
                mov ah,str1[SI]
                cmp ah,' '
                je remove
                INC SI
                cmp SI,cntr
                jge ext
                jmp L1



                remove:
                        mov BX,SI
                   R1:
                        mov ah,str1[BX+1]
                        mov str1[BX],ah
                        cmp BX,len
                        jge ChangeLen
                        add BX,1
                        jmp R1

                        ChangeLen:
                                mov str1[BX],'$'
                                sub cntr,1
                                jmp L1
        ext:
                mov ah,09h
                LEA DX,str1
                int 21h

                mov ax,4C00h
                int 21h
end
  
Share: 



Audris Schmidt
Audris Schmidt author of Program to remove leading, trailing or internal spaces in a string is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!