50 likes | 169 Views
EE314 Microprocessor Systems. Chapter 8. Objectives: Linking separate object files together Creating and using an object code library Predicting the execution time for a block of code How interrupt are supported and used by DOS How two programs can execute “simultaneously”
E N D
EE314Microprocessor Systems Chapter 8 Objectives: Linking separate object files together Creating and using an object code library Predicting the execution time for a block of code How interrupt are supported and used by DOS How two programs can execute “simultaneously” How memory is managed by DOS Using information from the PC’s mouse Writing a memory-resident program Beating your computer at tic-tac-toe Testing for protected-mode operation How assembly language interfaces with C Advanced Programming Applications Based on "An Introduction to the Intel Family of Microprocessors" by James L. Antonakos
8.2 Using EXTRN and PUBLIC Assembler Directives ;Program TESTBIN.ASM: Test the ;DISPBIN display procedure. .MODEL SMALL .CODE EXTRN DISPBIN:FAR ;for linking .STARTUP SUB AL,AL ;clear counter AGAIN: PUSH AX ;save counter CALL DISPBIN ; binary display MOV DL,20H ;load blank character MOV AH,2 ;display character INT 21H ;DOS call MOV AH,2 ;output a second blank INT 21H POP AX ;get counter back INC AL ;increment it JNZ AGAIN ;and repeat until ;counter equals zero .EXIT END ;Procedure DISPBIN.ASM: Display value ;of AL in binary on the screen. .MODEL SMALL .CODE PUBLIC DISPBIN;for linking DISPBIN PROC FAR MOV CX,8 ;set up loop counter NEXT: SHL AL,1 ;move bit into CF PUSH AX ;save number JC ITIS1 ;was the MSB a 1? MOV DL,30H ;load '0' character JMP SAY01 ;go display it ITIS1: MOV DL,31H ;load '1' character SAY01: MOV AH,2 ;display character INT 21H ;DOS call POP AX ;get number back LOOP NEXT ;and repeat RET DISPBIN ENDP END DISPBIN.OBJ TESTBIN.OBJ LINK /? or LINK /help LINK <objs>,<exefile>,<mapfile>,<libs>,<deffile> LINK TESTBIN+DISPBIN,,; TESTBIN.EXE
Building and Using an Object Code Library Display AL in binary on screen: Display AL in hex on screen: Display AL in BCD on screen: Display AL in as unsigned integer: DISPBIN.ASM DISPHEX.ASM DISPBCD.ASM DISPINT.ASM DISPBIN.OBJ DISPHEX. OBJ DISPBCD. OBJ DISPINT. OBJ NUMOUT.LIB ML /? ML [/options] filelist [/link linkoptions] ML /c /Fl DISPBIN.ASM DISPHEX.ASM DISPBCD.ASM DISPINT.ASM LIB /? LIB library [options] [commands] [,listfile [,newlibrary]] LIB NUMOUT.LIB +DISPBIN +DISPHEX +DISPBCD +DISPINT Other possible commands: -name = delete .obj file from library -+name = replace .obj file in library (an .obj file with the same name must exist) *name = extract .obj file (create an independent name.obj file) -*name = extract and delete from library .obj file (create an independent name.obj file) ;Program TESTBIN.ASM: Test the ... ... EXTRN DISPBIN:FAR ;for linking ... CALL DISPBIN ; binary display ... LINK TESTBIN,,,NUMOUT
8.3 Using MACROS A MACRO is a text placed between the definition line and the end line. DISP_MSG MACRO MOV AH,9 ;display string function INT 21 ;DOS call ENDM In the following text, the macro NAME is replaced every time it occurs with the macro’s BODY. EXPANDING a macro Even if the body of a macro contents (typically) a group of instructions, it is NOT a subroutine, the expression “calling a macro” is not similar to “calling a subroutine”. To be more flexible, macros allow PARAMETERS’ transfer. The FORMAL parameters follow the macro’s name in the definition line. When the macro is used, the formal parameters are replaced trough the macro’s body with the ACTUAL parameters, specified in the line “calling” the macro, following it’s name. in program, the macro “called”: SEND_MSG ABC will be replaced with: LEA DX, ABC MOV AH,9 INT 21H SEND_MSG MACRO ADR LEA DX, ADR ;;setup pointer to string MOV AH,9 ;;display string function INT 21H ;;DOS call ENDM avoids repeating the comments every time the macro is expanded
8.3 Using MACROS A LABEL used in the macro definition is not allowed to repeat in the program each time the macro is expanded. To avoid this, the label is declared LOCAL. HEXOUT MACRO LOCAL NOADD CMP AL,10 JC NOADD ADD AL,7 NOADD: ADD AL,30h MOV DL,AL MOV AH,2 INT 21H ENDM Every time the macro is expanded, a new name for the label is defined. The conditional statement IF - ELSE - ENDIF allows conditional macro expanding. the operators allowed by IF statement are: EQ Equal NE Not equal LT Less than GT Greater than LE Less than or equal GE Greater than or equal SHIFT MACRO SIZE IF SIZE EQ 8 SHR AL,1 ELSE SHR AX,1 ENDIF ENDM Macro Operators: % the following arithmetical expression will be replaced by it’s value <...> enclose a literal character string ;; macro comment & substitute - allows parameter as part of a word (without a “separator”) S_MAKE MACRO NUM, TEXT STR&NUM DB ‘&TXT’,0DH,0AH,‘$’ ENDM S_MAKE 1, <This is a message> S_MAKE 2, <This is another message>