1
CS344-321 Assembly Language Programming Appendix page
______
Appendix A
Assembler and Linker
This course you can use any of the following software:
MicroSoft version 3.0
ASSEMBLER : MASM.EXE
LINKER : LINK.EXE
LIBRARY MANAGEMENT : LIB.EXE
UTILITY : EXE2BIN.COM
Borland version 4.1
ASSEMBLER : TASM.EXE
LINKER : TLINK.EXE
Public Domain (Arrow Soft) arrowsof.zip
ASSEMBLER : ASM.EXE
LINKER : VAL.EXE
UTILITY : X2B.COM
Assembling A Program
Method 1: assembling without a command line, just enter the assembler name:
MASM ASM
Source filename [.ASM]:Input filename [.asm]:
Object filename [filename.OBJ]:Object filename [filename.obj]:
Source listing [NUL.LST]:Source listing [NUL.lst]:
Cross reference [NUL.CRF]:Cross reference [NUL.crf]:
Press Enter if you don’t want to output cross reference file, otherwise enter
[drive:]name [.extension]
Press Enter if you don’t want to output listing file, otherwise enter
[drive:]name [.extension]
Press Enter if you want object file name as shown, otherwise enter
[drive:]name [.extension]
Enter only name of source or input filename if the extension is .asm, otherwise enter
[drive:] name [.extension]
Method 2: assembling with a command line:
The general format for using a command line to assemble is
masm/tasm/asm [options] source [, [object] ][, [listing] ][, [crossref] ] [;]
There are many options (see manual for more information), we will discuss some of them:
/MX Make public and external names case sensitive.
/ML Make all names case sensitive.
/MU Convert all names to uppercase.
Assume source file name is test.asm.
Example 1.
masm test,test,test,test or masm test, , , ; or masm test,,,,
will produce test.obj, test.lst, test.crf.
Example 2.
masm test,test,test; or masm test, ,test;
will produce test.obj, test.lst.
Example 3.
masm test;
will produce only test.obj.
Example 4.
masm /MX test;
Linking a Program
Method 1: liking without a command line, just enter the linker name:
LINK VAL
Object Modules [.OBJ]:OBJ file(s):
RUN File [filename.EXE]: EXE file [filename.exe]:
List File [NUL.MAP]:LST file:
Libraries [.LIB]: LIB files:
Note! If there are more than one object modules use + e.g. test1.obj+test2.obj. It is the same for libraries.
Method 2: linking with a command line:
The general format for using a command line to link is
link/tlink/val [options] objfile, exefile [, [mapfile] ][, [libraryfile] ] [;]
There are many options (see manual for more information).
Example 1. no library
link test,test,test; or link test, , ;
will produce test.exe, test.map
Example 2. There are two object files, test1.obj, test2.obj and no library.
link test1+test2,test;
will produce test.exe.
Example 3. There are two object files, test1.obj, test2.obj and one library, mylib.lib.
link test1+test2,test,,mylib
will produce test.exe, test.map.
Example 4. There are two object files, test1.obj, test2.obj and two libraries, mylib1.lib, mylib2.lib.
link test1+test2,test,,mylib1+mylib2
will produce test.exe, test.map.
Convert .EXE to .COM
exe2bin/x2b test.exe test.com
or
use option /t of tlink at linking time, e.g. tlink /t test;
Make a library
Example 1. To create a new library name mylib and insert test.obj,
lib
Library name: mylib
Library does not exist. Create? y
operations: test
List file:
Example 2. To insert test1.obj and delete test.obj in mylib.lib and make as a new library nmylib.lib.
lib
Library name: mylib
operations: test1-test
List file:
Output Library: nmylib
Note! you may use +objfile to add and –objfile to delete
Appendix B
Reserve Words
Register Names
AH CH DL EDI GS
AL CL DS EDX IP
AX CS DX EIP SI
BH CX EAX ES SP
BL DH EBP ES SS
BP DI EBX ESI
BX DI ECX FS
Symbolic Instructions
AAA ARPL CDQ CMPSn ESC
AAD BOUND CLC CWDn HLT
AAM BSF CLD DAA IDIV
AAS BSR CLI DAS IMUL
ADC BTn CLTS DEC IN
ADD CALL CMC DIV INC
AND CBW CMP ENTER INSw
INT JNLE LOCK POPAD SCASn
INTO JNO LODSn POPF SETnn
IRET JNP LOOP POPFD SGDT
JA JNS LOOPE PUSH SHL
JAE JNZ LOOPNE PUSHAD SHLD
JB JO LOOPNZ PUSHF SHR
JBE JP LOOPZ PUSHFD SHRD
JCXZ JPE LSL RCL SIDT
JE JPO LSS RCR SLDT
JECXZ JS LSS REN SMSW
JG JZ LTR REP STC
JGE LAHF MOV REPE STD
JL LAR MOVSn REPNE STI
JLE LDS MOVSX REPNZ STOSn
JMP LEA MOVZX REPZ STR
JNA LEAVE MUL RET SUB
JNAE LES NEG RETF TEST
JNB LFS NOP ROL VERR
JNBE LGDT NOT ROR VERRW
JNE LGS OR SAHF WAIT
JNG LIDT OUTn SAL XCHG
JNGE LLDT POP SAR XLAT
JNL LMSW POPA SBB XOR
Directives
ALIGN ENDIF IFIDN PUBLIC
.ALPHA ENDM IFNB PURGE
ASSUME ENDP IFNDEF .RADIX
.CODE ENDS INCLUDE RECORD
COMM EQU INCLUDELIB REPT
COMMENT .ERRnn IRP .SALL
.CONST EVEN IRPC SEGMENT
.CREF EXITM LABEL .SEQ
.DATA EXTRN .LALL .SFCOND
.DATA? .FARDATA .LFCOND .STACK
DB .FARDATA? .LIST STRUC
DD GROUP LOCAL SUBTTL
DF IF MACRO .TFCOND
DOSSEG IFI .MODEL TITLE
DQ IF2 NAME .XALL
DT IFB ORG .XCREF
DW IFDEF OUT .XLIST
ELSE IFDIF PAGE
END IFE PROC
Operators
AND HIGH NEAR SHR
BYTE LE NOT SIZE
COMMENT LENGTH NOTHING STACK
CON LINE OFFSET THIS
DUP LOW OR TYPE
EQ LT PTR WIDTH
FAR MASK SEG WORD
GE MOD SHL XOR
GT NE SHORT
Appendix C
8086/8088 Mnemonic
______
mnemonicชื่อเต็มmnemonicชื่อเต็ม
______
AAAASCII adjust for additionJNAEJump on not above or equal
AADASCII adjust for divisionJNBJump on not below
AAMASCII adjust for multiplicationJNBEJump on not below or equal
AASASCII adjust for subtractionJNCJump on not carry
ADCAdd with carryJNEJump on not equal
ADDAddJNGJump on not greater
ANDANDJNGEJump on not greater or equal
CALLCALLJNLJump on not less than
CBWConvert byte to wordJNLEJump on not less than or equal
CLCClear carry flagJNOJump on not overflow
CLDClear direction flagJNPJump on not parity
CLIClear interrupt flagJNSJon not sign
CMCComplement carry flagJNZJump on not zero
CMPCompareJOJump on overflow
CMPSCompare byte or word (of string)JPJump on parity
CMPSBCompare byte stringJPEJump on parity even
CMPSWCompare word stringJPOJump on parity odd
CWDConvert word to double wordJSJump on sign
DAADecimal adjust for additionJZJump on zero
DASDecimal adjust for subtractionLAHFLoad AH with flags
DECDecrementLDSLoad pointer into DS
DIVDivideLEALoad effective address
ESCEscapeLESLoad pointer into ES
HLTHaltLOCKLOCK bus
IDIVInteger divideLODSLoad byte or word (of string)
IMULInteger multiplyLODSBLoad byte (string)
INInput byte or wordLOADSW Load word (string)
INCIncrementLOOPLOOP
INTInterruptLOOPELOOP while equal
INTOInterrupt on overflowLOOPNELOOP while not equal
IRETInterrupt returnLOOPNZLOOP while not zero
JAJump on aboveLOOPZLOOP while zero
______
mnemonicชื่อเต็มmnemonicชื่อเต็ม
______JBE JAE Jump on above or equal MOV Move
JBJump on belowMOVSMove byte or word (of string)
JBEJump on below or equalMOVSBMove byte (string)
JCJump on carryMOVSWMove word (string)
JCXCJump on CX zeroMULMultiply
JEJump on equalNEGNegate
JGJump on greaterNOPNo operation
JGEJump on greater or equalNOTNOT
JLJump on less thanOROR
JLEJump on less than or equalOUTOutput byte or word
JMPJumpPOPPOP
JNAJump on not abovePOPFPOP flags
PUSHPUSHSHLShift left
PUSHFPUSH flagsSHRShift right
RCLRotate through carry leftSTCSet carry flag
RCRRotate through rightSTDSet direction flag
REPRepeatSTISet interrupt flag
RETReturnSTOSStore byte or word (of string)
ROLRotate leftSTOSBStore Byte (string)
RORRotate rightSTOSWStore word (string)
SAHFStore AH into flagsSUBSubtract
SALShift arithmetic leftTESTTEST
SARShift arithmetic rightWAITWAIT
ABBSubtract with borrowXCHGExchange
SCASScan byte or word (of string)XLATTranslate
SCASBScan byte (string)XORExclusive OR
SCASWScan word (string)
Appendix D
ASCII Code
7 0 0 0 0 1 1 1 1
Bit 6 0 0 1 1 0 0 1 1
positions 5 0 1 0 1 0 1 0 1
4 3 2 1
0 0 0 0 NUL DLE SP 0 @ P \ p
0 0 0 1 SOH DC1 ! 1 A Q a q
0 0 1 0 STX DC2 “ 2 B R b R
0 0 1 1 ETX DC3 # 3 C S c s
0 1 0 0 EOT DC4 $ 4 D T d t
0 1 0 1 ENQ NAK % 5 E U e u
0 1 1 0 ACK SYN & 6 F V f v
0 1 1 1 BEL ETB ‘ 7 G W g w
1 0 0 0 BS CAN ( 8 H X h x
1 0 0 1 HT EM ) 9 I Y i y
1 0 1 0 LF SUB * : J Z j z
1 0 1 1 VT ESC + ; K [ k {
1 1 0 0 FF FS , < L \ l |
1 1 0 1 CR GS - = M ] m }
1 1 1 0 SO RS . > N ^ n ~
1 1 1 1 SI US / ? O _ o DEL
ตารางข้างบนแทนอักขระรหัสตั้งแต่00000000 ถึง01111111 ถ้าต้องการใช้ทั้ง8 บิตรหัสตั้งแต่10000000 ถึง11111111 จะแทนอักขระพิเศษเช่นใช้แทนอักขระภาษาไทยเป็นต้น
อักขระที่เป็นprintable character ได้แก่อักขระตั้งแต่SP (00100000) ถึง~ (0111110) นอกนั้นจะเป็นอักขระที่ใช้ควบคุมเช่นCR ใช้แทนการสิ้นสุดบรรทัดของระบบปฏิบัติการUnix หรือCR กับLFแทนการสิ้นสุดบรรทัดของระบบปฏิบัติการDOS เป็นต้น
ASCII Code
เลขฐานสิบหกตัวหน้า
0 1 2 3 4 5 6 7
0 NUL DLE SP 0 @ P \ p
เลขฐาน 1 SOH DC1 ! 1 A Q a q
สิบหก 2 STX DC2 “ 2 B R b R
ตัวหลัง 3 ETX DC3 # 3 C S c s
4 EOT DC4 $ 4 D T d t
5 ENQ NAK % 5 E U e u
6 ACK SYN & 6 F V f v
7 BEL ETB ‘ 7 G W g w
8 BS CAN ( 8 H X h x
9 HT EM ) 9 I Y i y
A LF SUB * : J Z j z
B VT ESC + ; K [ k {
C FF FS , < L \ l |
D CR GS - = M ] m }
E SO RS . > N ^ n ~
F SI US / ? O _ o DEL
เช่น อักขระ0 แทนด้วยรหัสASCII เลขฐานสิบหก30
อักขระ1 แทนด้วยรหัสASCII เลขฐานสิบหก31
อักขระA แทนด้วยรหัสASCII เลขฐานสิบหก41
อักขระa แทนด้วยรหัสASCII เลขฐานสิบหก61
อักขระSP หรือblank แทนด้วยรหัสASCII เลขฐานสิบหก02
อักขระCR แทนด้วยรหัสASCII เลขฐานสิบหก0D
อักขระLF แทนด้วยรหัสASCII เลขฐานสิบหก0A
อักขระBEL หรือbeep แทนด้วยรหัสASCII เลขฐานสิบหก07
เป็นต้น
Computer Science, Prince of Songkhla University