0% found this document useful (0 votes)
7 views

String Functions

Uploaded by

Revanth Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

String Functions

Uploaded by

Revanth Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

13. Implement the following string manipulation functions using appropriate registers.

a) Copy a string b) Lower to upper case

a) Copy a string
org 100h

.DATA

source DB "Assembly Language", 0 ; Source string

destination DB 20 DUP(0) ; Destination string, with enough space to


hold the source string

.CODE

; Copy the string from source to destination

MOV SI, OFFSET source ; Set SI to point to the source string

MOV DI, OFFSET destination ; Set DI to point to the destination string

MOV CX, 0 ; Counter for string length

MOV AL, 0 ; Temporary register to hold characters

COPY_LOOP:

MOV AL, [SI] ; Move a character from source to AL

MOV [DI], AL ; Move the character from AL to destination

INC SI ; Increment SI to point to the next character in source

INC DI ; Increment DI to point to the next character in


destination

INC CX ; Increment the counter

CMP AL, 0 ; Check if the character is null (end of string)

JNZ COPY_LOOP ; If not null, continue copying

; Terminating Program

MOV AH, 09H ; Output function

INT 21H

ret
Output:

b) Lower to upper case

org 100h

.DATA

source DB "assembly", 0 ; Source string

destination DB 20 DUP(0) ; Destination string, with enough


space to hold the source string

.CODE

; Copy the string from source to destination

MOV SI, OFFSET source ; Set SI to point to the source string

MOV DI, OFFSET destination ; Set DI to point to the destination


string

MOV CX, 0 ; Counter for string length

MOV AL, 0 ; Temporary register to hold characters

COPY_LOOP:

MOV AL, [SI] ; Move a character from source to AL

MOV BL,AL ;

SUB BL,32 ; SUBSTRACT 32 TO CONVERT TO UPPERCASE


MOV [DI], BL ; Move the character from AL to destination

INC SI ; Increment SI to point to the next character in


source

INC DI ; Increment DI to point to the next character in


destination

INC CX ; Increment the counter

CMP AL, 0 ; Check if the character is null (end of string)

JNZ COPY_LOOP ; If not null, continue copying

;Terminating Program

MOV AH, 09H ; Output function

INT 21H

ret

output:

c)to LowerCase
org 100h

.DATA

source DB "ASSEMBLY", 0 ; Source string

destination DB 20 DUP(0) ; Destination string, with enough


space to hold the source string

.CODE
; Copy the string from source to destination

MOV SI, OFFSET source ; Set SI to point to the source string

MOV DI, OFFSET destination ; Set DI to point to the destination


string

MOV CX, 0 ; Counter for string length

MOV AL, 0 ; Temporary register to hold characters

COPY_LOOP:

MOV AL, [SI] ; Move a character from source to AL

MOV BL,AL ;

ADD BL,32 ; ADD 32 TO CONVERT TO LOWERCASE

MOV [DI], BL ; Move the character from AL to destination

INC SI ; Increment SI to point to the next character in


source

INC DI ; Increment DI to point to the next character in


destination

INC CX ; Increment the counter

CMP AL, 0 ; Check if the character is null (end of string)

JNZ COPY_LOOP ; If not null, continue copying

;Terminating Program

MOV AH, 09H ; Output function

INT 21H

ret

Output:

You might also like