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
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
Dave,
You had posted a nice example here (http://www.masm32.com/board/index.php?topic=12621.msg97236#msg97236) - 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
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
Okay that helps. Thank you.
I realized I had commands set up in Visual Studio to handle 16-bit assembler programs.
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)
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.
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
I have the Irvine components and the code as posted works for me under Windows 2000. How are you assembling and linking?
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 !!!
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
Irvine16.inc starts with:
.model small,stdcall
.stack 4096
.386
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.
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
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.
well - it has been a good exercise
but, stick with 32-bit code :U
Quote from: magus841 on May 09, 2010, 04:09:04 AM
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.
Running time should not be a problem for 16-bit code. However,
if the C++ is 32-bit it should not work at all.
Regards,
Steve N.