it does assemble using MASM, although both versions have little problems :P
both versions use a .END directive, but do not reference the entry point
your version doesn't initialize the DS register, nor does it terminate properly
as Jochen mentioned, this is 16-bit code and will build if you use a 16-bit linker
i have never used the .STARTUP or .EXIT directives, so i was curious to see exactly what they do
i figured the .STARTUP directive sets the DS register and .EXIT terminates with INT 21h
well, i was half-right :P
.EXIT generates the following code, at least when the SMALL model is specified
mov ah,4Ch
int 21hit may generate something different if the TINY model is specified
the code generated by .STARTUP was a little more surprising
again, this is for a SMALL model program and it undoubtedly generates something different for other models
mov ax,@data
mov ds,ax
mov bx,ss
sub bx,ax
shl bx,4
mov ss,ax
add sp,bxthe first 2 lines are pretty simple
they load the data segment into AX, then into DS - very common code for 16-bit EXE's
the rest of the code forces the SS register to reference the same segment as the DS register
a bit of a mystery for a beginner, probably
but it's forcing the .DATA segment and .STACK segment into a single GROUP
not really sure why they do that - it isn't necessary, in many cases
personally, i would write the program to look something like this...
;###############################################################################################
.MODEL SMALL
.386
;###############################################################################################
.DATA
X db 3
;###############################################################################################
.CODE
;***********************************************************************************************
_main PROC FAR
mov ax,@data
mov ds,ax
MOV AL,5
ADD AL,X
mov ah,4Ch
int 21h
_main ENDP
;###############################################################################################
END _maini would also add a couple other directives, but that's beyond what the teacher wants
you could replace the first 2 lines of code with .STARTUP and the last 2 with .EXIT, just to make him happy :P
_main PROC
.STARTUP
MOV AL,5
ADD AL,X
.EXIT
_main ENDP
the program doesn't appear to do much when you run it
but, it does return an exit code of 8 (5+X), that could be accessed in a batch file with ERRORLEVEL commands