im using fasm (flat assembler 1.68), and im trying to output a string with int21h/ah=09h

jmp main
msg db "hello world$"
main:
mov dx, msg
mov ah, 09
int 21h

this code outputs "hello world", but it outputs some control characters before it ([SOME WEIRD CONTROL CHARACTERS]hello world)

so how can i fix this?

Strange.

Presumably DOS, or you'd get nothing.

I notice the lack of a return statement. The control chars may appear at the beginning of the line, but that doesn't mean they were printed before your message. You might be running past the end of your program, and hitting something that moves the cursor, then prints who-knows-what.

Also, I don't see any segment setup, so this is a com program?

Strange.

Presumably DOS, or you'd get nothing.

I notice the lack of a return statement. The control chars may appear at the beginning of the line, but that doesn't mean they were printed before your message. You might be running past the end of your program, and hitting something that moves the cursor, then prints who-knows-what.

Also, I don't see any segment setup, so this is a com program?

yes its DOS, and yes its a com program. And that was only part of the program.

even if i put

mov ah, 4Ch
int 21h

or 'ret'

i still see control characters before my message

Hmmm... not a fasm user, so just some other observations. No org statement, or use 16 statement. Thought fasm syntax was a dollar symbol before hex numbers, but that may be optional. Some assemblers need exe2bin to fix linkage of programs. Maybe give us the whole program and the process you follow and it could attract a solution.

Actually, it's so short, a dir listing of executable (so we see file size) and use debug to dump the contents, and post it here.

Hmmm... not a fasm user, so just some other observations. No org statement, or use 16 statement. Thought fasm syntax was a dollar symbol before hex numbers, but that may be optional. Some assemblers need exe2bin to fix linkage of programs. Maybe give us the whole program and the process you follow and it could attract a solution.

Actually, it's so short, a dir listing of executable (so we see file size) and use debug to dump the contents, and post it here.

Heres the disassembly:

1462:0100 EB0C          JMP     010E
1462:0102 68            DB      68
1462:0103 65            DB      65
1462:0104 6C            DB      6C
1462:0105 6C            DB      6C
1462:0106 6F            DB      6F
1462:0107 20776F        AND     [BX+6F],DH
1462:010A 726C          JB      0178
1462:010C 64            DB      64
1462:010D 24BA          AND     AL,BA
1462:010F 0200          ADD     AL,[BX+SI]
1462:0111 B409          MOV     AH,09
1462:0113 CD21          INT     21
1462:0115 B44C          MOV     AH,4C
1462:0117 CD21          INT     21
1462:0119 0200          ADD     AL,[BX+SI]
1462:011B B409          MOV     AH,09
1462:011D CD21          INT     21
1462:011F B44C          MOV     AH,4C
-u
1462:0121 CD21          INT     21

Ha! Isn't funny how we overlook the obvious? When you pointed DX at 0002, you forgot that your program actually loads at 0100. Just change

MOV     DX,0002

to

MOV     DX,0102

BTW, here's how to use debug to get a decent listing (ok, pathetic listing, but we're using "debug")

-u100,101
139A:0100 EB0C          JMP     010E
-d102,10d
139A:0100        68 65 6C 6C 6F 20-77 6F 72 6C 64 24           hello world$
-u10e,122
139A:010E BA0200        MOV     DX,0002
139A:0111 B409          MOV     AH,09
139A:0113 CD21          INT     21
139A:0115 B44C          MOV     AH,4C
139A:0117 CD21          INT     21
139A:0119 0200          ADD     AL,[BX+SI]
139A:011B B409          MOV     AH,09
139A:011D CD21          INT     21
139A:011F B44C          MOV     AH,4C
139A:0121 CD21          INT     21

thanks, turns out i should of had an org statement in the first place

need code snake game
run emu8086

Hi, I'm trying to print the $ character. I tried putting a "\" but it didnt work..
Any idea??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.