Sinan Samet
Sinan Samet

Reputation: 6752

Writing a string to a file gives output with weird characters in assembly

I am trying to save my string to a file in assembly but it gives me this weird output with "ver 2.40 (all kinds of special characters)"

This is what I do:

mov ah,09
mov dx,200
int 21
int 20

e 200 "Test$"
n test.com
r cx
:0009
w
q

It saves it succesfully and it also runs fine when I don't exit the program and use "g" but when I "q" and try to run test.com it gives me the output I mentioned.

Upvotes: 1

Views: 433

Answers (3)

Frank Kotler
Frank Kotler

Reputation: 3119

int 20 is not the problemm I don't think. 9 in cx is not enough to write code at 100 (presumably) and string at 200. I think you want w 100 also. If this is not DEBUG, forgive me.

Upvotes: 1

Weather Vane
Weather Vane

Reputation: 34583

My DOS book says of int 20h

This was the standard way to terminate DOS programs on DOS V1. With the introduction of DOS functions 4Ch and 31h this is no longer the recommended way to terminate a program unless it must maintain compatibility with DOS V1 systems.

I suggest you use int 21h function AH = 4Ch with AL set to a return code.

Upvotes: 0

rkhb
rkhb

Reputation: 14409

I presume you're using DEBUG.EXE.

After e 200 "Test$" do a d 200. You see the memory dump beginning at offset 200. This looks like:

16C7:0200  54 65 73 74 24 00 00 00-00 00 00 00 00 00 00 00   Test$...........
16C7:0210  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
16C7:0220  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
16C7:0230  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
16C7:0240  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
16C7:0250  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
16C7:0260  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
16C7:0270  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................

Now count the offset up until you reach the 24: 200, 201, 202, 203, 204 - You want to store the memory from offset 100h until 204h, this are 105h bytes (204h-100h+1).

This value is to be stored in CX:

r cx
:0105

With w you write CX bytes.

Upvotes: 2

Related Questions