Математика | ||||
ASSEMBLY | ||||
Contents
Introduction...............................................................................1 Who is This Book For?................................................................................1 What is Covered in This Book.....................................................................1 What isn't Covered in This Book..................................................................2 Why Do You Need Assembler?...................................................................2 What You Need to Use This Book...............................................................3 The Structure of the Book............................................................................4 How to Use the Book...................................................................................5 Installing the Disk.........................................................................................5 The Tutorial Program....................................................................................6 The Structure and Usage of the Source Code............................................7 Chapter One: The Assembler Environment...........................9 Fundamental Knowledge.................................................................11 Assembler as a Programming Language..................................................11 Machine Code and Assembly Language...................................................12 Assembler as a Software Component.......................................................13 Creating Programs at a Glance.................................................................14 Source Code and Text Editors...................................................................15 Object Modules and Compilers..................................................................16 The Flelationship Between Modules in a Program.....................................16 Object Libraries and Library Managing......................................................17 Executable Modules and Link Editors........................................................18 The Linking Process..................................................................................19 Two Kinds of Executable Modules.............................................................20 Loading Programs and System Blocks......................................................21 The Processor and its Internal Registers...................................................22 Data Group Registers................................................................................23 The Internal Registers of the 180386/180486..............................................24 The Program Segment Prefix - PSP..........................................................25 Tools..................................................................................................27 Compiling Programs..................................................................................27 Managing Libraries....................................................................................29 Creating Executable Modules....................................................................30 Output from the Assembler........................................................................32 Source Listing - The .LST File...................................................................33 Debugging Programs Using CodeView.....................................................35 The Command CV- The CodeView Debugger.........................................36 The Basic CodeView Features..................................................................38 Stepping Through Programs......................................................................39 Watching Variables....................................................................................40 Watching Local Variables - The Local Window.........................................41 Using the Memory Window........................................................................42 Using Breakpoints......................................................................................42 Library................................................................................................44 A Set of BAT-Files for Dealing with Assemblers........................................44 ASMSw- Choosing an Assembler.............................................................44 ASM - Compiling Programs.......................................................................46 FView - The File Browsing Program..........................................................49 RUN - Running and Debugging Programs................................................49 Summary............................................................................................53 Chapter Two: From Instructions to Programs.....................55 Fundamental Knowledge.................................................................57 The Basic Elements of Programming........................................................57 Preliminaries - Instructions and Directives.................................................57 Operands and Data...................................................................................59 The Instruction Pointer and Program Flow................................................60 Jump into the Loop....................................................................................62 Flags..........................................................................................................62 State Flags.................................................................................................64 Control Flags.............................................................................................67 Additional Flags of i80286 and 180386/180486...........................................68 Tools..................................................................................................69 MOV Instruction.........................................................................................69 ADD and SUB - The Simplest Arithmetic Instructions...............................69 MUL Instruction..........................................................................................70 DIVInstruction...........................................................................................72 JMP - Unconditional Jump.........................................................................73 Checking for Conditional Jumps -CMP.....................................................74 Pseudo High-Level Language Constructions in Assembler.......................76 High-Level Program Flow Using MASM 6.0 Directives.............................78 Simple Loops.............................................................................................80 Library................................................................................................81 A Demo Program to Illustrate Using Flags................................................81 Calculating Factorials................................................................................83 Using Flags - Detecting the Step-by-step Mode........................................88 Summary............................................................................................91 Chapter Three: Memory and Data.........................................93 Fundamental Knowledge.................................................................95 Memory- Purpose and Structure...............................................................95 Segment Addressing.................................................................................96 An Effective Address.................................................................................96 Forms of SegmentOffset Notation............................................................98 Physical and Logical Segments.................................................................99 Program Segments..................................................................................100 The Data Segment...................................................................................100 The Code Segment..................................................................................103 The Stack.................................................................................................104 Tools................................................................................................107 Creating a Program - Starting with the Bare Bones.................................107 EXE Program Template...........................................................................108 COM Program Template..........................................................................111 Using Simplified Directives - General Template......................................113 Defining and Using Data - EQU...............................................................115 Defining Data with the DB Directive.........................................................117 DW and DD Directives.............................................................................118 Addressing Your Data..............................................................................120 The DUP Prefix........................................................................................121 The LEA Instruction.................................................................................121 Instructions Which Work with the Stack...................................................122 Stack and Flags.......................................................................................123 Library..............................................................................................125 Inputting and Outputting Numeric Data...................................................125 Using Flags to Determine the Type of Processor....................................128 Summary..........................................................................................134 Chapter Four: Data Structures............................................135 Fundamental Knowledge...............................................................137 Strings.....................;................................................................................137 Declaring Strings.....................................................................................138 Processing Strings...................................................................................140 Arrays.......................„.............................................................................141 Declaring an Array...................................................................................141 Providing Additional Information for String Variables..............................143 Using and Addressing Arrays..................................................................745 Addressing Modes...................................................................................146 Manipulating Strings and Arrays..............................................................148 Structures................................................................................................750 Unions......................................................................................................757 Defining String Constants........................................................................752 Manipulating String Constants.................................................................752 Tools................................................................................................154 Moving Strings - The MOVS* Instructions...............................................754 Comparing Strings - The CMPS* Instructions.........................................755 Searching Strings - The SCAS" Instructions...........................................755 Processing String Elements - The LODS and STOS Instructions...........756 The REP Prefix........................................................................................757 Specifying Memory Units in Instructions - The PTR Operator.................759 Labels......................................................................................................760 Library..............................................................................................161 Copying Strings - RepBios.......................................................................767 Comparing Strings - CompStr..................................................................762 Sorting Strings - The Program BSort.......................................................765 Summary..........................................................................................171 Chapter Five: Program Flow and Design...........................173 Fundamental Knowledge...............................................................175 Procedures in Assembly Language.........................................................775 An Example of Procedures......................................................................176 Writing a Procedure (SMALL Memory Model).........................................178 Passing Parameters................................................................................180 Passing Parameters Through Registers..................................................180 Passing Parameters in Memory...............................................................181 Passing Parameters Using the Stack......................................................182 Calling Procedures Using INVOKE..........................................................184 NEAR and FAR Procedures....................................................................185 The Directives PUBLIC and EXTRN........................................................186 An Introduction to Macros........................................................................187 Macros with Parameters..........................................................................190 Macro Libraries........................................................................................191 Macros vs Procedures.............................................................................191 Directives and Operators.........................................................................192 Computations and Tests During Program Assembly...............................192 Tools................................................................................................194 Starting With the END!.............................................................................194 The SEGMENT and ENDS Directives.....................................................194 The .MODEL Directive.............................................................................194 The Logical Segment Declaration Directives...........................................196 The ASSUME Directive...........................................................................196 The Procedure Treatment Directives and Instructions............................196 Indirect JMPs and CALLs........................................................................198 The PUBLIC, EXTRN and EXTRNDEF Directives..................................199 Macro Treatment Directives.....................................................................200 The INCLUDE Directive...........................................................................200 The LOCAL Directive...............................................................................201 Assembly- Time Conditions....................................................................20) Library..............................................................................................203 A Small Macrolibrary for Input and Output...............................................203 The Macro Inplnt - Input Integers............................................................206 Using Macros - The Program "Calculator"...............................................207 Summary..........................................................................................211 Chapter Six: Using BIOS and DOS......................................213 Fundamental Knowledge...............................................................215 What is DOS?..........................................................................................215 Levels of DOS Service.............................................................................216 The Main DOS Components....................................................................217 BIOS - Basic Input/Output System..........................................................218 Hidden DOS Files....................................................................................220 The Command Processor........................................................................227 Interrupts..................................................................................................222 The DOS Memory Map............................................................................224 Цена: 300руб. |
||||