w04_Assembly_Language_Basics

  • 格式:doc
  • 大小:262.00 KB
  • 文档页数:28

Module 4: Assembly Language Basics错误!使用“开始”选项卡将 Heading 2 应用于要在此处显示的文字。

105 Module 4 Overview106 错误!使用“开始”选项卡将 Heading 1 应用于要在此处显示的文字。

The x86 ArchitectureWhat You Will LearnAt the end of this section, the student will be able to:∙Discuss the basic architecture of the Intel® x86 family of microprocessors∙Discuss Registers and their functions∙Discuss Flags and how they are used错误!使用“开始”选项卡将 Heading 2 应用于要在此处显示的文字。

107Pentium i-386 is a 32-bit CISC (Complex Instruction Set Computer) processor, whereas the APLHA is RISC-based (Reduced Instruction Set Computer). No 16-bit code is covered in this module, however the principles are similar.The processors have a number of general-purpose registers. Registers are special-purpose memory locations that are located in the microprocessor itself. Accessing registers is much faster than accessing external memory. Some registers are general purpose, while others have dedicated functions.General-purpose registers are used to hold values for computation and store results internally. Registers in general are byte, work, or DWORD addressable.The flags register is the only bit addressable register. Any instructions affect the flags register based on the results of a computation. For example, after a subtraction instruction, the zero flag is set if the result is zero and cleared if the result is non-zero.Assembly instructions take 0, 1, or 2 arguments call operands. An operand can be an immediate value, register value, or a pointer to a memory location. The general syntax for Intel Assembly is one of the following:Prefix Instruction [operand 1],[operand 2] ; commentWhere:So for a MOV EAX,[12341234] instruction, the source operand is the value at address 12341234 and the destination operation is the EAX register. This instruction will move the value stored at [12341234] into the EAX register.108 错误!使用“开始”选项卡将 Heading 1 应用于要在此处显示的文字。

Intel 386+ processors contain a variety of 32-bit registers. The i-386 family of processorsis known as non-orthogonal. This means the register and the instruction set are notcompletely interchangeable. In other words, some instructions can only be used withcertain registers. For example, IN and OUT instructions are hardwired to the accumulator(EAX) register, ECX is used for counting for loop instructions, and EDI and ESI are usedfor indexing/string instructions. Other addressing modes can only be applied to certainregisters.The i-386 family has six general-purpose registers – EAX, EBX, ECX, EDX, EDI, ESI.Each register begins with the letter “E" for “Extended” to address the full 32-bits insteadof just 16.AddressingEAX, EBX, ECX, EDX registers can be addressed in the following ways:Similarly syntax exists for EBX, ECX, and EDX.Note:The ESI and EDI registers are not byte addressable.错误!使用“开始”选项卡将 Heading 2 应用于要在此处显示的文字。

109General-Purpose RegistersEAX is also referred to as the Accumulator. This register is used the most and contains the results of many instructions. It is common for compiled code that returns a value to do so using the EAX register.ECX specializes in counting.EBX and EDX are general-purpose registers and are used for addressing memory as a pointer, used as operands for logic and arithmetic functions, and contain the results of instructions. EAX and ECX can also be used for these functions.Indexing RegistersEDI, ESI are general-purpose registers that specialize in indexing. String instructions use EDI as the destination pointer, and ESI for the source pointer. Therefore, in order to copy a block of memory from one place to another, ESI would be set up to point to the source block, and EDI would be set up to point to the destination block. ECX would be loaded with the number of bytes to transfer, the direction flag would be set up to increment or decrement, and then REP MOVS would copy the bytes.Stack RegistersESP and EBP are primarily used for stack manipulation and control. ESP is the stack pointer and used to point to the current stack location. The EBP register is used to point to the stack frame for a given routine. At routine entry, the EBP register is typically saved on the stack and then set equal to the value of the current stack pointer. The EBP is then used to reference arguments and local variables.Flag RegisterThe flags register is a collection of single-bit flags. Many instructions alter the flags to describe the result of the instruction. These flags can then be tested by conditional jump instructions.110 错误!使用“开始”选项卡将 Heading 1 应用于要在此处显示的文字。