There are two things in assembly code execution: the base and the register.
Into the system
octal
Consists of eight symbols :0 1 2 3 4 5 6 7eight
Into theone
The decimal system
It consists of 10 symbols :0 1 2 3 4 5 6 7 8 9ten
Into theone
N into the system
Is composed of N symbols: everyN
Into theone
So let’s think about under what circumstances could 1 plus 1 be equal to 3? If the decimal system is defined to consist of 10 symbols: 0, 1, 3, 5, 8, A, B, F, S, 6, each decimal carries one. Notice that 0, 1, 3 is just a sign. In this case 1 + 1 = 3, isn’t that interesting. Consider that we can also define our own set of base rules that can be used to encrypt . The following is an octal addition table
0 1 2 3 4 5 6 7
10 11 12 13 14 15 16 17
20 21 22 23 24 25 26 27.1+1 = 2
1+2 = 3 2+2 = 4
1+3 = 4 2+3 = 5 3+3 = 6
1+4 = 5 2+4 = 6 3+4 = 7 4+4 = 10
1+5 = 6 2+5 = 7 3+5 = 10 4+5 = 11 5+5 = 12
1+6 = 7 2+6 = 10 3+6 = 11 4+6 = 12 5+6 = 13 6+6 = 14
1+7 = 10 2+7 = 11 3+7 = 12 4+7 = 13 5+7 = 14 6+7 = 15 7+7 = 16
Copy the code
The octal multiplication table is shown below
0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27..1*1 = 1
1*2 = 2 2*2 = 4
1*3 = 3 2*3 = 6 3*3 = 11
1*4 = 4 2*4 = 10 3*4 = 14 4*4 = 20
1*5 = 5 2*5 = 12 3*5 = 17 4*5 = 24 5*5 = 31
1*6 = 6 2*6 = 14 3*6 = 22 4*6 = 30 5*6 = 36 6*6 = 44
1*7 = 7 2*7 = 16 3*7 = 25 4*7 = 34 5*7 = 43 6*7 = 52 7*7 = 61
Copy the code
- Binary shorthand
Binary:1 0 1 1 1 0 1 1 1 1 0 0Three binaries in a group:101 110 111 100Octal:5 6 7 4A group of four binaries:1011 1011 1100Hexadecimal: B b CCopy the code
Binary: writes from 0 to 1111. 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0 1 2 3 4 5 6 7 8 9 A B C D E F that’s hexadecimal.
Width of data
There is no limit to the size of a mathematical number. It can be infinitely large. But in a computer, due to the constraints of the hardware, the data are all limited in length (we call the data width), the data beyond the maximum width will be discarded.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int test(){
int temp = 0x1FFFFFFFF;
return temp;
}
int main(int argc, char * argv[]) {
printf("%x\n",test());
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}Copy the code
- Common data widths
1 Bit: a Bit is a binary Bit.0 or 1 2 Byte: A Byte consists of eight bits. The smallest unit in memory Byte 3. Word: a Word consists of two bytes (16 bits), which are called the high Byte and the low Byte respectively.
register
The diagram above shows the connection between internal components by bus.
CPU
In addition to theThe controller
,Arithmetic unit
There areregister
. Among themregister
Is used for temporary storage of data. The CPU’s computing speed is very fast. For the sake of performance, the CPU creates a small temporary storage area inside the CPU and copies the data from memory to this small temporary storage area before the operation. The operation is carried out in this small temporary storage area. We call this little temporary storage arearegister
. forarm64
System for the CPU, if the register tox
The beginning of the sentence indicates aA 64 - bit
Register, if withw
It’s one32 -
There are no 16-bit and 8-bit registers available for access and use in the system. Where the 32-bit register is the lower 32-bit part of the 64-bit register and does not stand alone. The most important components in the CPU areregister
, you can control the CPU by changing the contents of registers. The number and structure of registers are different for different cpus.
- Floating point and vector registers
Floating-point number storage and its operation of the particularity, the CPU specifically provides the floating-point number register to deal with the floating-point number. Floating point register 64-bit: D0-D31 32-bit: S0-S31. Today’s CPU support vector operations (vector operations are used in graphics processing related fields) also provide a number of vector registers for support vector computing systems. Vector register 128 bits: V0-V31.
- General purpose register
General purpose register
Also known asData address register
Usually used to do the temporary storage of data calculation, do accumulation, counting, address saving and other functions. These registers are defined to hold operands in CPU instructions and are used as regular variables in the CPU. The ARM64 has 32 64-bit general purpose registersx0
到 x30
, and the XZR(zero register), these general purpose registers are sometimes used for specific purposes. thenw0
到 w28
These are32 -
.. Because 64-bit cpus are compatible with 32 bits, you can use only the lower 32 bits of the 64-bit register. Such asw0
isx0
The lower 32 bits of. In the 8086 assembly, there is a special register segment register :CS, DS, SS, ES four registers to hold the base address of these segments, this belongs to the Intel architecture CPU, not in ARM. You can visually see the memory address of the register during the debugging of the Xcode breakpoint.How does the CPU handle data processing?
The CPU stores the data in memory into the general purpose register and then performs operations on the data in the general purpose register. For example, suppose you have a block in memory that has a green memory space with a value of 3, and you want to increase its value by 1 and store the result in a yellow memory space.1. The CPU first places the value of the green memory space in the X0 register:
mov
X0, green memory space 2, then add the X0 register to 1:add
X0, 1; X0, 1;mov
Yellow memory space, X0
PC register
The PC register is an instruction pointer register, which indicates the address of the instruction currently to be read by the CPU. There is no difference between instructions and data in memory or on disk. They are binary information. While working, the CPU treats some information as instructions and others as data, giving different meanings to the same information. For example, 1110 0000 0000 0011 0000 1000 1010 1010. It can be regarded as data 0xE003008AA. It could also be an instruction mov, x0, x8. The CPU treats the contents of memory cells that the PC points to as instructions. If a piece of memory has been executed by the CPU, it must have been pointed at by the PC. Before executing an instruction, the CPU reads the instruction from memory to the CPU and executes it. Registers run much faster than memory reads and writes, and for performance, the CPU also incorporates a cache storage area. While the program is running, the instruction code and data to be executed are copied to the cache (done by the operating system), and the CPU reads the instructions from the cache in turn to execute. The ARM A11 processor on the iPhoneX has a level 1 cache of 64KB and a level 2 cache of 8M.
- Bl instruction
Where the CPU executes the instruction is determined by the contents of the PC register. We can control the CPU to execute the target instruction by changing the contents of the PC register. ARM64 provides a MOV instruction (transfer instruction) that can be used to modify the values of most registers, such as MOV x0,#10, MOV X1, and #20. However, the MOV instruction cannot be used to set the value of the PC register, and the ARM64 does not provide such a function. The ARM64 provides additional instructions to modify the value of the PC register. These instructions are collectively called transfer instructions, the simplest being the BL instruction. Bl:
- Jump to the label to execute
- Put the next instruction address into
Lr register
.Lr register
The following address is the way back during assembly execution.