Third chapter of p145 ~ p252, three times.
Summary
This chapter is mainly learning the assembly code, the assembler is not variable, only the registers, memory, instructions, etc.
Register classified as follows:
- Program counter (commonly referred to as "PC", x86-64 expressed by% rip) gives the next instruction to be executed is the address in memory.
- The integer register file 16 contains naming locations, each storing 64-bit values generally used to save function parameters, local variables, return values.
- Condition code register save state, if and while for realizing the like.
- A set of vector registers for storing one or more integer or floating point.
Benpian just mainly about the use of the integer registers.
Data Format
Intel represented by 16-bit data type word, double words (double word) represents 32-bit data types, quad words (four words) indicates 64
Integer registers
X86-64 of a CPU memory contains a set of 16 64-bit general-purpose registers worth, for storing integer data and 64-bit pointer named summarized as follows:.
% RAX return value
% rbx,% rbp,% r12 ,% r13 ,% r14,% r15 callee saved
% rdi,% rsi,% rdx ,% rcx,% r8,% r9 of 1,2,3,4,5,6 argument
% rsp stack pointer
% r10,% r11 the caller save
Complete Figure
Addressing
Divided into several addressing, register addressing, absolute addressing, indirect addressing, indexed addressing immediately. Referring specifically to FIG lower
instruction
Mentioned above are the basics, introduces the following start instructions, instruction usage based on the above basis.
MOV
Role of the MOV instruction is to copy data from one place to another. The basic format MOV S, D
, the effect is to copy S to D.
There are many different formats MOV instruction, functions are the same, but different size of transfer data such as movb, movw, movl, movq, movabsq, respectively, byte, word, long, quad word, abs quad word.
x86-64 has a limit, can not be completed from one memory to another memory in the mov instruction.
When the source and destination sizes are inconsistent, there are two categories mov instruction, movz and movs instructions, were used to achieve zero-extended (high bit 0) and the sign-extended (high bit of the sign bit). Movz zero extension, symbol movs extended below:
cltq is a quick instruction, cltq = movslq% eax,% rax. I wonder what use this command, the next check, quite interesting, original y referenced when the function is not declared, from 32-bit to 64-bit , the compiler will automatically add cltq conversion, and the conversion may be a problem. reference Links
Stack command
Instruction stack operation has two pushq and popq, pushq% rbp => subq $ 8,% rsp; movq% rbp, (% rsp); popq% rax => movq (% rsp),% rax; addq $ 8,% rsp ;
x86-64, the program stack stored in a memory area, the stack grows downwards, so that the physical bottom of the stack to a position higher than the physical location of the stack, the stack out of the stack are in operation, as shown below:
Arithmetic and logic operation instruction
Common arithmetic, with non-exclusive or, left right and other operations shown below:
leaq rather special instructions