"Don't tell me how hard you work. Tell me how you get done."
- James J. Ling

String concatenation

July 19, 2006

MSG DB ‘Yap$’
MSG2 DB ‘Grainne$’

MOV CX, 3
LEA si, MSG
LEA di, MSG2

recur:
 
 MOV AL, [si]
 MOV [di], AL
 INC si
 INC di
 DEC CX
 JNZ recur

mov al, ‘$’
MOV AH, 09
LEA DX, MSG2
INT 21H
INT 20H

Another way of doing this code at the same time conscious about memory usage daw[coded by Niel]

MSG DB ‘Yap$’
MSG2 DB ‘Grainne$’

mov cx, 3       ; counter for REP instruction
lea si, MSG     ; string to be copied
lea di, MSG2    ; where to copy
cld             ; clear directrion flag
rep movsb       ; store byte from si to di
mov al, ‘$’      ; the NULL terminator. remember? :D
mov [di], al      ; terminate the new string
mov ah, 09      ; print function
lea dx, MSG2    ; string to be printed
int 21h         ; call DOS
int 20h         ; exit to DOS
I tried opening command rather than cmd for my assembly code, but still I’ve waited for a long time and failed to assemble my code. I was told by Niel that it might be because of other issues, for the code assembled properly in his machine. What other issues it might be, I’ll still know about them. As for now, I was told that the output of my assembly code is ‘Yapinne’. I still need to modify this code, because I intend to display ‘Grainne Yap’. I’ll just keep you posted soon!

 

 

Posted by phengpheng at 8:33 pm | permalink

Previous Comments

:D just make di point to where you want to start concatenating. in the second example, your friend "niel" just properly terminated after copying so that MSG2 (which is"Grainne") became a properly terminated string "Yap". =) which isn't what you wanted to achieve.

i modified his listing a little to _really_ do concatenation.

—–

msg db "Yap$"
msg2 db "Grainne$"

lea di, msg2 ; di to msg2
add di, 7 ; go to terminator
mov al, " " ; al is a space
mov [di], al ; replace terminator with a space
inc di ; go to next index

; start concatenation
mov cx, 3
lea si, msg
cld
rep movsb

mov al, "$"
mov [di], al
mov ah, 09
mov dx, offset msg2

int 21h ; call DOS
int 20h ; exit to DOS

—–

output:

Grainne Yap

Posted by yue at July 20, 2006, 5:53 am

put the declarations of string after the code..

MOV CX, 3
LEA si, MSG
LEA di, MSG2
recur:

MOV AL, [si]
MOV [di], AL
INC si
INC di
DEC CX
JNZ recur
mov al, '$'
MOV AH, 09
LEA DX, MSG2
INT 21H
INT 20H

MSG DB 'Yap$'
MSG2 DB 'Grainne$'
or do it this way:

jmp start
MSG DB 'Yap$'
MSG2 DB 'Grainne$'
start:
MOV CX, 3
LEA si, MSG
LEA di, MSG2
recur:

MOV AL, [si]
MOV [di], AL
INC si
INC di
DEC CX
JNZ recur
mov al, '$'
MOV AH, 09
LEA DX, MSG2
INT 21H
INT 20H

Posted by ugin at July 20, 2006, 2:08 pm

add the following codes - "jmp start" and "start:"

jmp start

MSG DB 'Yap$'
MSG2 DB 'Grainne$'

start:

MOV CX, 3
LEA si, MSG
LEA di, MSG2

recur:

MOV AL, [si]
MOV [di], AL
INC si
INC di
DEC CX
JNZ recur

mov al, '$'
MOV AH, 09
LEA DX, MSG2
INT 21H
INT 20H
or place the declaration after the codes:

MOV CX, 3
LEA si, MSG
LEA di, MSG2

recur:

MOV AL, [si]
MOV [di], AL
INC si
INC di
DEC CX
JNZ recur

mov al, '$'
MOV AH, 09
LEA DX, MSG2
INT 21H
INT 20H

MSG DB 'Yap$'
MSG2 DB 'Grainne$'

Posted by ugin at July 20, 2006, 3:15 pm

Sir Ugin! Thank you! Ara ya entende ya yo…

Posted by phengpheng at July 21, 2006, 2:36 pm

All comments are moderated. Your comments will not appear here unless approved by the blog owner. Thank you.

Add a comment








     

July 2006
M T W T F S S
« May   Aug »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

About Me

A Computer Science graduate who is a fanatic in assembly, java, and j2me programming. Developed BlueVoice system (Direct Voice Communication in Mobile Phones), this system allows mobile users to experience FREE VOICE CALLS

Subscribe

Technorati
Bloglines

Tagboard

phengpheng:

Haven’t managed my blog for a long time already because I’m so busy now… Sorry to cause you guyz trouble…

Jun Mark:

hoW tO creaTE a PrOGram thAT woULD oUTpuT ascii table???

Jun Mark:

pLZ anSwer mY qUEstions

cutieGurl:

how to convert binary to hexadecimal, decimal and octal?????????please. answer me??????????

mary ann:

kuya, ung binary to decimal converter nyo. mali man? ung sa mga compare mo. ung may 0,9,A,F etc… bad character lumalabaspls rep asap po. tnx

carol:

how to convert decimal to binary to octal and hexadecimal

Galwin:

been here!

galwin:

nice site. hope you could visit mine, too.

pathy:

FRIENDS FOREVER!! Miss you na!!!

ridvan:

aus, i seldom see lady programmers. hehe. keep it up. and oh yeah, i guess i saw you during the MICT Quiz Show held in cdo. :)
keep up the codes!

phengpheng:

I miss updating this blog… Sana may time and pc ako to learn new stuffs aside from my work…

support:

Congratulations, you’ve just completed the installation of this shoutbox.

pheng:

uy! you’re here again!

Jay:

Woooohhhh orange…sweat… nakakasilaw! hehe :)

jay:

tagboard flood hehe sensya… had nothing fun to do. :)

pheng:

jaaaaayyyyy….:) ketal man?:)

niel:

no spamming please :p hehehe joke lang jay.

Jay:

Uyyyyyy!!!! Grraaaaaaaiiiinnnneeee
:)
Sssshhhh, el sikret! :)
Niiiiiiiiiiiiieeeeeel
Sup dude!!!!
Paaaaaaaaaaaaaathy
Ketal!?

niel:

ei pheng! :D slick-elegant layout! love it!

yue:

phengpheng!

Leave a message ▼