Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8 Advanced Programming Applications Objectives: Linking separate object files together Creating and using an object code library Predicting the.

Similar presentations


Presentation on theme: "Chapter 8 Advanced Programming Applications Objectives: Linking separate object files together Creating and using an object code library Predicting the."— Presentation transcript:

1 Chapter 8 Advanced Programming Applications 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 EE314 Microprocessor Systems Based on "An Introduction to the Intel Family of Microprocessors" by James L. Antonakos

2 8.2 Using EXTRN and PUBLIC Assembler Directives ;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 ;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 DISPBIN.OBJ TESTBIN.OBJ LINK TESTBIN+DISPBIN,,; LINK /? or LINK /help LINK,,,, TESTBIN.EXE

3 Building and Using an Object Code Library DISPBIN.ASM DISPHEX.ASM DISPBCD.ASM DISPINT.ASM 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.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) LINK TESTBIN,,,NUMOUT ;Program TESTBIN.ASM: Test the...... EXTRN DISPBIN:FAR ;for linking... CALL DISPBIN ; binary display...

4 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. SEND_MSG MACRO ADR LEA DX, ADR ;;setup pointer to string MOV AH,9;;display string function INT 21H;;DOS call ENDM in program, the macro “called”: SEND_MSG ABC will be replaced with: LEA DX, ABC MOV AH,9 INT 21H avoids repeating the comments every time the macro is expanded

5 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 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. 8.3 Using MACROS Every time the macro is expanded, a new name for the label is defined. The conditional statement IF - ELSE - ENDIF allows conditional macro expanding. SHIFT MACRO SIZE IF SIZE EQ 8 SHR AL,1 ELSE SHR AX,1 ENDIF ENDM the operators allowed by IF statement are: EQEqual NENot equal LTLess than GTGreater than LELess than or equal GEGreater than or equal 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, S_MAKE 2,


Download ppt "Chapter 8 Advanced Programming Applications Objectives: Linking separate object files together Creating and using an object code library Predicting the."

Similar presentations


Ads by Google