What is wrong with this build program?

I am very new to assembler programming, so this is probably a very obvious mistake, but ...

I use MSVC ++, and when I compile any project that has a file with the .asm extension, it uses the rule

NAME    EXTENSIONS    COMMAND LINE                                  RULE FILE
MASM    *.asm         ml.exe \c [All Options] [Additional Opti...   C:\Program Files\Microsoft Visual St...

And to make sure the compiler works, I tried the code

main proc
  mov ax, 10
main endp
end main

But when I compiled it, I get three errors

.\compt1.asm(1) : error A2034:must be in segment block : main
.\compt1.asm(2) : error A2034:must be in segment block
.\compt1.asm(3) : fatal error A1010:unmatched block nesting : main

So I'm just wondering if there is any obvious error in the code part, or is it the compiler that messed up.

+3
source share
6 answers

Try the following:

.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 main
+1
source

I assume the code needs some directives, try this:

.model small
.code
main:
  mov ax, 10
end main

.model , , .code , .

EDIT: , , .

; 
  include \masm32\include\masm32rt.inc
;

comment * -----------------------------------------------------
                 Build this console app with
              "MAKEIT.BAT" on the PROJECT menu.
        ----------------------------------------------------- *

  .data?
    value dd ?

  .data
    item dd 0

  .code

start:

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

  call main
  inkey        ; wait for a keystroke before exiting
  exit

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

main proc

  print "Hello World",13,10
  ret

main endp

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

end start

( )

+1

".code" , MASM , . , RETURN , , . , .

+1

segment. segment CODE .

0
source

This seems to work for me using the following lines ML and LINK
ml / coff / c test.asm
link / subsystem: console test.obj

TITLE Test app
.386
.MODEL flat, stdcall
.STACK 4096
; --------------------
.code
main PROC
ret
main ENDP
; --------------------
END main
0
source

Source: https://habr.com/ru/post/1711544/


All Articles