Since there is no dollar sign terminating the first name, just do the
with DX set to the address of the first name. It will continue printing until it hits the dollar sign after the last name.
...which means your first name will need a label.
Also, instead of padding the last name with spaces, pad it with dollar signs. :)
Once that is fixed, make another program with add commands in it and watch what they do in debug.
Thank you thines01
I've changed the codes to
lea dx,msg1 ;prompt
mov ah,0ah ;get input
lea dx,msg2 ;print firstname part
lea dx,lastname ;print lastname part
but it didn't work for lastname, printed some stranger character on screen. do you know why it happened?
If you look at this in debug, is your last name terminated with a dollar sign?
Also, you only need one print.
Print the address of the first name and it will also print the last name until it hits the dollar sign.
My guess is that you did not fill enough dollar signs in the last name.
Thank you, sorry I'm new to assembly and I've no idea to add $ sign to the last name :S
When add $ sign to string (on prompt) it'll show the concatenation mostly correct. I say mostly because it shows two sqaure between first and last name instead of spaces!
msg1 db 0ah,0dh,'Enter your family:$'
msg2 db 0ah,0dh,'Kamiar'
lastname db 21,21 dup(?)
Are you sure that this is what you want? Unless memory fails me, db 21, 21 dup(?) is asking the assembler to generate a byte array consisting of 014h, followed by 21 undefined bytes. I think what you want is something more like:
lastname db ' ', 20 dup('$')
You are also passing the address of the first byte of lastname to Int 21h, which will overwrite the space code intended for separating the first and last name. Put the space at the end of the FirstName string instead.
By the way, in your original post, you tried to "ADD" strings, and or characters, using ADD:
Certainly an interesting concept, but totally foreign to assembly language. ADD is a machine instruction that adds integers. What you were actually doing in the first case was adding the pointer for lastname to the first 2 characters of msg2, then replacing the first 2 characters of msg2 with this rather interesting, but nonsensical, result. In the second case, you were adding the first character in msg2 to the '$' character and then replacing the first character of msg2 with this odd, and probably undefined, character. Concatenating strings is a somewhat more involved process which is frequently provided as a feature in high level languages - often overloaded on the addition operator. I suspect that this is what you were thinking. You need to change your mindset when working in assembler. You can never assume that something is done for you (i.e., using ADD to add strings). Perhaps you should write a function that takes 2 input strings and returns a concatenated version. It would be a good exercise for you.