1

I'm trying to learn assembly language, and currently i've got a question about different assemblers and how to proper run .bin files

Here is the code i'm using in emu8086:

org 100h
mov bx, HELLO_MSG
call print_string

mov bx, GOODBYE_MSG
call print_string

jmp $               

print_string:
    pusha
    mov ah, 0x0e
loop:
    mov al, [bx]
    cmp al, 0
    je return
    int 0x10
    inc bx
    jmp loop

return:
    popa
    ret

HELLO_MSG:
    db 'Hello, World!', 0

GOODBYE_MSG:
    db 'Goodbye!', 0

It works just fine.

However, when i'm using nasm to assemble it (without org 100h, and adding

times 510 -( $ - $$ ) db 0
dw 0xaa55

at the end), it's just not working. I've tried many other options to make it write a string line on screen, but without success.

I'm beginning to suspect that i'm doing something wrong in the process of running this code. These are my steps:

  1. Writing the code, using Notepad++ as a text editor and saving it as *.asm
  2. Assembling this file, using cmd with this command:

    (e.g.)nasm G:\nasm\hello.asm -f bin -o G:\nasm\hello.bin

  3. Using UltraISO to make the .iso image, i'm putting this hello.bin file inside it and setting it as a boot file (it usually works)

  4. After that i'm starting VMWare to boot from this .iso, and after that it just not working (this particular code just showing me an empry screen with _ in the right corner)

PS. I'm on Win7 64bit Thank you in advance for any help you can provide

  • 1
    ORG 0x100 is for MS-DOS .COM files. Boot sectors use ORG 0x7c00 and the segment registers aren't set automatically for you. You need load DS with 0. – Ross Ridge Jun 23 '15 at 00:48
  • @RossRidge thank you, this thing with the DS worked. But now i'm not fully understand why it was so crucial for it to work properly. And i forgot to mention about org 0x7c00, i was using it for nasm – Anton Chupeev Jun 23 '15 at 10:28
  • `org` tells the program where it thinks it'll be loaded in memory (see [this answer](http://stackoverflow.com/a/8140401/1715829))... – Buddy Jun 23 '15 at 18:13
  • @Buddy thank you about your answer, though i already know org, it's still very educational to read about it. I was wondering about the DS register, and how it is affecting the programm behavior – Anton Chupeev Jun 23 '15 at 20:11
  • When you load a value from memory (in `mov al, [bx]`), the value of `bx` is an offset from the start of the "data segment" (the value of which is in `DS`). In the case the data segment should be set to 0. – Buddy Jun 23 '15 at 20:43
  • @Buddy thank you again, now it's more clear for me :D – Anton Chupeev Jun 23 '15 at 21:39

0 Answers0