How to print "Hello World" in Assembly for DOS debug.exe

741 views Asked by At

Why does this code did not display "Hello World" I am currently using Assembly language in dos box. This is my first time to code Assembly language.

-a
073F:0100 jmp 126
073F:0102 db 0d, 0a, 'Hello, World!'
073F:0111 db 0d, 0a, '$'
073F:0114 xor ax, ax
073F:0116 mov ah, 9
073F:0118 mov dx, 102
073F:011B int 21
073F:011D mov ax, 4c
073F:0120 int 21
073F:0122
-g 0100

The Hello World did not display when i typed -g 0100. The code also not throwing any errors I just got this output

AX=0000 BX=0000 CX=0000 DX=0000 SP=00FD BP=0000 SI=0000
DI=0000 DS=073F ES=073F SS=073F IP=0100 NV UP EI PL NZ NA PO NC
073F:0100 EB24     JMP    0126
1

There are 1 answers

0
puppydrum64 On

That output is your error message. It's commonly referred to as a "register dump", or a list of what values were in each register at the time of the fault.

073F:0100 jmp 126
073F:0102 db 0d, 0a, 'Hello, World!'
073F:0111 db 0d, 0a, '$'
073F:0114 xor ax, ax
073F:0116 mov ah, 9
073F:0118 mov dx, 102
073F:011B int 21
073F:011D mov ax, 4c
073F:0120 int 21
073F:0122 ?? (anything could be here since you didn't write to it.)
073F:0123 ?? (anything could be here since you didn't write to it.)
073F:0124 ?? (anything could be here since you didn't write to it.)
073F:0125 ?? (anything could be here since you didn't write to it.)
073F:0126 ?? JMP 126 takes you here, but who knows what is here.
-g 0100

The jmp at the beginning was the right idea, because you need to jmp over your string to prevent the CPU from trying to interpret it as executable code. However you just jumped too far in this case. jmp 114 should do the job. I would still recommend using a proper assembler, however.