Nasm problem

Programming, for all ages and all languages.
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Nasm problem

Post by sbeng77 »

Hi,
i'm trying win32 nasm:

segment code
main:

mov dx,message
mov AH,9
int 0x21
;mov ax,0x4c00
int 0x21
ret
segment data
message db 'test','$'

on dos shell i digit:

nasm -o test.com -f bin test.asm

Now, when i execute this test.com, it print many "strange" characters and also "test" string. Which is error?
Thank you.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Nasm problem

Post by Combuster »

Code: Select all

ORG 100h
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Re: Nasm problem

Post by sbeng77 »

Ok,
now it's ok.
There's code:

org 100h
message db 'Hello',13,10,'$'

main:

mov dx, message
mov AH,09h
int 21h

I don't understand if i try to replace "Hello" with "test", it give me an error of "CS:...." during executing file.exe/com. Why?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Nasm problem

Post by pcmattman »

Do you update the "mov AH,09h" line?
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Re: Nasm problem

Post by sbeng77 »

I don't understand.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Nasm problem

Post by pcmattman »

Wait, never mind. I was thinking of the wrong int 21 function - been a while since I've delved into that sort of stuff.

You might want to put the "message db...." line after the code, otherwise it might possibly attempt to execute the string. There's no segments or whatnot in a COM file ;)
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Re: Nasm problem

Post by sbeng77 »

I permit to extend this thread with another question:

org 100h

mov ax,num1
add ax,num2
aaa
mov dx,ax
mov ah,09h
int 21h
mov ah,4Ch ; ah = 4Ch
int 21h
num1 DW 10
num2 DW 15

I would sum num1 with num2 and print to screen. When executing this code it give me bad characters and not only 25. :(
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Nasm problem

Post by pcmattman »

You need to convert the integer to a string first - at the moment it'll write the ASCII character 25, not 2 and 5.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Nasm problem

Post by Combuster »

Do you know exactly what

Code: Select all

mov ax,num1
does?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Re: Nasm problem

Post by sbeng77 »

Insert num1 at ax register :)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Nasm problem

Post by Combuster »

sbeng77 wrote:Insert num1 at ax register :)
and what is "num1"?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Re: Nasm problem

Post by sbeng77 »

Combuster wrote:
sbeng77 wrote:Insert num1 at ax register :)
and what is "num1"?

DW
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Nasm problem

Post by Combuster »

That answer would score you zero points on a test for being too obvious, try again.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sbeng77
Posts: 17
Joined: Mon Sep 29, 2008 8:06 am
Contact:

Re: Nasm problem

Post by sbeng77 »

org 100h

mov al,num1
add al,num2

mov dx,ax
mov ah,09h
int 21h
mov ah,4Ch ; ah = 4Ch
int 21h

num1 db 5
num2 db 3


Ok, now i've sum two number but when execute this code it prints me many bad characters! :(
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Nasm problem

Post by AJ »

I think what Combuster was getting at is that you are actually loading ax and dx with pointers.

The second problem is that for DOS interrupts, a quick look in RBIL shows that Int 21h ah = 09h reveals that DS:DX should contain a pointer to a '$' terminated string. You need to convert your numeric answer to a string (once you have learned what [] does) and then add '$' termination, also ensuring that DS points where expected.

Cheers,
Adam
Post Reply