News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Help starting program.

Started by magus841, May 09, 2010, 12:50:00 AM

Previous topic - Next topic

magus841

Hey all. I was having some trouble just getting this program to assemble. I had been using and include file that would generally take care of "house-keeping" things but I'm trying to get away from that and just write the program using MS-DOS interrupts and such. Here's my code:


TITLE blah (main.asm)

dosseg
.model small
.stack 100h

.data
prompt BYTE 'Please enter a line. End your line with a period.',  0ah, 0dh, 00h

.code
main PROC

mov ax, @data
mov ds, ax

        mov dx, offset prompt
        mov ah, 9
        int 21h


ret
exit

main ENDP

END main


I keep the getting the following errors and I'm not quite sure what they mean since I am pretty sure my syntax is correct. Still pretty bad at this. I appreciate any help :)

1>.\main.asm(3) : warning A4015:directive ignored with /coff switch
1>.\main.asm(22) : error A2008:syntax error : exit
1>.\main.asm(13) : error A2006:undefined symbol : DGROUP
1>.\main.asm(26) : warning A4023:with /coff switch, leading underscore required for start address : main

dedndave

you are trying to link a 16-bit OBJ with a 32-bit linker
see the sticky threads in the 16-bit programming sub-forum   :bg

jj2007

Dave,

You had posted a nice example here - my adaptation below.

Magus,
What you posted is 16-bit code. You need the 16-bit linker for that, and other command line options depending on your assembler.

.Model small ; credits to DednDave
.Stack 512

.Data
MsgText db "Hello World", 13, 10
db "Press any key to continue ...", 13, 10, "$"

.Code

_main proc FAR

; set the DS register to DGROUP (will fail with later Masm versions - use ml 6.14, 6.15 or JWasm)
mov ax, @DATA
mov ds, ax

; display the message
mov dx, offset MsgText
mov ah, 9
int 21h

; wait for a key
mov ah, 0
int 16h

; the DOS equivalent to ExitProcess
mov ax, 4C00h
int 21h

_main endp

end _main

RichMasm options:
OPT_Linker link16 ; must be in lowercase
OPT_Assembler JWasm ; if you use JWasm ([url=http://www.japheth.de/JWasm.html]here[/url]), you may activate this option by deleting the x
OxPT_Assembler mlv615
OPT_DebugA /nologo /omf ; activate by deleting the x if you are using recent versions of ml.exe

These options are not really needed:
OPT_Wait 0 ; 1=wait for a keystroke before closing the console
OPT_DebugL /nologo ; put any additional option on the linker command line here
OPT_Res 0

dedndave

thanks Jochen
here is a link to d/l a 16-bit linker
i should mention that it is a self-extracting zip file
so, the first time you execute it, it just extracts the linker executable
(can cause some confusion for beginners - and me)

http://website.masm32.com/microsoft/Lnk563.exe

place the extracted EXE file in the masm32\bin folder
in the batch files Jochen points to, i had written them for the linker to be named Link16.exe instead of Lnk563.exe
simply make sure the name of the linker EXE file matches the one in the batch file
Link16.exe, Lnk563.exe, and Link563.exe are all the same version of the linker - just named differently

magus841

Okay that helps. Thank you.

I realized I had commands set up in Visual Studio to handle 16-bit assembler programs.

dedndave

cool   :U

i might add.....

the file inside the self-extracting ZIP archive file is the same name as the archive, itself
so, when you want to extract it, it prompts for an over-write - it is ok to over-write, unless you want it in both forms

(it would be less confusing if the EXE was in a regular ZIP file - probably smaller, too)

magus841

My program assembles without errors. But when I go to run it, I get this message in the console window: "The system cannot execute the specified program." Nothing more, nothing less. My code: (it didn't really change).


TITLE blah (main.asm)

Include Irvine16.inc

.data
prompt db 'Please enter a line. End your line with a period.',  0ah, 0dh, 00h

.code
main PROC

     mov ax, @data
     mov ds, ax

     mov dx, offset prompt
     call WriteString

exit

main ENDP

END main


Edit: I'm running on Windows Vista Home Premium 32-bit. Not sure if that helps.

dedndave

wellllll - i dunno what Kip has for WriteString
try this....
TITLE blah    (main.asm)

Include Irvine16.inc

.data
promptA db 'Please enter a line. End your line with a period.',  0Dh, 0Ah, 24h

.code
main PROC

     mov ax, @data
     mov ds, ax

     mov dx, offset promptA
     mov ah,9
     int 21h

     mov ax,4C00h
     int 21h

main ENDP

END main

notice, i changed the string terminator
i also changed the label to promptA - Kip may use "prompt" for something else

MichaelW

I have the Irvine components and the code as posted works for me under Windows 2000. How are you assembling and linking?
eschew obfuscation

dedndave

Quote"The system cannot execute the specified program."

this error sounds like it is trying to access I/O ports or memory addresses not allowed under NT
but, Michael might be right - maybe something is fishy in the EXE header or something

EDIT - oh - i see no stack segment !!!

dedndave

try assembling this one - just to see if the batch file, assembler, and linker are set up correctly
        .MODEL SMALL
        .STACK 512

;------------------------------------------------------------

        .DATA

MsgText db 'Hello World',13,10
        db 'Press any key to continue ...',13,10,36

;------------------------------------------------------------

        .CODE

_main   PROC    FAR

;set the DS register to DGROUP

        mov     ax,@DATA
        mov     ds,ax

;display the message

        mov     dx,offset MsgText
        mov     ah,9
        int     21h

;wait for a key

        mov     ah,0
        int     16h

;terminate

        mov     ax,4C00h
        int     21h

_main   ENDP

;------------------------------------------------------------

        END     _main

MichaelW

Irvine16.inc starts with:

.model small,stdcall
.stack 4096
.386


eschew obfuscation

magus841

Alright, that worked. It has something to do with the way I set up the project file.

I like working in Visual Studio and I followed Irvine's guide to set up Visual Studio to assemble 32-bit and 16-bit applications. And I've been generally just using his project templates to start my assignments and it's worked so far. Guide is here: http://kipirvine.com/asm/gettingStarted/index.htm

Either way, this has all been very helpful and I thank you :) now I just need to optimize C++ code with assembly language. That's the reason I was trying to get this to work.

dedndave

perhaps you are creating a 32-bit program with 16-bit elements inside it
for example, a 32-bit program would not like the 16-bit method of setting the data segment register
maybe a review of how you have it set up ?

at least you know the assembler works   :P

magus841

I realize that now. I was starting with a 32-bit template and I was trying to make it function like it was a 16-bit application. Didn't work so well. I'm tired...

But a general question: would it drastically affect run time/processing speed if I used a 16-bit application vs. a 32-bit one? What I'm basically trying to do is optimize a C++ function by calling a routine that's written in assembler to do the function.