print a string on two different lines
13,214
Solution 1
Here are your specific problems:
- You define
msg
twice (a86 will barf on that). - You call int21 fn9 with the same value of msg so you're not printing the two messages out, just two copies of the first.
- You don't have a newline character in either message so they'll abut each other rather than be on separate lines.
The solutions to those points (without providing the actual code).
- Label the second message as
msg2
. - Load
msg2
into dx before calling int21 for the second time. - Change the messages to put a newline before the '$' symbol (or at least the first one).
Update: Since some other helpful soul has already provided source, here's my solution. I would suggest you learn from this and modify your own code to do a similar thing. If you copy it verbatim from a public site for classwork, you'll almost certainly be caught out for plagiarism:
jmp start ; This will start the program
msg db "Hello Word.",0a,"$" ; A string variable .
msg2 db "Michael J. Crawley$" ; A string variable with a value.
start: mov ah,09 ; subfunction 9 output a string
mov dx,offset msg ; DX for the string
int 21h ; Output the message
mov dx,offset msg2 ; DX for the string
int 21h ; Output the message
exit:
mov ah,4ch
mov al,00 ; Exit code
int 21h ; End program
This outputs:
Hello Word.
Michael J. Crawley
Solution 2
Two definitions of msg?
Author by
Michael
Updated on June 04, 2022Comments
-
Michael almost 2 years
I am trying to get my program to display a string on two different lines.
This is a .com program and I am using A86 assembler.
jmp start ; This will start the program ;============================ msg db "Hello Word.$" ; A string variable msg db "Michael J. Crawley$" ; A string variable with a value. ;============================ start: mov ah,09 ; subfunction 9 output a string mov dx,offset msg ; DX for the string int 21h ; Output the message int 21h ; Output the message exit: mov ah,4ch mov al,00 ; Exit code int 21h ; End program
-
Michael about 14 yearsI am not sure I understand. Should I remove one.... db "Michael J. Crawley$" ; A string variable with a value.
-
Michael Burr about 14 yearsDon't DOS int21 calls return a result code in AX as well so it would have to be reloaded before the 2nd call? Or did DOS just set the carry flag to indicate an error.
-
paxdiablo about 14 years@Michael, not fn9, it returns nothing.
-
Ponkadoodle about 14 years@Mike: No, they each need unique names. You could replace the first "msg" with "msg1", and the second with "msg2".
-
Michael about 14 yearsNo... I am not a copy paste kind of guy I actually want to learn this. I will try it.
-
Michael about 14 years0a is the placement of the string?
-
paxdiablo about 14 years@Mike, 0a is the hex code for a newline (ASCII 10) character. int21/fn9 will intepret this as a request to drop down to the start of a new line.
-
paxdiablo about 14 yearsThis is why a86 is so good and why Harald is so rightly arrogant :-) It will assemble a file without any of the gumpff required by other assemblers - I always hated masm and it's requirement that I had to provide 25 lines of administrivia just to do a 5-line hello world program. Turbo Assembler took away a lot of that but a86 goes all the way.
-
User.1 over 9 yearsBe aware, you might also need a
0Dh
byte along with the0Ah
byte to do a complete new line and carriage return