the .MODEL directive tells the assembler what 16-bit memory model to use
16-bit code on an 80x86 processor uses segmented memory
the memory model can be tiny, small, medium, compact, large, huge
tiny model - all code, data, and stack space fits into one 64 kb segment
small model - all code is in one 64 kb segment, all data is in one 64 kb segment, stack is in one 64 kb segment
the other models have multiple code segments, multiple data segments, or both
huge was rarely used, where a data segment must be contiguous across more than 64 kb
when i say "64 kb segment", i am refering to the maximum size
for 16-bit intel CPU's, memory was addressed by using a segment register and an offset
the segment registers for 80x86 processors are CS, DS, ES, SS
code, data, extra data, stack
each segment register points to the base of a 64 kb segment of memory
a physical address on older CPU's was calculated as
16 x segment + offset
only 64 kb may be addressed at a time, using one segment register value
this is because the offset is only 16 bits wide
but, by using segment registers, you can address 1 mb of memory
newer processors are able to work this way for backward compatibility
.386 - tells the assembler which instruction set to allow
the default is .8086
nowdays, we use .586 or .686, mostly, for 32-bit programs
but, for 16-bit code, .386 allows the use of older 32 bit instructions
.STACK 1024 - creates a stack segment with 1024 bytes of stack space
the assembler uses default names and attributes for segments created this way
OPTION CaseMap:None - means that label names are case sensitive
after that, you can use .DATA, .DATA?, and .CODE to open segments with little typing
again, the assembler uses default names and attributes for segments created this way
in the old days, we used to create segments something like this
_TEXT SEGMENT WORD PUBLIC 'CODE'
_TEXT ENDS
but, most of us use the simplified directives, now
segments cannot be nested, so when you open one segment, it closes any previously opened segment
FAR and NEAR procedures differ in the type of RET instruction that is used
this tells the assembler whether to use RETN or RETF when it sees RET in the source code
it also tells the assembler whether to use a FAR call or a NEAR call when calling the procedure
for NEAR calls, only the instruction pointer is pushed onto the stack
so, when you RETurn, only the IP is popped off with RETN
for FAR calls, the code segment is pushed, then the instruction pointer
this allows for calls into different code segments
by nature, 16-bit EXE's use a far procedure for the main entry point
16-bit tiny model programs would use a near procedure for the main entry point
procedures other than the main entry may be near or far, depending on the segment
quite often, they can be near because the procedure is in the same segment as the call
if you google around, you will find the masm programmers reference guide
it's a lot of reading - most of which may not mean anything until you get your feet wet
but, all this stuff is explained in that manual