.Notice  - Last Update:1988/07/09 17:30
Importance Notice: The information contained in this option are for quick
                   reference only. The accuracy of it should be based on your
                   language manual.
Set Up By        : Kuang H. Tseng
Language         : MACRO ASSEMBLER(5.0) by Microsoft(R)
. 1.   Language Elements
    Character Sets
         A-Z, a-z, 0-9, ? @ _ $ : . [ ] ( ) < > { } + - / *
         & % ! ' ~ | \ = # ^ ; , ` "
    Data fields - (refer to separate key line for more detail)
    Constants - (refer to separate key line for more detail)
    Keywords
    Comments - after special character ';'
    Tokens
    Identifiers - (refer to separate key line for more)
    Macros
    Instructions - (refer to separate key line for more)
    Operators - (refer to separate key line for more)
    Declarations
    Program Line
    Compiler Directives - (refer to separate key line for more)
    Compiler Options - (refer to separate key line for more)
. 2.   Data fields
    DB (byte) - 1 byte
    DW (word) - 2 bytes
    DD (doubleword) - 4 bytes
    DF (farword) - 6 bytes
    DQ (quadword) - 8 bytes
    DT (tenbytes) - 10 bytes
. 3.1  Identifiers (symbols/names/labels)
    - Alphabetic letters A to Z, digits 0 to 9, special characters ? . @ _ $
      (but ? or $ can not stand alone as identifier)
    - The first character must be an alphabetic letter, a special character or .
    - Default is case insensitive but can be overruled with compiler option
    - Up to 31 characters are significant
. 3.2  Predefined Equate Symbols
    @Code     - alias equate for .CODE segment name
    @CodeSize - numeric equate indicates code memory model,0/1/2
    @CurSeg   - current segment name
    @Data     - alias equate for .DATA data group name
    @DataSize - numeric equate that indicates the data memory model
    @FarData  - alias equate for initialized far data segment name
    @FarData? - alias equate for uninitialized far data segment name
    @FileName - current source file
. 3.3  Constants
    Integers
         Binary - radix specifier B, i.e., 01011010B
         Octal -  radix specifier Q or O
         Decimal - radix specifier D
         Hexadecimal - radix specifier H, number start with a decimal digit
    Packed binary coded decimals
    Real numbers - consist of an integer part,a fractional part and an exponent
    Strings - consist of one or more ASCII characters enclosed in ' or "
. 4.1. Operators
  Arithmetic Operator
    +         addition
    -         subtraction/negative unary
    *         multiplication
    /         integer division
    MOD       remainder(modulus)
  Index Operator
    []        addition
  Shift Operator
    SHR
    SHL
  Logical Operators
    NOT       bitwise complement
    AND       bitwise AND
    OR        bitwise inclusive OR
    XOR       bitwise exclusive OR
  Relational Operators
    EQ        true if equal
    NE        true if not equal
    LT        true if less than
    LE        true if less than and equal
    GT        true if greater than
    GE        true if greater and equal
  Segment Override Operator
    :         address relative to a specific segment
  Type Operator
    PTR
    SHORT
    THIS
    HIGH/LOW
    OFFSET
    SEG
    .TYPE
    TYPE
    LENGTH
    SIZE
. 4.2. Operator Precedence
    LENGTH,SIZE,WIDTH,MASK,(),[],<>
    .
    :
    PTR,OFFSET,SEG,TYPE,THIS
    HIGH,LOW
    +,-
    *,/,MOD,SHL,SHR
    +,-(binary)
    EQ,NE,LT,LE,GT,GE
    NOT
    AND
    OR,XOR
    SHORT,.TYPE
. 5.1. List of Instructions (all processors) by Name & Description in Name order
    AAA - ASCII adjust after addition
    AAD - ASCII adjust before division
    AAM - ASCII adjust after multiply
    AAS - ASCII adjust after subtraction
    ADC - add with carry
    ADD - add
    AND - logical and
    CALL - call procedure
    CBW - convert byte to word
    CLC - clear carry flag
    CLD - clear direction flag
    CLI - clear interrupt flag
    CMC - complement carry flag
    CMP - compare two operands
    CMPS/CMPSB/CMPSW/CMPSD - compare string
    CWD - convert word to double
    DAA - decimal adjust after addition
    DAS - decimal adjust after subtraction
    DEC - decrement
    DIV - unsigned divide
    ESC - escape
    HLT - halt
    IDIV - signed divide
    IMUL - signed multiply
    IN - input from port
    INC - increment
    INT - interrupt
    IINTO - interrupt on overflow
    IRET/IRETD - interrupt return
    JA/JNBE - jump if above/not below or equal
    JB/JNAE - jump if below/not above or equal (unsigned comparisons)
    JAE/JNB - jump if above or equal/not below (unsigned comparisons)
    JBE/JNA - jump if below or equal/not above (unsigned comparisons)
    JE/JZ - jump if equal(zero)
    JNE/JNZ - jump if not equal(not zero)
    JL/JNGE - jump if less/not greater or equal (signed comparisions)
    JGE/JNL - jump if greater/not less or equal (signed comparisions)
    JLE/JNG - jump if less or equal/not greater (signed comparisions)
    JG/JNLE - jump if greater/not less or equal (signed comparisions)
    JS - jump if sign
    JNS - jump if not sign
    JC - jump if carry
    JNC - jump if not carry
    JO - jump if overflow
    JNO - jump if not overflow
    JP/JPE - jump if parity/parity even
    JNP/JPO - jump if no parity/parity odd
    JCXZ/JECXZ -jump if CX is zero
    JMP - jump unconditionally
    LAHF -load flags into AH register
    LDS/LES/LFS/LGS/LSS - load far pointer
    LEA - load effective address
    LES/LFS/LGS - load far pointer to extra segment
    LOCK - lock the bus
    LODS/LODSB/LODSW/LODSD - load string operand
    LOOP - loop
    LOOPE/LOOPZ - loop if equal
    LOOPNE/LOOPNZ - loop if not equal
    LSS - load far pointer to stack segment
    MOV - move data
    MOVS/MOVSB/MOVSW/MOVSD - move string data
    MUL - unsigned multiply
    NEG - two's complement negation
    NOP - no operation
    NOT - one's complement negation
    OR - inclusive or
    OUT - output to port
    POP - pop
    POPF/POPFD - pop flags
    PUSH - push
    PUSHF/PUSHFD - push flags
    RCL/RCR/ROL/ROR - rotate
    REP MOVS/MOVSB/MOVSW - repeat string move
    REP STOS/STOSB/STOSW - repeat store string
    REPE/REPZ CMPS/CMPSB/CMPSW - repeat compare string while equal
    REPE/REPZ SCAS/SCASB/SCASW - repeat scan string while equal
    REPNE/REPNZ CMPS/CMPSB/CMPSW - repeat compare string while not equal
    REPNE/REPNZ SCAS/SCASB/SCASW - repeat scan string while not equal
    RET/RETN/RETF - return from procedure
    ROL/ROR - rotate
    SAHF - store ah into flags
    SAL/SAR/SHL/SHR - shift
    SBB - subtract with borrow
    SCAS/SCASB/SCASW/SCASD - scan string flags
    STC - set carry flag
    STD - set direction flag
    STI - set interrupt flag
    STOS/STOSB/STOSW/STOSD - store string data
    SUB - subtract
    TEST - logical compare
    WAIT - wait
    XCHG - exchange
    XLAT/XLATB - translate
    XOR - exclusive or
. 5.2. List of Instructions (80186-80386) by Name & Description in Name order
    BOUND - check array bounds
    ENTER - make stack frame
    INS/INSB/INSD/INSW - input from port to string
    LEAVE - terminate stack frame initialized by ENTER instruction
    OUTS/OUTSB/OUTSD/OUTSW - output a string to a port
    PUSHA - push all general-purpose registers onto stack
    POPA - pop the top 16 bytes of the stack onto DI,SI,BP,SP,BX,DX,CX,AX
. 5.3. List of Instructions (80286-80386) by Name & Description in Name order
    ARPL - adjust requested
    CLTS - clear task switched flag
    LAR - load access rights
    LGDT/LIDT/LLDT - load descriptor table
    LMSW - load machine status word
    LSL - load segment limit
    LTR - load task register
    SGDT/SIDT/SLDT - store descriptor table
    SMSW - store machine status word
    STR - store task register
    VERR/VERW - verify read or write
. 5.4. List of Instructions (80386 only) by Name & Description in Name order
    BSF/BSR - bit scan
    BT/BTC/BTR/BTS - bit tests
    CDQ - convert doubleword to quadword
    CMPSD - compare string in doubleword data element size
    CWDE - convert word to extended double
    INSD - input from port to string in doubleword data element size
    IRETD - interrupt return
    JECXZ - jump if CX is zero
    LFS/LGS/LSS - load far pointer to stack segment
    LODSD - load string operand in doubleword data element size
    MOVSD - move string data in doubleword data element size
    MOVSX - move with sign-extend
    MOVZX - move with zero-extend
    OUTSD - output string to port in doubleword data element size
    POPFD - pop flags into the 32-bit flags register
    POPAD - pop 32-bit registers of AX,CX,DX,BX,SP,BP,DI
    PUSHAD - push 32-bit registers of AX,CX,DX,BX,SP,BP,SI,DI
    PUSHFD - push the 32-bit flags register
    SCASD - scan string in doubleword data element size
    SETA - set if above
    SETAE - set if not above or equal
    SETB - set if below
    SETC - set if carry
    SETE - set if equal/zero
    SETG - set if greater
    SETGE - set if not greater or equal
    SETL - set if less
    SETLE - set if less or equal
    SETNA - set if not above
    SETNAE - set if not above or equal
    SETNB - set if not below
    SETNBE - set if not below or equal
    SETNC - set if not carry
    SETNE - set if not equal
    SETNG - set if not greater or equal
    SETNGE - set if not greater or equal
    SETNL - set if not less
    SETNLE - set if not less or equal
    SETNO - set if not overflow
    SETNP - set if not parity
    SETNS - set if not sign
    SETNZ - set if not zero
    SETO - set if overflow
    SETP - set if parity
    SETPE - set if parity even
    SETS - set if sign
    SETZ - set if zero
    SHLD/SHRD - double precision shift
    STOSD - store string data in doublewod data element size
. 5.5. List of Instructions (8087-80387) by Name & Description in Name order
    F2XM1 - 2^X-1
    FABS - absolute value
    FADD/FADDP/FIADD - add
    FCHS - change sign
    FCLEX/FNCLEX - clear exceptions
    FCOM/FCOMP/FCOMPP/FICOM/FICOMP - comapar
    FDECSTP - decrement stack pointer
    FDISI/FNDISI - disable interrupts
    FDIV/FDIVP/FIDIV - divide
    FDIVR/FDIVRP/FIDIVR - divide reversed
    FENI/FNENI - enable interrupts
    FFREE - free register
    FIST/FISTP - store integer
    FLD/FILD/FBLD - load
    FLDCW - load control word
    FLDENV - load environment state
    FINCSTP - increment stack pointer
    FINIT/FNINIT - initialize coprocessor
    FLD1/FLDZ/FLDPI/FLDL2E/FLDL2T/FLDLG2/FLDLN2 - load constant
    FMUL/FMULP/FIMUL - multiply
    FNOP - no operation
    FPATAN - partial arctangent
    FPREM - partial remainder
    FPTAN - partial tangent
    FRNDINT - round to integer
    FRSTOR - restore saved state
    FSAVE/FNSAVE - save coprocessor state
    FSCALE - scale
    FSQRT - square root
    FST/FSTP/FIST/FISTP/FBSTP - store
    FSTCW/FNSTCW - store control word
    FSTENV/FNSTENV - store environment state
    FSTSW/FNSTSW - store status word
    FSUB/FSUBP/FISUB - subtract
    FSUBR/FSUBRP/FISUBR - subtract reversed
    FWAIT - wait
    FXAM - examine
    FXCH - exchange registers
    FXTRACT - extract exponent and significand
    FYL2X - Y log2(X)
    FYL2XP1 - Y log2(X+1)
. 6.1. EXE program structure
         TITLE     progname
         .MODEL    SMALL
         .DATA
         EXTRN     ?:BYTE
         .CODE
         PUBLIC    progname
progname proc
         ret
progname endp
         END
. 6.2. COM program structure
         TITLE pgmname
CODESEG SEGMENT PARA PUBLIC 'CODE'
         ASSUME CS:CODESEG,DS:CODESEG,ES:CODESEG,SS:CODESEG
         ORG 0100H
BEGIN: JMP PGM_START
; enter variables here
VAR1     DB        ?
PGM_START:
; enter logic here
         MOV  VAR1,0
         RET
CODESEG  ENDS
         END BEGIN
. 7.1  Sample of Main Program
; sample 1
         title     program1
         DOSSEG                   ;Use Microsoft segment convention
cr       EQU       0dh            ;carriage return
lf       EQU       0ah            ;linefeed
         .MODEL    SMALL
         .STACK    64
         .DATA
messg    DB      'Welcome to MASM Assembler programming with kEDITOR',cr,lf,'$'
         .CODE
start:   mov       ax,@DATA       ;load segment address to ds
         mov       ds,ax

         mov       dx,OFFSET messg
         mov       ah,09h
         int       21h

         mov       ax,4C00h       ;AH=4Ch (DOS Exit function),AL=0 error free
         int       21h
         END       start
. 7.2  Sample of Main Program calling a Subprogram
; sample 2
         title     program2
         DOSSEG                   ;Use Microsoft segment convention
cr       EQU       13             ;carriage return
lf       EQU       10             ;linefeed
         .MODEL    SMALL
         .STACK    64
         .DATA
messg    DB        'Sample program - Calling subprograms',cr,lf
len_mess EQU       $-messg
         .CODE
start:   mov       ax,@DATA       ;load segment address to ds
         mov       ds,ax
         call      messout        ;calling subprogram messout
         call      done           ;calling subprogram done

messout  proc
         mov       bx,1           ;file handle 1 for standard output
         mov       cx,len_mess
         mov       dx,OFFSET messg
         mov       ah,40h
         int       21h
         ret
messout  endp

done     proc
         mov       ax,4C00h       ;AH=4Ch (DOS Exit function),AL=0 error free
         int       21h
done     endp
         END       start
. 7.3  Sample of Macro Writing
; sample 3
         title     program3
         DOSSEG                   ;Use Microsoft segment convention
         .MODEL    SMALL
         .STACK    64
DOSCALL  MACRO     intno
         mov       ah,intno
         int       21h
         ENDM
         .DATA
cr       EQU       13             ;carriage return
lf       EQU       10             ;linefeed
messg    DB        'Sample program - Macro Writing',cr,lf
len_mess EQU       $-messg
         .CODE
start:   mov       ax,@DATA       ;load segment address to ds
         mov       ds,ax

         mov       bx,1           ;file handle 1 for standard output
         mov       cx,len_mess
         mov       dx,OFFSET messg
         DOSCALL   40h            ;use macro definition DOSCALL

         mov       al,0           ;error free
         DOSCALL   4Ch

         END       start
. 7.4  Sample 1 of String Copying Processing
str1     DB        'Sample program - String Handling',cr,lf
str1len  EQU       $-str1
str2     DB        50 DUP(' ')
         ...
         cld
         mov       si,offset str1
         mov       di,offset str2
         mov       cl,str1len
         xor       ch,ch
         shr       cx,1
         jnc       moveword
         movsb
moveword:
         rep       movsw
. 7.5  Sample 2 of String Copying Processing
         cld                      ;move/copy string from string1 to string2
         lea       si,string1
         lea       di,string2
         mov       cx,len_str1
         rep movsb
         mov       cx,len_str1
         mov       dx,OFFSET string2
. 7.6  Sample of String Searching Processing
         cld                      ;use of scasb to scan
         mov       cx,len_str2
         lea       di,string2
         mov       al,'l'         ;scan string2 for 'l'
         repne scasb
         jne       notfnd         ;not found
found:   mov       ah,0           ;found
         dec       di             ;point back to offset of 'l'
         jmp short jump
         
notfnd:  mov       ah,1
jump:
. 7.7  Sample of Table Processing
; sample 5
         title     program5
         DOSSEG                   ;Use Microsoft segment convention
         .MODEL    SMALL
         .STACK    64
         .DATA
table    DB        'MONDAY   '
         DB        'TUESDAY  '
         DB        'WEDNESDAY'
         DB        'THURSDAY '
         DB        'FRIDAY   '
         DB        'SATURDAY '
         DB        'SUNDAY   '
NINE     DB        9
table_width EQU    9
weekday  DB        9 dup(" ")
         .CODE
start:   mov       ax,@DATA       ;load segment address to ds
         mov       ds,ax
         mov       es,ax

         lea       si,table
         mov       al,3           ;third weekday 
         dec       al
         mul       NINE
         add       si,ax
         mov       cx,table_width
         cld
         lea       di,weekday
         rep  movsb               ;should have 'WEDNESDAY' in weekday
         
         mov       ax,4C00h       ;error free
         int       21h

         END       start
. 7.8  Sample of Loop Processing
         jcx       jumploop
zeroloop:
         mov       byte ptr [si],0
         inc       si
         loop      zeroloop
jumploop:
. 7.9  Sample of Subroutine Interface with C
_SumOf3  proc
         push      bp
         mov       bp,sp
         sub       sp,2
         mov       ax,[bp+4]
         add       ax,[bp+6]
         mov       [bp-2],ax
         mov       ax,[bp+8]
         add       ax,[bp-2]
         mov       sp,bp
         pop       bp
         ret
_SumOf3  endp
. 8.   Compiler Directives
Segment
    SEGMENT        ENDS      GROUP          ASSUME         END
Data Allocation
    DB   DW   DD   DF   DQ   DT   LABEL     ALIGN     EVEN ORG
. 9.   Compiler Options
    /A                  writes segments in alphabetical order
    /B                  sets buffer size
    /C                  specifies a cross-reference file
    /D                  creates Pass 1 listing
    /Dsymbol[=value]    Defines assembler symbol
    /E                  creates code for emulated floating-point instructions
    /H                  lists command-line syntax and all assembler options
    /Ipathname          sets include-file search path
    /L                  specifies an assembly-listing file
    /ML                 makes names case sensitive
    /MU                 converts names to uppercase letters
    /MX                 makes public and external names case sensitive
    /N                  suppresses tables in listing file
    /P                  checks for impure code
    /S                  writes segments in source-code order
    /T                  suppresses messages for successful assembly
    /V                  displays extra statistics to screen
    /W{0/1/2}           sets error display level
.10.   BIOS Interrupts
    INT 05H             Print the screen
    INT 10H   00H       Set video mode
              01H       Set cursor size  
              02H       Set cursor position
              03H       Read cursor position
              04H       Read light-pen position
              05H       Set active display page
              06H       Scroll window up
              07H       Scroll window down
              08H       Read character and attribute at cursor position
              09H       Write character and attribute at cursor
              0AH       Write character
              0BH       Set color palette
              0CH       Write graphics pixel dot
              0DH       Read graphics pixel dot
              0EH       Write character in teletype (TTY) mode
              0FH       Get current video display mode
              10H       Set palette registers
              13H       Write character string
    INT 11H             Equipment Determination
    INT 12H             Memory Size Determination
    INT 13H   00H       Reset diskette system
              01H       Get diskette status
              02H       Read diskette sectors
              03H       Write diskette sectors
              04H       Verify diskette sectors
              05H       Format disk track
    INT 14H   00H       Initialize serial communications port parameters
              01H       Send character to communications port
              02H       Read character from communications port
              03H       Get serial communications port status
    INT 16H   00H       Read a character
              01H       Check if character is ready for reading
              02H       Get current shift status
    INT 17H   00H       Printer output
              01H       Initialize printer port
              02H       Read printer port status
    INT 18H             ROM BASIC entry
    INT 19H             Bootstrap loader
    INT 1AH   00H       Read time clock
              01H       Set time clock
              04H       Read date from time clock
              05H       Set date in time clock
.11.   DOS Interrupts
    INT 21H   00H       Program terminate
              01H       Keyboard input with echo
              02H       Display character output
              03H       Auxiliary input
              04H       Auxiliary output
              05H       Printer output
              06H       Direct console input/output
              07H       Direct console input without echo
              08H       Character input without echo
              09H       Display character string
              0AH       Buffered keyboard input
              0BH       Get keyboard status
              0CH       Clear keyboard buffer and then input
              0DH       Disk reset
              0EH       Select default disk drive
              0FH       Open file
              10H       Close file
              11H       Search for first matching disk filename
              12H       Search for next matching disk filename
              13H       Delete file
              14H       Sequential read
              15H       Sequential write
              16H       Create file
              17H       Rename file
              19H       Get default disk drive
              1AH       Set disk transfer area address
              1BH       Get allocation table information
              21H       Random read
              22H       Random Write
              23H       Get file size (in record count)
              24H       Set random record number
              25H       Set interrupt vector
              26H       Create a new program segment prefix
              27H       Random block read
              28H       Random block write
              29H       Parse filename
              2AH       Get date
              2BH       Set date
              2CH       Get time
              2DH       Set time
              2EH       Set/reset verify switch
              2FH       Get disk transfer area address
              30H       Get MS-DOS version number
              31H       Terminate and stay resident
              33H       Get/set Ctrl-Break
              35H       Get interrupt vector
              36H       Get free disk space
              38H       Get/set country-dependent information
              39H       Make subdirectory
              3AH       Remove subdirectory
              3BH       Change current directory
              3CH       Create file
              3DH       Open file
              3EH       Close file
              3FH       Read from file or device
              40H       Write to file or device
              41H       Delete file
              42H       Move file pointer
              43H       Get/set file attributes
              44H       IOCTL - Device driver control
              45H       Duplicate file handle
              46H       Force handle duplication
              47H       Get current directory
              48H       Allocate memory
              49H       Release allocated memory
              4AH       Modify allocated memory block
              4BH       Load/execute program
              4CH       Terminate process with return code
              4DH       Get return code of subprogram
              4EH       Search for first match
              4FH       Search for next match
              54H       Get verify flag
              56H       Rename file
              57H       Get/set file date and time
              58H       Get/set allocation strategy
              59H       Get extended error code information
              5AH       Create temporary file
              5BH       Create new file
              5CH       Lock/unlock file access
              62H       Get PSP address
    INT 22H             Terminate address
    INT 23H             Control-C/Control Break address
    INT 24H             Critical error handler address
    INT 25H             Absolute disk read
    INT 26H             Absolute disk write
    INT 27H             Terminate and stay resident
    INT 2FH             Print spool control
.12.   Keyboard Scan Codes
    Key  in HEX  in Dec        Key  in HEX  in Dec        Key  in HEX  in Dec
    ---  ------  ------        ---  ------  ------        ---  ------  ------
    A a    1E      30          F1     3B      59           1     02       2
    B b    30      48          F2     3C      60           2     03       3
    C c    2E      46          F3     3D      61           3     04       4
    D d    20      32          F4     3E      62           4     05       5
    E e    12      18          F5     3F      63           5     06       6
    F f    21      33          F6     40      64           6     07       7
    G g    22      34          F7     41      65           7     08       8
    H h    23      35          F8     42      66           8     09       9
    I i    17      23          F9     43      67           9     0A      10
    J j    24      36          F10    44      68           0     0B      11
    K k    25      37
    L l    26      38           !     02       2         Left    4B      75
    M m    32      50           @     03       3         Right   4D      77
    N n    31      49           #     04       4          Up     48      72
    O o    18      24           $     05       5         Down    50      80
    P p    19      25           %     06       6
    Q q    10      16           ^     07       7       Num Lock  45      69
    R r    13      19           &     08       8    Scroll Lock  46      70
    S s    1F      31           *     09       9      Caps Lock  3A      58
    T t    14      20           (     0A      10         Prt Sc  37      55
    U u    16      22           )     0B      11
    V v    2F      47          _ -    0C      12         Home    47      71
    W w    11      17          + =    0D      13          End    4F      79
    X x    2D      45          | \    2B      43         PgUp    49      73
    Y y    15      21          { [    1A      26         PgDn    51      81
    Z z    2C      44          } ]    1B      27
                               : ;    27      39          Ins    52      82
     Esc   01       1          " ',   28      40          Del    53      83
     Tab   0F      15          < ,.   33      51
    Ctrl   1D      29          > .    34      52     Left Shift  2A      42
     Alt   38      56          ? /    35      53    Right Shift  36      54
 Space Bar 39      57          ~ `    29      41            -    4A      74
   Return  1C      28      Backspace  0E      14            +    4E      78
