CS - code segment DS - data segment ES - extended segment SS - stack segment IP - instruction pointer (associated w/ CS) SP - stack pointer (associated w/ SS) BP - base pointer (also associated w/ SS) AX [AH,AL] - 'accumulator' - I/O, arithmetic BX [BH,BL] - 'base register' - addressing, computation CX [CH,CL] - 'count register' - loops, computation DX [DH,DL] - 'data register' - I/O, multiply, divide SI - source index (associated w/ DS) DI - destination index (associates w/ ES) ************************************************************************ Skeleton .COM file: compile using: ML /AT page 60,80 TITLE SKELETON A skeleton .COM file ;----------------------------------------------------------------------- CODESG SEGMENT PARA 'Code' ASSUME CS:CODESG,DS:CODESG ORG 100H BEGIN: JMP MAIN ;----------------------------------------------------------------------- ;data declarations here ;----------------------------------------------------------------------- MAIN PROC NEAR MOV AX,CS ;point to correct data segment MOV DS,AX ;put code here MOV AX,4C00H ;funciton 4Ch minor code 0 INT 21H ; terminate normally MAIN ENDP CODESG ENDS END BEGIN ************************************************************************ Skeleton .EXE file: Compile using: ML page 60,80 TITLE SKELETON A skeleton .EXE file ;----------------------------------------------------------------------- STACKSG SEGMENT PARA STACK 'Stack' DW 32 DUP(0) STACKSG ENDS ;----------------------------------------------------------------------- DATASG SEGMENT PARA 'Data' ;put data here DATASG ENDS ;----------------------------------------------------------------------- CODESG SEGMENT PARA 'Code' MAIN PROC FAR ASSUME SS:STACKSG,DS:DATASG,CS:CODESG ;tell compiler the segment locations MOV AX,DATASG ;tell processor the MOV DS,AX ; data segment location ;put code here MOV AX,4C00H ;funciton 4Ch minor code 0 INT 21H ; terminate normally MAIN ENDP CODESG ENDS END MAIN ************************************************************************ ********************************* * Unconditional Jumps (p116-7): * ********************************* ;jump forward JMP label ;no colon here . . . label: ;don't forget the colon here ;jump backward label: ;don't forget the colon here . . . JMP label ;no colon here ***************** * Loops (p118): * ***************** label: ;don't forget the colon here . . . LOOP label ;no colon here ******************************* * Compares (p120)/ * * Conditional Jumps (p121-3): * ******************************* CMP register/memory , register/memory/immetiate compares the first operand to the second i.e. CMP DX,27 ;is DX<27,DX=27,or DX>27 ? CMP COUNT,AX ;is COUNT <, =, or > AX -Jumps based on unsigned data *** WARNING: All conditional jumps must be preceded by a compare or test!!! JE/JZ Jump if Equal -or- Jump if Zero JNE/JNZ Jump if Not Equal -or- Jump if Not Zero JA/JNBE Jump if Above -or- Jump if Not Below or Equal JAE/JNB Jump if Above or Equal -or- Jump if Not Below JB/JNAE Jump if Below -or- Jump if Not Above or Equal JBE/JNA Jump if Below or Equal -or- Jump if Not Above -Jumps based on signed data *** WARNING: All conditional jumps must be preceded by a compare or test!!! JE/JZ Jump if Equal -or- Jump if Zero JNE/JNZ Jump if Not Equal -or- Jump if Not Zero JG/JNLE Jump if Greater than -or- Jump if Not Less than or Equal to JGE/JNL Jump if Greater than or Equal to -or- Jump if Not Less than JL/JNGE Jump if Less than -or- Jump if Not Greater than or Equal to JLE/JNG Jump if Less than or Equal to -or- Jump if Not Greater than ******************************** * Calling Procedures (p123-7): * ******************************** a procedure (function, module, subroutine, or whatever you want to call it) is set up like this proc-name PROC FAR ;or PROC NEAR . . . RET proc-name ENDP CALL proc-name ;transfers execution to the procedure RET ;placed just before the end of a procedure ; returns control ; to the instruction following the CALL ******************************** * Boolean Operations (p127-8): * ******************************** operation register/memory , register/memory/immediate performs the boolean operation on each bit i.e. AND AX,DX ;stores logical AX and DX into AX XOR CHAR,30H ;stores logical CHAR xor 30H into CHAR AND | 0 1 --+---- 0 | 0 0 1 | 0 1 OR | 0 1 --+---- 0 | 0 1 1 | 1 1 XOR | 0 1 --+---- 0 | 0 1 1 | 1 0 NOT register/memory inverts each bit (binary 1's to 0's and 0's to 1's) ******************************* * Clearing the Screen (p141): * * Scroll up screen (p163): * ******************************* AH - function 06H AL - number of lines to scroll, or 00H for full screen BH - attribute value (color, reverse video, blinking) CX - starting row:column DX - ending row:column ex. MOV AX,0600H ;AH=06 (scroll), AL=00 (full screen) MOV BH,71H ;white background (7), blue foreground (1) MOV CX,0000H ;upper left row:column MOV DX,184FH ;lower right row:column INT 10H ;Call interrupt service **************************** * Display a string (p142): * **************************** AH - function 09H DX - address of string (NOTE: String must end with a '$') ex. MSG DB 'Put message here','$' . . . MOV AH,09H ;AH=09 (display a strong) LEA DX,MSG ;Load Effective Address of the message into DX INT 21H ;Call interrupt service ************************************************* * Display a single character w/o repeat (p150): * ************************************************* AH - function 02H DL - character to display ex. MOV AH,02H ;request display character MOV DL,char ;character to display INT 21H ;call interrupt service ********************* * Attributes/ * * Colors (p159-60): * ********************* Background | Foreground Attribute BL | R G B | I R G B Bit Number 7 | 6 5 4 | 3 2 1 0 bit 7 - blinking bit 6-4 - background color bit 3 - intensity bit 2-0 - foreground color COLOR I R G B | COLOR I R G B black 0 0 0 0 | grey 1 0 0 0 blue 0 0 0 1 | lite blue 1 0 0 1 green 0 0 1 0 | lite green 1 0 1 0 cyan 0 0 1 1 | lite cyan 1 0 1 1 red 0 1 0 0 | lite red 1 1 0 0 magenta 0 1 0 1 | lite magenta 1 1 0 1 brown 0 1 1 0 | yellow 1 1 1 0 white 0 1 1 1 | brite white 1 1 1 1 ******************************* * Set cursor position (p162): * ******************************* AH - function 02H BH - page # - 0(use for default),1,2,or3 DH - row DL - column ex. MOV AH,02H ;set sursor MOV BH,00 ;page 0 MOV DH,12 ;row 12 MOV DL,30 ;column 30 INT 10H ;Call interrupt service ******************************************* * Display character w/ attributes (p165): * ******************************************* AH - function 09H AL - ASCII character to be displayed BH - page number (use 0 for default) BL - Attribute CX - number of characters to print ex. MOV AH,09H ;request display MOV AL,01H ;happy face MOV BH,0 ;page 0 MOV BL,16H ;blue background, brown foreground MOV CX,60 ;60 smileys INT 10H ;Call interrupt service **************************************** * Display character w/ repeats (p166): * **************************************** AH - function 0AH AL - ASCII character to be displayed BH - page number (use 0 for default) CX - number of characters to print ex. MOV AH,0AH ;request display MOV AL,03H ;heart MOV BH,0 ;page 0 MOV CX,20 ;20 hearts INT 10H ;Call interrupt service ************************* * Increment * * Decrement (p101) * * Addition * * Subtraction (p222-4): * ************************* INC/DEC register/memory increase or decrease the operand by one ADD/SUB register/memory , register/memory/immediate adds second operand to (or subtracts second operand from) the first operand and replaces the first operand with the result i.e. INC CH ;adds 1 to CH DEC DX ;subtracts 1 from DX ADD AX,07H ;calculates AX + 07H and puts the answer in AX SUB MAX,14 ;calculates MAX - 14 and puts the answer in MAX ****************************** * Multiplication (see p227): * ****************************** MUL register/memory/immediate unsigned multiplication IMUL register/memory/immediate signed multiplication Instruction Muiltiplier Multiplicand Product MUL CL Byte AL AX MUL BX Word AX DX:AX MUL EBX Double Word EAX EDX:EAX ************************ * Division (see p235): * ************************