Author Topic: I feel so stupid, but...  (Read 12346 times)

nobody

  • Guest
I feel so stupid, but...
« 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

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: I feel so stupid, but...
« Reply #1 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