Assembly Code to Concatenate two Strings
DATA SEGMENT
STR1 DB "HELLO$"
STR2 DB " INDIA$"
STR DB ?
TMP DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
;SET LOOP COUNTER
MOV CX, 5
;ADDRESS OF STR1
LEA BX, STR1
;ADDRESS OF STR
LEA AX, STR
AGAIN1:
;PICK CHARACTER FROM BX(STR1)
MOV DL, [BX]
;LOAD ADDRESS STR
XCHG BX, AX
;LOAD CHARACTER AT BX(STR)
MOV [BX], DL
;LOAD ADDRESS STR1
XCHG AX, BX
;INCREMENT STR1 ADDRESS
INC BX
;INCREMENT STR ADDRESS
INC AX
LOOP AGAIN1
;ADDRESS OF STR1
LEA BX, STR2
MOV CX, 6
AGAIN2:
;PICK CHARACTER FROM BX(STR21)
MOV DL, [BX]
;LOAD ADDRESS STR
XCHG BX, AX
;LOAD CHARACTER AT BX(STR)
MOV [BX], DL
;LOAD ADDRESS STR2
XCHG AX, BX
;INCREMENT STR2 ADDRESS
INC BX
;INCREMENT STR ADDRESS
INC AX
LOOP AGAIN2
;LOAD ADDRESS OF STR
XCHG BX, AX
;END STR
MOV [BX], "!"
INC BX
MOV [BX], "$"
;PRINT STR
MOV DX, OFFSET STR
MOV AH, 09H
INT 21H
CODE ENDS
DATA SEGMENT
STR1 DB "HELLO$"
STR2 DB " INDIA$"
STR DB ?
TMP DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
;SET LOOP COUNTER
MOV CX, 5
;ADDRESS OF STR1
LEA BX, STR1
;ADDRESS OF STR
LEA AX, STR
AGAIN1:
;PICK CHARACTER FROM BX(STR1)
MOV DL, [BX]
;LOAD ADDRESS STR
XCHG BX, AX
;LOAD CHARACTER AT BX(STR)
MOV [BX], DL
;LOAD ADDRESS STR1
XCHG AX, BX
;INCREMENT STR1 ADDRESS
INC BX
;INCREMENT STR ADDRESS
INC AX
LOOP AGAIN1
;ADDRESS OF STR1
LEA BX, STR2
MOV CX, 6
AGAIN2:
;PICK CHARACTER FROM BX(STR21)
MOV DL, [BX]
;LOAD ADDRESS STR
XCHG BX, AX
;LOAD CHARACTER AT BX(STR)
MOV [BX], DL
;LOAD ADDRESS STR2
XCHG AX, BX
;INCREMENT STR2 ADDRESS
INC BX
;INCREMENT STR ADDRESS
INC AX
LOOP AGAIN2
;LOAD ADDRESS OF STR
XCHG BX, AX
;END STR
MOV [BX], "!"
INC BX
MOV [BX], "$"
;PRINT STR
MOV DX, OFFSET STR
MOV AH, 09H
INT 21H
CODE ENDS
No comments:
Post a Comment