Programming the Microprocessor A Course in Microprocessor Electrical

  • Slides: 31
Download presentation
Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia

Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia

Ö To develop programs and programming techniques using : · the MASM macro assembler

Ö To develop programs and programming techniques using : · the MASM macro assembler program, · the DOS function calls, · and the BIOS function Calls (see Appendix A)

Some programming techniques : 4 Macro sequences 4 keyboard and display manipulation 4 program

Some programming techniques : 4 Macro sequences 4 keyboard and display manipulation 4 program modules 4 library files 4 using the mouse 4 interrupt hooks

Modular Programming – The assembler and Linker • The assembler program converts a symbolic

Modular Programming – The assembler and Linker • The assembler program converts a symbolic source module (file) into a hexadecimal object file • Example 7 -1 shows how the assembler dialog that appears as a source module named NEW. ASM is assembled • Source file are created using Work. Bench, an editor that comes with the assembler, or by almost any other word processor or editor capable of generating an ASCII file

Modular Programming(cont’d) – The linker program • which executes as the second part of

Modular Programming(cont’d) – The linker program • which executes as the second part of ML, reads the object files, created by the assembler program, and links them into a single execution file (. EXE) • Example 7 -2 shows the protocol involved with the linker program when it is used to link the files NEW, WHAT, and DONUT – PUBLIC and EXTRN • PUBLIC is used to declare that labels of code, data, or entire segments are available to other program modules ( see Example 7 -3 )

Modular Programming(cont’d) • EXTRN (external) is used to declare that labels are external to

Modular Programming(cont’d) • EXTRN (external) is used to declare that labels are external to a module (see Example 7 -4) – Libraries • they are collections of procedures that can be used by many different programs • The procedures are assembled and compiled into a library file by the LIB program that accompanies the MASM assembler program • Creating a Library File – is created with the LIB command typed at the DOS prompt

Modular Programming(cont’d) – is a collection of assembled. OBJ files that each perform one

Modular Programming(cont’d) – is a collection of assembled. OBJ files that each perform one procedure or task (see Example 7 -5) – After each file is assembled, the LIB program is used to combine them into a library file (see Example 7 -6) – Macros • it is a group of instructions that perform one task, just as a procedure performs one task • the difference is that a procedure is accessed via a CALL instruction, while a macro is inserted in the program at the point of usage as a new sequence of instructions

Modular Programming(cont’d) • the MACRO and ENDM directives are used to delineate a macro

Modular Programming(cont’d) • the MACRO and ENDM directives are used to delineate a macro sequence • Example 7 -8 shows how a macro is created and used in a program • Local Variables in a Macro – A local variable is one that appears in the macro, but is not available outside the macro – To define a local variable, use the LOCAL directive – See Example 7 -9

Modular Programming(cont’d) • Conditional Statement in Macro Sequences – create instructions that control the

Modular Programming(cont’d) • Conditional Statement in Macro Sequences – create instructions that control the flow of the program – they are variations of IF-THEN, IF-THENELSE, DO-WHILE, FOR and REPEATUNTIL statement – See Table 7 -1, Table 7 -2, Example 7 -10, 7 -11, 712, 7 -13, 7 -14

Using The Keyboard and Video Display 4 Reading the Keyboard with DOS Functions –

Using The Keyboard and Video Display 4 Reading the Keyboard with DOS Functions – the keyboard of PC is read via a DOS function call – There are three ways to read the keyboard : • reads a key and echoes (or displays) the key on the video screen • simply tests to see if a key is pressed-if it is, the function reads the key; otherwise, it returns without any key • allows an entire character line to be read from the keyboard

Using The Keyboard and Video Display (cont’d) – Reading a Key with an Echo

Using The Keyboard and Video Display (cont’d) – Reading a Key with an Echo • Example 7 -15 shows how a key is read from the keyboard and echoed (sent) back out to the video display using a prosedure called KEY – Reading a Key without an Echo • Example 7 -16 shows a procedure that uses function number 06 H to read the keyboard – Read an Entire Line with an Echo • Use one function call (number 0 AH). This function reads an entire line of information-up to 255 characters-from the keyboard (see Example 7 -17 )

Using The Keyboard and Video Display (cont’d) 4 Writing to the Video Display with

Using The Keyboard and Video Display (cont’d) 4 Writing to the Video Display with DOS Functions – Use functions 02 H or 06 H for displaying one character at a time or function 09 H for displaying an entire string of characters (see Example 7 -18 and 7 -19 4 Using BIOS Video Function Calls at INT 10 H (see Table 7 -4 and Example 7 -20)

Using The Keyboard and Video Display (cont’d) 4 Display Macro – a register can

Using The Keyboard and Video Display (cont’d) 4 Display Macro – a register can be specified as the argument, an ASCII character in quotes, or the numeric value for an ASCII character (see Example 7 -22) 4 The Mouse – The mouse pointing device is controlled with INT 33 H – The function number is selected through the AL register an AH is usually set to 00 H before the INT 33 H is executed