alaphate Posted April 20, 2009 Posted April 20, 2009 (edited) The code below can be compiled and linked to an .exe file.However, when I executed it, it "encountered a problem, and needs to be closed".MASM32 has no @data macro, how to get the msg's DS address?Thank you for help in advance..386.model flat, stdcall.data msg db "Hello World!$".codeMain PROC ;mov ax,@data ;mov ds,ax lea dx,msg mov ah,9 int 21 int 20Main ENDPend Main Edited April 20, 2009 by alaphate
enhzflep Posted April 21, 2009 Posted April 21, 2009 The code below can be compiled and linked to an .exe file.However, when I executed it, it "encountered a problem, and needs to be closed".MASM32 has no @data macro, how to get the msg's DS address?You should really use an assembler that's designed to produce 16 bit DOS executables.I just looked at the start of your source - you've told it to use a flat memory model DOS didn't have a flat memory model - it was cut into 64kb segments - I'm about 90% sure this won't fly.Never bothered to write exe file using assembler until I did it under windows - I always wrote .com files since they hadno header and one could easily produce a 10byte executable.When writing dos .com files, DS is the same as CS. I.e code and data reside in the same segment.All you have to do is mov ax, cs mov ds, axorpush cs pop dsNasm combined with NasmIDE used to be my toolset of choice under DOS. You can find both windows and dos versions here:http://sourceforge.net/project/showfiles.php?group_id=6208
alaphate Posted April 21, 2009 Author Posted April 21, 2009 (edited) Enhzflep,Thank you for your help.I downloaded TASM5.0, and the code below can run successfully.Then, the problem comes to how to convert it to MASM version.Especially, this line: mov ax, @data, because no @data syntax in MASM.The program has data segment because it uses small model.I don't know why I should fill DS when the program starts.I think DS should be auto-filled when the program starts.Does @data have value before the program starts?.model small.data msg db "Hello world!$".codemain: mov ax, @data mov ds, ax mov dx, offset msg mov ah,9h ;print string in dx int 21h mov ah,4ch ;terminate process int 21hend main Edited April 21, 2009 by alaphate
enhzflep Posted April 21, 2009 Posted April 21, 2009 (edited) Enhzflep,Thank you for your help.The program has data segment because it uses small model.I don't know why I should fill DS when the program starts.I think DS should be auto-filled when the program starts.Does @data have value before the program starts?That's okay, a pleasure. Yes, from memory DS is set to the correct segment by the OS between loading and executing the code (though that may only be when you use the .tiny memory model)As to the question about the @data notation in masm, it's as easy as writing "seg data" Here's a masm source for a HelloWorld..model small .stack .data message db "Hello world!", "$" .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 mainCheck out this thread for a 600kb zip of some dos asm stuff: http://www.masm32.com/board/index.php?topic=10213.0The above code comes from this tutorial: http://www.xs4all.nl/~smit/asm01001.htm Edited April 21, 2009 by enhzflep
alaphate Posted April 21, 2009 Author Posted April 21, 2009 Enhzflep,Thank you very much!Now I can compile it under MASM.The tutorial is very helpful. Thx, bro!
X-88 Posted May 28, 2016 Posted May 28, 2016 (edited) How to make hello world gui application using easy code go asm? [solved] http://masm32.com/board/index.php?topic=514.0 Edited May 28, 2016 by X-88
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now