TPH0[:Editor CommandsPredefined SymbolsMASM/TASM Mode EquivalentsAscii ChartsKey Scan CodesOptimizing PASCAL with ASMOptimizing C with ASM
The Registers8086 InstructionsChoosing a "MODEL"TASM Command Line ParametersTLink Command Line Parametersó?.█"Ü%-é1ä4▀K|MäR
Cursor Movement Commands 
-------------------------------------------- 
Character left       Ctrl-S or Left arrow 
Character right      Ctrl-D or Right arrow 
Word left            Ctrl-A or Ctrl-Left 
                      arrow 
Word right           Ctrl-F or Ctrl-Right 
                      arrow 
Line up              Ctrl-E or Up arrow 
Line down            Ctrl-X or Down arrow 
Scroll up            Ctrl-W 
Scroll down          Ctrl-Z 
Page up              Ctrl-R or PgUp 
Page down            Ctrl-C or PgDn 
Last position        Ctrl-Q P 


Insert & Delete Commands 
-------------------------------------------- 
Insert mode on/off     Ctrl-V or Ins 
Insert line            Ctrl-N 
Insert options         Ctrl-O O 
Delete line            Ctrl-Y 
Delete to end of line  Ctrl-Q Y 
Delete character left  Ctrl-H or Backspace 
Delete character       Ctrl-G or Del 
Delete word right      Ctrl-T 
Delete block           Ctrl-K Y 

Block Commands 
-------------------------------------------- 
Mark block begin      Ctrl-K B 
Mark block end        Ctrl-K K 
Mark single word      Ctrl-K T 
Copy block            Ctrl-K C 
Move block            Ctrl-K V 
Delete block          Ctrl-K Y 
Read block from disk  Ctrl-K R 
Write block to disk   Ctrl-K W 
Hide/display block    Ctrl-K H 
Print block           Ctrl-K P 
Miscellaneous Commands 
-------------------------------------------- 
Load new file         F3 
Pick List             Alt-F3 
Assemble/Compile      F8 
Link                  F9 
Show Next/Prev Error  F5/F6 
Tab                   Ctrl-I or Tab 
Tab mode              Ctrl-O T or Ctrl-Q T 
Fill mode             Ctrl-O F 
Autoindent on/off     Ctrl-O I or Ctrl-Q I 
Unindent mode         Ctrl-O U 
Restore line          Ctrl-Q L 
Set place marker      Ctrl-K n 
Find place marker     Ctrl-Q n 


Miscellaneous Commands con't 
-------------------------------------------- 
Control character prefix      Ctrl-P 
Abort operation               Ctrl-U 
Find                          Ctrl-Q F 
Find & replace                Ctrl-Q A 
Repeat last find              Ctrl-L 
Editor/Menu Toggle            <ESC>/F10 
Search Options 
------------------------------------------- 
B         Searches backward 
G         Searches globally 
L         Searches locally 
n         n = any number; searches n times 
N         Replaces without asking 
U         Ignores uppercase/lowercase 
W         Searches for whole words only 

Symbol           Description 
-------------------------------------------------------
@code           Code segment name 
@codesize       0=Small, Compact model; 1=All others 
@cpu            Enabled processor instrcutions 
@curseg         Current segment name 
@data           Near data segment 
@datasize       Data memory model: 0=Tiny, Small, Med.
                 1=Compact; 2=Huge 
@fardata        Far data segment name 
@fardata?       Far uninitialized data segment name 
@filename       Assembly filename as equated symbol 
@wordsize       Segment address size: 2=16 bit; 4=32 
??date          Today's date 
??filename      Assembly filename as string 
Symbol           Description 
-------------------------------------------------------
??time          Current system time (DOS Country code)
??version       Turbo Assembler version number 
                 [HIGH byte (major), LOW byte (minor)]




Symbols may be UPPER or lower case, as you desire. 



MASM Mode         IDEAL Mode 
--------------------------------------- 
.186              P186 
.286              P286 
.286C             P286N 
.286P             P286N 
.287              P287 
.386              P386 
.386C             P386N 
.386P             P386N 
.387              P387 
.8086             P8086 
MASM Mode         IDEAL Mode 
--------------------------------------- 
.8087             P8087 
.ALPHA            DOSSEG 
.CODE             CODESEG 
 COMMENT          (none) 
.CONST            CONST 
.CREF             %CREF 
.DATA             DATASEG 
.DATA?            UDATASEG 
.ERR              ERR 
.ERR1             ERRIF1 
MASM Mode         IDEAL Mode 
--------------------------------------- 
.ERR2             ERRIF2 
.ERRB             ERRIFB 
.ERRDEF           ERRIFDEF 
.ERRDIF           ERRIFDIF 
.ERRE             ERRIFE 
.ERRIDN           ERRIFIDN 
.ERRIDNI          ERRIFIDNI 
.ERRNB            ERRIFNB 
.ERRENDEF         ERRIFNDEF 
.ERRNZ            ERRIF 
MASM Mode         IDEAL Mode 
--------------------------------------- 
.FARDATA          FARDATA 
.FARDATA?         UFARDATA 
.LALL             %MACS 
.LFCOND           %CONDS 
.LIST             %LIST 
.MODEL            MODEL 
 %OUT             DISPLAY 
 PAGE             %PAGESIZE 
.RADIX            RADIX 
.SALL             %NOMACS 
MASM Mode         IDEAL Mode 
--------------------------------------- 
.SEQ              (none) 
.SFCOND           %NOCONDS 
.STACK            STACK 
 SUBTTL           %SUBTTL 
.TFCOND           (none) 
 TITLE            %TITLE 
.TYPE             SYMTYPE 
.XALL             (none) 
.XCREF            %NOCREF 
.XLIST            %NOLIST 


DC HX CH  DC HX CH       DC HX CH  DC HX CH 
0  00 NL │ 1 01           2 02    │ 3 03 
4  04   │ 5 05          6 06   │ 7 0F   
8  08   │ 9 09  HT      10 0A FF │11 0B   
12 0C    │13 0D  CR      14 0E   │15 0F   
16 10   │17 11         18 12   │19 13   
20 14   │21 15         22 16   │23 17   
24 18   │25 19         26 1A    │27 1B   
28 1C   │29 1D         30 1E   │31 1F   
32 20  SP│33 21  !       34 22  " │35 23  # 
36 24  $ │37 25  %       38 26  & │39 27  ' 
40 28  ( │41 29  )       42 2A  * │43 2B  + 
44 2C  , │45 2D  -       46 2E  . │47 2F  / 
48 30  0 │49 31  1       50 32  2 │51 33  3 
52 34  4 │53 35  5       54 36  6 │55 37  7 
56 38  8 │57 39  9       58 3A  : │59 3B  ; 

DC HX CH   DC HX CH       DC HX CH   DC HX CH 
60 3C  < │ 61 3D  =       62 3E  > │ 63 3F  ? 
64 40  @ │ 65 41  A       66 42  B │ 67 43  C 
68 44  D │ 69 45  E       70 46  F │ 71 47  G 
72 48  H │ 73 49  L       74 4A  J │ 75 4B  K 
76 4C  L │ 77 4D  M       78 4E  N │ 79 4F  O 
80 50  P │ 81 51  Q      82 52   R │ 83 53  S 
84 54  T │ 85 55  U      86 56   V │ 87 57  W 
88 58  X │ 89 59  Y      90 5A   Z │ 91 5B  [ 
92 5C  \ │ 93 5D  ]      94 5E   ^ │ 95 5F  _ 
96 60  ` │ 97 61  a      98 62   b │ 99 63  c 
100 64 d │101 65  e      102 66  f │103 67  g 
104 68 h │105 69  i      106 6A  j │10F 6B  k 
108 6C l │109 6D  m      110 6E  n │111 6F  o 
112 70 p │113 71  q      114 72  r │115 73  s 
116 74 t │117 75  u      118 76  v │119 77  w 

DC  HX CH  DC  HX CH      DC  HX CH  DC  HX CH 
120 78  x │121 79  y      122 7A  z │123 7B  { 
124 7C  | │125 7D  }      126 7E  ~ │127 7F   
128 80  Ç │129 81  ü      130 82  é │131 83  â 
132 84  ä │133 85  à      134 86  å │135 87  ç 
136 88  ê │137 89  ë      138 8A  è │139 8B  ï 
140 8C  î │141 8D  ì      142 8E  Ä │143 8F  Å 
144 90  É │145 91  æ      146 92  Æ │147 93  ô 
148 94  ö │149 95  ò      150 96  û │151 97  ù 
152 98  ÿ │153 99  Ö      154 9A  Ü │155 9B  ¢ 
156 9C  £ │157 9D  ¥      158 9E  ₧ │159 9F  ƒ 
160 A0  á │161 A1  í      162 A2  ó │163 A3  ú 
164 A4  ñ │165 A5  Ñ      166 A6  ª │167 A7  º 
168 A8  ¿ │169 A9  ⌐      170 AA  ¬ │171 AB  ½ 
172 AC  ¼ │173 AD  ¡      174 AE  « │175 AF  » 
176 B0  ░ │177 B1  ▒      178 B2  ▓ │179 B3  │ 

DC  HX CH  DC  HX CH      DC  HX CH  DC  HX CH 
180 B4  ┤ │181 B5  ╡      182 B6  ╢ │183 B7  ╖ 
184 B8  ╕ │185 B9  ╣      186 BA  ║ │187 BB  ╗ 
188 BC  ╝ │189 BD  ╜      190 BE  ╛ │191 BF  ┐ 
192 C0  └ │193 C1  ┴      194 C2  ┬ │195 C3  ├ 
196 C4  ─ │197 C5  ┼      198 C6  ╞ │199 C7  ╟ 
200 C8  ╚ │201 C9  ╔      202 CH  ╩ │203 CB  ╦ 
204 CC  ╠ │205 CD  ═      206 CE  ╬ │207 CF  ╧ 
208 D0  ╨ │209 D1  ╤      210 D2  ╥ │211 D3  ╙ 
212 D4  ╘ │213 D5  ╒      214 D6  ╓ │215 D7  ╫ 
216 D8  ╪ │217 D9  ┘      218 DA  ┌ │219 DB  █ 
220 DC  ▄ │221 DD  ▌      222 DE  ▐ │223 DF  ▀ 
224 E0  α │225 E1  ß      226 E2  Γ │227 E3  π 
228 E4  Σ │229 E5  σ      230 E6  µ │231 E7  τ 
232 E8  Φ │233 E9  Θ      234 EA  Ω │235 EB  δ 
236 EC  ∞ │237 ED  φ      238 EE  ε │239 EF  ∩ 

DC  HX CH  DC  HX CH      DC  HX CH  DC  HX CH 
240 F0  ≡ │241 F1  ±      242 F2  ≥ │243 F3  ≤ 
244 F4  ⌠ │245 F5  ⌡      246 F6  ÷ │247 F7  ≈ 
248 F8  ° │249 F9  ∙      250 FA  · │251 FB  √ 
252 FC  ⁿ │253 FD  ²      254 FE  ■ │255 FF 




BYTE VALUE      KEY      BYTE VALUE      KEY 
--------------------------------------------- 
 59              F1   │  60               F2 
 61              F3   │  62               F4 
 63              F5   │  64               F6 
 65              F7   │  66               F8 
 67              F9   │  68               F10 
 84-93  SHIFT F1-F10  │  94-103   CTRL F1-F10 
104-113   ALT F1-F10  │  0                NUL 
15         SHIFT-TAB  │  71              HOME 
72          UP ARROW  │  73           PAGE UP 
75          LF ARROW  │  77          RT ARROW 
79               END  │  80          DN ARROW 
81           PAGE DN  │  82            INSERT 
83            DELETE  │  114       CTRL-PrtSc 
To add external assembly language subroutines to Turbo
Pascal, you should first identify your critical code 
segments. These are procedures and functions that are 
called most frequently. Optimizing these few routines 
will give your program the best results, and the 
needed speed you're after (in many cases.) After 
defining the critical code, you need to perform these 
steps: 

> Write a NEAR or FAR assembly language PROC 
> Declare the PROC PUBLIC, exporting the procedure 
  label to PASCAL 
> Use the {$L xxxx} PASCAL directive to load the OBJ 
  module 
> Declare the procedure EXTERNAL in PASCAL 


TASM provides a specific memory model for writing 
assembly routines for PASCAL, the TPASCAL model. 
Essentially, this model makes addressing variables on 
the stack a bit easier. Note you do not have to use 
the TPASCAL model, you may use a standard ASSUME xxx 
type format if you wish. Each method has it's 
advantages and disadvatages. 

On the following pages is a shell you can use as a 
template for writing ASSEMBLY subroutines for use with
Turbo Pascal, WITHOUT using the TPASCAL memory model. 
%TITLE "Shell for Pascal .OBJ modules" 

      IDEAL 

      SEGMENT DATA Word Public 

 ;--> Put any EXTRN data declarations here 

 ;--> Put STATIC variables here 

ENDS  DATA 

SEGMENT CODE Byte Public 

ASSUME  CS:CODE, DS:DATA 

 ;--> Put any public code calls here 

 ;--> Put any extrn code declarations here 

 ;----------------------------------- 
 ; PROCEDURE ProcedureName <Params> ; 
 ;----------------------------------- 

PROC   ProcedureName   NEAR 

       . . . . .code here 

       RET 

ENDP   ProcedureName 
 ;---------------------------------------- 
 ; FUNCTION FunctionName <Params> <Type> ; 
 ;---------------------------------------- 

PROC   FunctionName    NEAR 

       . . . . .code here 

       RET 

ENDP   FunctionName 

ENDS   CODE 

       END 


Although Turbo C creates tight, fast code, there is 
still room for improvement is some areas. After 
identifying your critical code segments, you can refer
to the following general purpose shell when writing 
assembly routines for Turbo C. 
%TITLE "Shell for C .OBJ modules" 

       IDEAL 
       MODEM  Small 

DATASEG 

 ;---> Put PUBLIC DATA here 

 ;---> Put EXTRN DATA here 

 ;---> Put initialized vars here 

FARDATA 

 ;---> Insert far-data-segment variables here 

CODESEG 

 ;---> Insert PUBLIC Code calls here 

 ;---> Insert EXTRN Code calls here 


 ;----------------------------- 
 ; <type> FuncName <params> 
 ;----------------------------- 

PROC   FuncName    NEAR 

       PUSH   BP 
       MOV    BP, SP 
       SUB    SP, N   ; optional: reserve local space 
       PUSH   DI      ; optional: save var di 
       PUSH   SI      ; optional: save var si 

       . . . . .code here 

       POP    SI 
       POP    DI 
       MOV    SP, BP 
       POP    BP      ; restore bp ptr 
       RET            ; return to caller 

ENDP   FuncName 

       END            ; end of module 


      │<------ 16 bits ------>│    │ 8086 REGISTERS │ 
      │< 8 bits  >│< 8 bits  >│    └─══════════════─┘ 
      ┌───────────┬───────────┐ 
  AX: │───AH──────┼────AL─────│─ Accumulator 
  BX: │───BH──────┼────BL─────│─ Base 
  CX: │───CH──────┼────CL─────│─ Count 
  DX: │───DH──────┴────DL─────│─ Data 
      │──────────SP───────────│─ Stack Pointer 
      │──────────BP───────────│─ Base Pointer 
      │──────────SI───────────│─ Source Index 
      │──────────DI───────────│─ Dest. Index 
      │──────────CS───────────│─ Code Segment 
      │──────────DS───────────│─ Data Segment 
      │──────────SS───────────│─ Stack Segment 
      │──────────ES───────────│─ Extra Segment 
      └──────────IP───────────┘─ Instruction Ptr 
- DATA TRANSFER INSTRUCTIONS - 

Mnumonic               Description 
---------------------------------------------- 

MOV Dest, Source       Copy byte or word 
POP Dest               Pop data from stack 
PUSH Dest              Push data onto stack 
XCHG Dest, Source      Exchange bytes & words 
XLAT/XLTAB Table       Transfer from table 

- I/O INSTRUCTIONS - 

IN Accumulator, Port   Input (get) byte/word 
OUT Port, Accumulator  Output (put) byte/word 


- ADDRESS INSTRUCTIONS - 

LDS Dest, Source       Load pointer using DS 
LEA Dest, Source       Load effective address 
LES Dest, Source       Load pointer using ES 

- FLAG INSTRUCTIONS - 

LAHF                   Load AH from (?) flags 
POPF                   Pop flag reg. from stack 
PUSHF                  Push flag reg. onto stack 
SAHF                   Store AH into (?) flags 
- ADDITION - 

AAA                    ASCII Adjust for addition 
ADC Dest, Source       Add with carry 
ADD Dest, Source       Add bytes or words 
DAA                    Decimeal adjust for addition 
INC Dest               Increment 

- SUBTRACTION - 

AAS                    ASCII adjust for subtraction 
CMP Dest, Source       Compare 
DAS                    Decimal adjust for subtraction 
DEC Dest               Decrement byte or word 
NEG Dest               Negate (two's complement) 
SBB Dest, Source       Subtract with borrow 

- SUBTRACTION - (continued) 

SUB Dest, Source       Subtract 

- MULTIPLICATION/DIVISION - 

AAM                    ASCII adjust for multiply 
IMUL Source            Integer multiply 
MUL  Source            Multiply 
AAD                    ASCII adjust for division 
CBW                    Convert byte to word 
CWD                    Convert word to double word 
DIV Source             Divide 
IDIV Source            Integer divide 


- LOGIC INSTRUCTIONS - 

AND Dest, Source       Logical AND 
NOT Dest               Logocal NOT (one's complement) 
OR  Dest, Source       Logical OR 
TEST Dest, Source      Test bits (no change) 
XOR Dest, Source       Logical Exclusive OR 

- SHIFT/ROTATE - 

RCL Dest, Count        Rotate Left through carry 
RCR Dest, Count        Rotate Right through carry 
ROL Dest, Count        Rotate Left 
ROR Dest, Count        Rotate Right 
SAR Dest, Count        Shift arithmetic Right 
SHR Dest, Count        Shift Right 

- SHIFT/ROTATE - (continued) 

SAL Dest, Count        Shift arithmetic Left 
SHL Dest, Count        Shift Left 

- UNCONDITIONAL FLOW TRANSFER - 

CALL Target            Call procedure 
JMP  Target            Jump to target 
RET  Value             Return from procedure 
RETN Value             Return from near procedure 
RETF Value             Return from far procedure 
- CONDITIONAL FLOW TRANSFER - 

JA/JNBE  Target      Jump if above/not below or equal 
JAE/JNB  Target      Jump if above or equal/not below 
JB/JNAE  Target      Jump if below/not above or equal 
JBE/JNA  Target      Jump if Below or equal/not above 
JC       Target      Jump if carry 
JE/JZ    Target      Jump if equal/0 
JG/JNLE  Target      Jump if greater/not less or equal
JGE/JNL  Target      Jump if greater or equal/not less
JL/JNGE  Target      Jump if less/not greater or equal
JLE/JNG  Target      Jump if less or equal/not greater
JNC      Target      Jump if no carry 
JNE/JNZ  Target      Jump if not equal/not 0 


- CONDITIONAL FLOW TRANSFER - (continued) 

JNO      Target      Jump if not overflow 
JNP/JPO  Target      Jump if NOT parity/parity odd 
JNS      Target      Jump if NOT sign 
JO       Target      Jump if overflow 
JP/JPE   Target      Jump if parity/parity even 
JS       Target      Jump if sign 

- LOOP INSTRUCTIONS -  

JCXZ  Target           Jump if CX = 0 
LOOP  Target           Loop while CX <> 0 
LOOPE/LOOPZ  Target    Loop while equal/0 
LOOPNE/LOOPNZ  Target  Loop while not equal/not 0 


- PROCESSOR CONTROL - 

CLC                    Clear carry 
CLD                    Clear direction (auto-inc) 
CLI                    Clear interrupt-enable flag 
CMC                    Complement carry 
STC                    Set carry 
STD                    Set direction (auto-dec) 
STI                    Set interrupt-enable flag 
NOP                    No operation 

- STRING INSTRUCTIONS - 

LODS   Source          Load string bytes or words 
LODSB  [shorthand]     Load string bytes 
- STRING INSTRUCTIONS - (continued) 

LODSW  [shorthand]     Load string words 
MOVS   Dest, Source    Move string bytes/words 
MOVSB  [shorthand]     Move string bytes 
MOVSW  [shorthand]     Move string words 
STOS   Dest            Store string bytes/words 
STOSB  [shorthand]     Store string bytes 
STOSW  [shorthand]     Store string words 
CMPS   Dest, Source    Compare string bytes/words 
CMPSB  [shorthand]     Compare string bytes 
CMPSW  [shorthand]     Compare string words 
SCAS   Dest            Scan string bytes/words 
- STRING INSTRUCTIONS - (contined) 

SCASB  [shorthand]     Scan string bytes 
SCASW  [shorthand]     Scan string words 
REP                    Repeat 
REPE/REPZ              Repeat while equal/0 
REPNE/REPNZ            Repeat while not equal/not 0 





** See next page for shorthand vs longhand 
equivalents. 


The following chart shows the shorthand string 
instructions and their longhand counterparts. 

 SHORTHAND      EQUIVALENT LONGHAND                   
--------------------------------------------------------
LODSB          LODS [BYTE PTR DS:SI] 
LODSW          LODS [WORD PTR DS:SI] 
STOSB          STOS [BYTE PTR ES:DI] 
STOSW          STOS [WORD PTR ES:DI] 
MOVSB          MOVS [BYTE PTR ES:DI], [BYTE PTR DS:SI]
MOVSW          MOVS [WORD PTR ES:DI], [WORD PTR DS:SI]
SCASB          SCAS [BYTE PTR ES:DI] 
SCASW          SCAS [WORD PTR ES:DI] 
CMPSB          CMPS [BYTE PTR DS:SI], [BYTE PTR ES:DI]
CMPSW          CMPS [WORD PTR DS:SI], [WORD PTR ES:DI]



TINY    : 64k Code and Data. Code and Data NEAR. 

SMALL   : 64k Code, 64k Data. Code and Data NEAR. 

MEDIUM  : Code > 64K, Data 64k. Code FAR, Data NEAR. 

COMPACT : Code 64k, Data > 64k. Code NEAR, Data FAR. 

LARGE   : Code and Data > 64k. Code and Data FAR. 
          No single Data Array > 64k. 

HUGE    : Code and Data > 64k. Code and Data FAR. 
          Single Data Array can be > 64k 


Syntax: 
 TASM [/Switches] SourceFile [,object] [,list] [,xref]

 Parameter             Description  
-------------------------------------------------------
/a,/s        Alphabetic or Source-code segment 
              ordering 
/c           Generate cross-reference in listing 
/dSYM[=VAL]  Define symbol SYM = 0, or = value VAL 
/e,/r        Emulated/Real floating-point instructions
/h,/?        Display this help screen 
/iPATH       Search PATH for include files 
/jCMD        Jam in assembler directive CMD (/jIDEAL) 
/kh#,/ks#    Hash table capacity, String space 
              capacity 
/l,/la       Generate listing: l=normal, la=expanded 
 Parameter             Description  
-------------------------------------------------------
/ml,/mx,/mu  Case sensitivity on symbols: ml=all, 
              mx=globals, mu=none 
/n           Suppress symbol tables in listing 
/p           Check for code segment overrides in 
              protected mode 
/t           Suppress messages if successful assembly 
/w0,/w1,/w2  Set warning level: w0=none, w1=w2=on 
/w-x,/w+x    Disable (-) or enable (+) warning x 
/x           Include false conditionals in listing 
/z           Display source line with error message 
/zi,/zd      Debug info: zi=full, zd=line numbers only


Syntax: TLINK OBJfiles, EXEfile, MAPfile, LIBfiles 

         /m = map file with publics 
         /x = no map file at all 
         /i = initialize all segments 
         /l = include source line numbers 
         /s = detailed map of segments 
         /n = no default libraries 
         /d = warn if duplicate symbols in libraries 
         /c = lower case significant in symbols 
         /3 = enable 32-bit processing 
         /v = include full symbolic debug information 
         /e = ignore Extended Dictionary 
         /t = create COM file 

