Page 1 of 2
Nasm problem
Posted: Sun Oct 05, 2008 1:49 pm
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.
Re: Nasm problem
Posted: Sun Oct 05, 2008 2:54 pm
by Combuster
Re: Nasm problem
Posted: Sun Oct 05, 2008 11:25 pm
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?
Re: Nasm problem
Posted: Mon Oct 06, 2008 12:39 am
by pcmattman
Do you update the "mov AH,09h" line?
Re: Nasm problem
Posted: Mon Oct 06, 2008 12:42 am
by sbeng77
I don't understand.
Re: Nasm problem
Posted: Mon Oct 06, 2008 12:45 am
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
Re: Nasm problem
Posted: Mon Oct 06, 2008 1:18 am
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.
Re: Nasm problem
Posted: Mon Oct 06, 2008 2:03 am
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.
Re: Nasm problem
Posted: Mon Oct 06, 2008 2:09 am
by Combuster
Do you know exactly what
does?
Re: Nasm problem
Posted: Mon Oct 06, 2008 2:17 am
by sbeng77
Insert num1 at ax register
Re: Nasm problem
Posted: Mon Oct 06, 2008 2:20 am
by Combuster
sbeng77 wrote:Insert num1 at ax register
and what is "num1"?
Re: Nasm problem
Posted: Mon Oct 06, 2008 2:30 am
by sbeng77
Combuster wrote:sbeng77 wrote:Insert num1 at ax register
and what is "num1"?
DW
Re: Nasm problem
Posted: Mon Oct 06, 2008 3:23 am
by Combuster
That answer would score you zero points on a test for being too obvious, try again.
Re: Nasm problem
Posted: Mon Oct 06, 2008 4:13 am
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!
Re: Nasm problem
Posted: Mon Oct 06, 2008 4:32 am
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