That add command will not do what you think.
Since there is no dollar sign terminating the first name, just do the
int 21h/09h
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. :)
[AFTERWARD]
Once that is fixed, make another program with add commands in it and watch what they do in debug.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
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.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
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:
add msg2,lastname
......or....
add msg2,'$'
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.
sbesch
Junior Poster in Training
61 posts since Aug 2009
Reputation Points: 10
Solved Threads: 8
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
thines01
and
sbesch