Chapter 8 Programming the Microprocessor 8 1 MODULAR

  • Slides: 24
Download presentation
Chapter 8: Programming the Microprocessor

Chapter 8: Programming the Microprocessor

8– 1 MODULAR PROGRAMMING • Many programs are too large to be developed by

8– 1 MODULAR PROGRAMMING • Many programs are too large to be developed by one person. – programs are routinely developed by teams of programmers • The linker program is provided with Visual Studio so that programming modules can be linked together into a complete program. • Linking is also available from the command prompt provided by Windows. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Assembler and Linker • The assembler program converts a symbolic source module (file)

The Assembler and Linker • The assembler program converts a symbolic source module (file) into a hexadecimal object file. • It is even a part of Visual Studio, located in the C: Program FilesMicrosoft Visual Studio. NET 2003Vc 7bin folder. • The version that comes with Visual C will not work for 16 -bit DOS programs. – if a 16 -bit assembler and linker are needed, they are in the Windows Driver Development Kit (DDK) The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • Whenever you create a source file, it should have the extension of

• Whenever you create a source file, it should have the extension of ASM. • Source files are created by using Note. Pad or almost any other word processor or editor capable of generating an ASCII file. • The linker program, which executes as the second part of ML, reads the object files that are created by the assembler program and links them together into a single execution file. • An execution file is created with the file name extension EXE. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • Execution files are selected by typing the file name at the DOS

• Execution files are selected by typing the file name at the DOS prompt (C: ). • If a file is short enough (less than 64 K bytes long), it can be converted from an execution file to a command file (. COM). • The command file is slightly different from an execution file in that the program must be originated at location 0100 H before it can execute. • This means that the program must be no larger than 64 K– 100 H in length. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • Library files are entered after the file name and after the switch

• Library files are entered after the file name and after the switch / LINK. • To use a library called NUMB. LIB while assembling a program called NEW. ASM, type ML NEW. ASM / LINK NUMB. LIB • In the Windows environment you cannot link a program—only assemble program. • You must use Visual Studio to link the program files during the build. • You can assemble a file or files and generate objects for use with Visual C++. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

To use a library called NUMB. LIB type C: masm 614BINml new. asm /LINK

To use a library called NUMB. LIB type C: masm 614BINml new. asm /LINK NUMB. LIB The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

Public and Extern • Very important to modular programming as they allow communications between

Public and Extern • Very important to modular programming as they allow communications between modules. – PUBLIC declares labels of code, data, or entire segments are available to other program modules – EXTRN (external) declares labels are external to a module • Without these statements, modules could not be linked together to create a program by using modular programming techniques. – modules would communicate with one another The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • PUBLIC is placed in the opcode field of a statement to define

• PUBLIC is placed in the opcode field of a statement to define a label as public, so the label can be seen & used by other modules. – made public, they combine with other public segments containing data with the same name • EXTRN appears in both data and code segments to define labels as external to the segment. – if defined as external, sizes must be defined as BYTE, WORD, or DWORD – if jump or call address is external, it must be defined as NEAR or FAR The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

Libraries • Libraries allow common procedures to be collected into one place so they

Libraries • Libraries allow common procedures to be collected into one place so they can be used by many different applications. – assembled and compiled by the LIB program that accompanies the MASM assembler • When the library file is linked with a program, only procedures required by are removed from the library file and added to the program. • A good set of library files is essential and saves hours in recoding common functions. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

Creating a Library File • A library file is a collection of assembled. OBJ

Creating a Library File • A library file is a collection of assembled. OBJ files that contains procedures or tasks written in assembly language or any other language. • The procedure must be declared PUBLIC and does not need to match the file name. • A variable is transferred to each file, so the EXTRN statement also appears in each procedure to gain access to an external variable. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • The LIB program begins with the copyright message from Microsoft, followed by

• The LIB program begins with the copyright message from Microsoft, followed by the prompt Library name. • Because this is a new file, the library program must be prompted with the object file name. • The LIB program is invoked with the object name following it on the command line. • Once a library file is linked to your program, only the library procedures actually used by your program are placed in the execution file. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

Macros • A group of instructions that perform one task, just as a procedure

Macros • A group of instructions that perform one task, just as a procedure performs one task. – a procedure is accessed via a CALL instruction – a macro & all instructions defined in the macro, is inserted in the program at the point of usage • Creating a macro is very similar to creating a new opcode • Macros execute faster than procedures because there is no CALL or RET instruction to execute. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • Macros will not function with the inline assembler – only in external

• Macros will not function with the inline assembler – only in external assembly language modules • MACRO and ENDM directives delineate a macro sequence. – MACRO contains the name of the macro and any parameters associated with it • Last statement of a macro is the ENDM instruction, which is placed on a line by itself. • Never place a label in front of ENDM, – the macro will not assemble The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

Local Variables in a Macro • A local variable is one that appears in

Local Variables in a Macro • A local variable is one that appears in the macro, but is not available outside the macro. – to define use the LOCAL directive • The LOCAL directive must always be used on the line immediately following the MACRO statement or an error occurs. • The LOCAL statement may have up to 35 labels, all separated with commas. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

Placing MACRO Definitions in Their Own Module • Macro definitions can be placed in

Placing MACRO Definitions in Their Own Module • Macro definitions can be placed in the program file or in their own macro module. – a file can be created that contains only macros to be included with other program files • Use the INCLUDE directive to indicate a program file will include a module that contains external macro definitions. • While not a library file, for practical purposes it functions as a library of macro sequences. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

 • When macro sequences are placed in a file they do not contain

• When macro sequences are placed in a file they do not contain PUBLIC statements as does a library. • Programs may contain both macro include files and library files. • A macro file named MACRO. MAC included in an assembly file using the statement: INCLUDE C: ASSMMACRO. MAC • No public or extern directives are needed to access macro statements that have been included. The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium,

The Intel Microprocessors: 8086/8088, 80186/80188, 80286, 80386, 80486 Pentium, Pentium Processor, Pentium II, Pentium, 4, and Core 2 with 64 -bit Extensions Architecture, Programming, and Interfacing, Eighth Edition Barry B. Brey Copyright © 2009 by Pearson Education, Inc. Upper Saddle River, New Jersey 07458 • All rights reserved.