Skip to main content
gamedev.net
🔒 Locked

ASM Code Question

Started by ajm0528 Jul 22, 2008 at 7:03 PM 14 replies 4.6k views
Original Post
ajm0528
ajm0528
I have an ASM Code Question. I recently downloaded/installed WinAsm Studio and wanted to test a simple Hello World application. When I assembled the code, I got two errors; one of them I fixed by adding an underscore infront of the 'main proc' statement. The other error says: D:\Programming\helloworld.asm(18) : fatal error A1010: unmatched block nesting : main Here is the code:

.model small
.stack
.data
message   db "Hello world, I'm learning Assembly !!!", "$"

.code

_main   proc
   mov   ax,seg message
   mov   ds,ax

   mov   ah,09
   lea   dx,message
   int   21h

   mov   ax,4c00h
   int   21h
main   endp
end main

Can anyone tell me what's wrong?
Ra
Ra
It looks like you edited your post, and the line with the error appears to be outside of the code you pasted. Can you paste the entire source?
Ra
Oxyd
Oxyd
Quote:
Original post by ajm0528
The other error says: D:\Programming\helloworld.asm(18) : fatal error A1010: unmatched block nesting : main


You gave _main to the proc macro and main to endp -- they need to match. Just add an underscore there. x)

Anon Mike
Anon Mike
Just in case you're not aware, since it seems to come up fairly routinely, the code you have there is 16-bit DOS code. Windows will emulate it for you but it isn't native Windows code (or any other even vaguely modern OS).

I'm not saying that what you're doing is completely wasted effort, but a lot of the kind of stuff people usually start doing as a next step from that point (e.g. talking directly to "video memory") either doesn't work at all or is extremely slow because of the layers of emulation needed to get it to work.
-Mike
ajm0528
ajm0528
Quote:
Original post by Anon Mike
Just in case you're not aware, since it seems to come up fairly routinely, the code you have there is 16-bit DOS code. Windows will emulate it for you but it isn't native Windows code (or any other even vaguely modern OS).

I'm not saying that what you're doing is completely wasted effort, but a lot of the kind of stuff people usually start doing as a next step from that point (e.g. talking directly to "video memory") either doesn't work at all or is extremely slow because of the layers of emulation needed to get it to work.


The tutorial I was looking at is most likely really old. I just found it on a search and saw the Hello World program.


Oxyd, when I add the underscore to the second main statement I get these:

Assembling: D:\Programming\testcode.asm
D:\Programming\testcode.asm(19) : error A2006: undefined symbol : main
D:\Programming\testcode.asm(9) : error A2004: symbol type conflict
D:\Programming\testcode.asm(19) : error A2148: invalid symbol type in expression : main
ajm0528
ajm0528
Ok, i put an underscore infront of all the 'main' statements and I get this:

D:\Programming\testcode.asm(9) : error A2004: symbol type conflict

which marks this line of code in the editor:
mov   ax,seg message
ajm0528
ajm0528
Anyone?
Decrius
Decrius
Are you sure 'seg' has to be infront of 'message'? I'm just a beginner but never saw that in my HW program...
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
ajm0528
ajm0528
Quote:
Original post by Decrius
Are you sure 'seg' has to be infront of 'message'? I'm just a beginner but never saw that in my HW program...


I tried removing 'seg' and I still get errors. Oh well, I was just wanting to mess around with ASM right now but I guess I'll stick to C++.
RabidDog
RabidDog
Wild stab in the dark, have you tried _message?
Decrius
Decrius
This is what 'Assembly Language Step-by-step' from Jeff Dunteman has as HW example. Note that you need to use NASM.

main.asm
bits 16org 0100hsection .textstart:    mov dc, helloworld    mov ah, 9    int 21h    mov ax, 04c00h    int 21hsection .datahelloworld db "Hello world!", 13, 10, "$"


NASM command line: nasm main.asm -f bin -o main.exe
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
ajm0528
ajm0528
Quote:
Original post by RabidDog
Wild stab in the dark, have you tried _message?


Didn't work. Maybe somethings wrong with WinAsm? I'm trying to get NASM to try it out.


I can't even get nasm to work. Maybe ASM isn't for me. :/ I seem to keep getting that stupid error talking about the underscore for 'main' I keep putting one but it still won't work. Even MASM32 gave me the same errors, even on several versions of this code. I can't figure this one out.

[Edited by - ajm0528 on July 23, 2008 5:36:41 PM]
ajm0528
ajm0528
Ok, so....messing around with WinAsm some more I discovered that when I make a new project, if I choose DOS->DosCom, a source file opens with template code that looks like this:
.model tiny.data      msg   db "This is a 16-bit DOS .COM executable",13,10,"Hello World!",13,10,"$" ; The string must ends with a $.code	.startup	mov   dx,offset msg ; Get the address of our message in the DX	mov   ah,9			; Function 09h in AH means "WRITE STRING TO STANDARD OUTPUT"		int   21h			; Call the DOS interrupt (DOS function call)		mov   ah,0			; Call bios function "GET KEYSTROKE"	int   16h	.exitend


When I "Go-All," it works but the DOS window flashes briefly and closes. It doesn't stay open, showing the text. Any ideas on how to make the window pause to stay open?

All in all, the problem is fixed (guess the first tutorial I found was OLD code or something. The code above seems to work just fine. I just need to know how to make the window pause so you can actually read the text.
smitty1276
smitty1276
You need to run it from a command line. Or, perhaps your IDE has an option to keep the window open.
ajm0528
ajm0528
There's also an option for DOS EXE. Still, the window flashes briefly then closes.
Decrius
Decrius
Make a new file, call it 'run.bat'.

Inside run.bat, write this:
mainpause

Where 'main' is the name of your executable (without the extension).
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.