Author Topic: How to print a message??? Help !!  (Read 18815 times)

nobody

  • Guest
How to print a message??? Help !!
« on: October 18, 2004, 10:26:24 PM »
I am working in DOS with nasm16.
My problem is as follow:

Let us see the example code:

main.asm
----------------------------------------

BITS 16
GLOBAL _start

SECTION .text


_start:
        .............
        .............
        mov si,strWelcomeMsg
        call print_str
        .............
        .............

SECTION .data

; Mensaje de inicio del kernel
  strWelcomeMsg:   db 13,10,"Running Ok",0

--------------------------------------------
Well, if i use with nasm16 -fbin main.asm, work ok.
The value loading in SI register is correct.

But, if I want to generate OBJ file for linking with other modules, SI NOT POINT TO CORRECT ADDRESS OF MESSAGE.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: How to print a message??? Help !!
« Reply #1 on: October 18, 2004, 11:24:28 PM »
Hi Rafa,

Dos loads a .com file with ds (and cs and es and ss and fs and gs) all loaded with the segment it loaded your file to. For an .exe file, ds and es point to PSP, not your data segment. In "-f obj" output format, Nasm knows the special symbol "..start" (you won't have to declare it "global"). ("_start" is the default entrypoint for "-f elf"...). Try:

..start:
    mov ax, data
    mov ds, ax
    ...

And I think it'll work. To use "exe2bin", you may need to pad the file with 100h bytes to account for the PSP - not really sure about that one.

Best,
Frank