How to run a MS-DOS .asm file using VS2013 or MASM32?

北城余情 提交于 2019-12-08 09:18:05

问题


Here is my test.asm code. Basically 'nothing' inside because just want to get it to build and run without errors first.

.model small
.stack 64
.data
.code

main proc
  mov ax,@data
  mov ds,ax

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

I have tried using visual studio 2013 include the lib, add the linkers and all those guides from websites but no luck. Always getting this error message "error A2006: undefined symbol : DGROUP" for both MASM32 and visual studio 2013.

Please guide me step by step on the build and run.. Also, i tried using dosbox and this is as far i can go..

Keep having the illegal command. What am I doing wrong? :(

回答1:


To paraphrase: how do I inflate a bicycle tire with a potato?

Your assembly is 16-bit, and you're targeting MS-DOS (the int21 call is a giveaway). Neither VS2013 nor MASM32 is capable of generating DOS executables. Try a different assembler, i. e. NASM. Alternatively, read up on modern assembly.




回答2:


VS doesn't include a 16-bit tool set. The most common 16-bit Microsoft assembler / tool set is MASM (ML.EXE) 6.11. (There's a patch to update it to 6.14, but then you need a dos extender or you need to run it from a 32-bit dos console window). There may be other 16-bit versions of MASM apparently available for download. Hopefully these will include instructions for how to install and setup the environment variables.

There are other programs that go along with Microsoft's 16 bit tool set, a linker, codeview (source level debugger), nmake (make utility), h2inc (converts a c .h file into an assembler .inc file), qh (quick help), pwb (programmer's work bench, a text base integrated development environment), and 16 bit versions of C / C++.

DGROUP normally groups _data, _bss, and stack into a single segment, but if you're using .model, you shouldn't need to reference it, and the names are different, like @data instead of _data. Example .asm file (the ,c means that C calling convention is used).

        .model  small,c
        .data
;       ...                     data goes here
        .stack  2048
        .code
        assume  cs:@code,ds:@data,es:nothing,ss:nothing
;-----------------------------------------------------------------------;
;       main                                                            ;
;-----------------------------------------------------------------------;
main    proc    far
        mov     ax,@data
        mov     ds,ax
        mov     es,ax
;       ...                     code goes here
        mov     ax,04c00h
        int     21h
main    endp
        end     main



回答3:


How to build a MSDOS program with MASM32 and run it in DOSBox

Download MASM32 and DOSBox for Windows and install them. MASM32 should be afterwards in C:\masm32 and DOSBox in %ProgramFiles^(x86)%\DOSBox-0.74 resp. %ProgramFiles%\DOSBox-0.74.

Start the MASM Quick Editor (qeditor.exe) and load menus.ini.

Scroll down to

&Run Program,"{b}.exe"

[&Tools]

Insert five lines:

&Run Program,"{b}.exe"
-
Assemble 16-bit .asm to .obj,cmd /C\masm32\bin\ml.exe /c "{a}" & pause
Link 16-bit .obj to .exe,cmd /C\masm32\bin\link16.exe "{b}" ,,,,, & pause
Build 16-bit .asm to .exe,cmd /C\masm32\bin\ml.exe /Bl"C:\masm32\bin\link16.exe" "{a}" & pause
Run in DosBox,cmd /Cstart /D"%ProgramFiles(x86)%\DOSBox-0.74" DOSBox.exe "{b}.exe"

[&Tools]

Eventually you have to change %ProgramFiles(x86)% to %ProgramFiles% - where DOSBox had been installed. Type in a command prompt SET and look which directories are allocated to that environment variables. Save the file and restart the MASM32 Quick Editor. Now you have under "Project" three new items at the end.

Type in a MS-DOS assembly program in MASM syntax:

.MODEL small
.STACK 1000h
.DATA
    hello db "Hello world!", 13, 10, '$'
.CODE
main PROC
    mov ax, @DATA           ; Initialize DS
    mov ds, ax

    mov dx, OFFSET hello    ; You can also write lea dx, hello
    mov ah, 09h             ; http://www.ctyme.com/intr/rb-2562.htm
    int 21h

    mov ax, 4C00h           ; http://www.ctyme.com/intr/rb-2974.htm
    int 21h
main ENDP
END main

and save it under an 8.3 name e.g. hello.asm.

Click on Project/Build 16-bit .asm to .exe and close the window by pressing any key. Now click on Project/Run in DosBox. The DOSBox windows will open and the program will run. The DOSBox windows stay open, so you start the program then at the command prompt there, e.g. type in "hello.exe".



来源:https://stackoverflow.com/questions/27217167/how-to-run-a-ms-dos-asm-file-using-vs2013-or-masm32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!