NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: nobody on April 15, 2005, 04:55:01 AM

Title: I feel so stupid, but...
Post by: nobody on April 15, 2005, 04:55:01 AM
dseg segment .data

Letter DB 'H'

cseg segment .text

MOV AX, dseg
   MOV DS, AX

MOV AH, 02H
   MOV DL, [Letter]
   INT 21H

MOV AH, 4CH
   INT 21H

Why won't this print out the letter 'H'? It's instead printing out some strange symbol ?. I'm using the 16-bit version of NASM, by the way. Compiling it with:
nasm -o test.com -f bin test.asm
Title: Re: I feel so stupid, but...
Post by: Frank Kotler on April 15, 2005, 07:20:41 AM
> dseg segment .data

segment .data

>         Letter DB 'H'
>
> cseg segment .text

segment .text

>         MOV AX, dseg
>         MOV DS, AX

These two lines are needed for an .exe file, but you don't want 'em for a .com file. Dos loads a .com file with segment registers pointed to your one-and-only segment. But your .com file is loaded into memory at offset 100h into that segment, so you *do* need:

org 100h

>         MOV AH, 02H
>         MOV DL, [Letter]
>         INT 21H
>
>         MOV AH, 4CH
>         INT 21H
>
> Why won't this print out the letter 'H'? It's instead printing out some strange
> symbol ?.

A case of Nasm not calculating a value for "Letter" such that ds:Letter actually points to your letter.

> I'm using the 16-bit version of NASM, by the way.

Why? Unless you're running on a 286, that isn't the build you want!

> Compiling
> it with:
> nasm -o test.com -f bin test.asm

That should be right.

Best,
Frank