Why learn assembler
As we all know, the App installed on the phone is a binary file, which is the machine language of zeros and ones that the machine can recognize, and assembly is a very low-level language that corresponds to machine language one to one, so that we can decompile machine language into assembly language and know the logic inside.
- Assembly language and machine language one – to – one correspondence, can compile and decompile
- High-level languages can be compiled into assembly languages, but assembly can hardly be decompiled into high-level languages
Type of compilation
Different CPUS use different architectures, different architectures correspond to different instruction sets, we mainly study the ARM64 architecture assembly.
architecture | IOS devices |
---|---|
x86 | Simulator, Mac |
armv7 | iPhone3GS, iPhone4, iPhone4S,iPad, iPad2, iPad3(The New iPad), iPad mini, iPod Touch 3G, iPod Touch4 |
armv7s | iPhone5, iPhone5C, iPad4(iPad with Retina Display) |
arm64 | After iPhone5S, iPhoneX, iPad Air, iPad mini2, M1 |
CPU and Register
A CPU has a very important part called a register. Registers are used for temporary storage of data. CPU computing speed is very fast. For performance purposes, the CPU creates a small temporary storage area and copies data from the memory to this small temporary storage area before performing operations. We call this small temporary storage area a register.
- For ARM64 cpus, a register that starts with an X indicates a 64-bit register, and a register that starts with a W indicates a 32-bit register, where the 32-bit register is the lower 32-bit part of the 64-bit register and does not exist independently.
Universal register
- The general purpose register, also known as the data address register, is usually used for temporary storage, accumulation, counting, address storage and other functions of data calculation. The main purpose of these registers is to store operands in CPU instructions and use them as regular variables in the CPU.
- ARM64 has 32 64-bit general purpose registers X0 through X28, FP, LR, SP
- PC register: Instruction pointer register, which shows the address of the current instruction to be read by the CPU
- Fp: Store the address at the bottom of the stack at some point
- Sp: saves the address at the top of the stack
- Lr: Save the way home, meet the ret instruction, PC->lr inside the value