2

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
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Kroi
  • 246
  • 3
  • 9
  • 2
    Maybe you intended to do `jmp 114` to jump over the data and start executing at the `xor ax,ax` which is at offset 114. I think you also want to use `g =0100` . `g 0100` will start executing at CS:IP which by default will be at offset 0100 of the current CS segment. `g 0100` will set a break point at 0100 and likely started at offset 0100. You need to use an `=` to specify a specific offset to start executing at. – Michael Petch Sep 30 '20 at 09:59
  • 2
    May be easier to simply put the data at the end instead of trying to jump over it. Also, your system call to terminate is being done wrong: `4c` should go to `ah`, and exit code to `al`, while you're doing it backwards. I.e. instead of `mov ax, 4c` there should be `mov ax, 4c00`. – Ruslan Sep 30 '20 at 10:14
  • @MichaelPetch It works, but how will I know if the **xor ax, ax** will go on `114` because some time i do `jmp 114` but the `xor ax, ax` is in `113` – Kroi Sep 30 '20 at 10:25
  • 2
    Because you are using DOS DEBUG you are forced to really compute by hand all the instructions and offsets ahead of time or assemble everything at least once and figure out the offsets and go back and reenter the appropriate ones a second time. The offsets will change as your data changes. DOS DEBUG is just a simple assembler that doesn't understand labels like a real assembler. I recommend if you are using DOS to use something like TASM (Turbo assembler) or MASM. You can put your instructions in an assembly file, use labels for offsets rather than values etc. – Michael Petch Sep 30 '20 at 10:28

1 Answers1

0

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.

puppydrum64
  • 1,598
  • 2
  • 15