Swift笔记 - 04.MemoryLayout 与 常用汇编指令

MemoryLayout

  • 可以使用MemoryLayout获取数据类型占用的内存大小
enum Password {
case number(Int, Int, Int, Int)
case other
}

MemoryLayout<Password>.stride//40,分配占用的空间大小
MemoryLayout<Password>.size1/33,实际用到的空间大小
MemoryLayout<Passwords.alignment//8,对齐参数

var age = 10

//MemoryLayout<Int>.size
//MemoryLayout<Int>.stride
//MemoryLayout<Int>.alignment

//MemoryLayout.size(ofValue: age)
//MemoryLayout.stride(ofValue: age)
//MemoryLayout.alignment(ofValue: age)
enum Password {
    case number (Int, Int, Int, Int) // 32
    case other // 1
}

var pwd = Password.number (5, 6, 4, 7) // 40
pwd = .other

MemoryLayout<Password>.size // 33
MemoryLayout<Password>.stride // 40
MemoryLayout<Password>.alignment // 8

汇编

常用的汇编指定

•有16个常用寄存器

  • %rax、%rbx、%rcx、%rdx、%rsi、%rdi、%rbp、%rsp
  • %r8、%r9、%r10、%r11、%r12、%r13、%r14、%r15

•寄存器的具体用途

  • %rax常作为函数返回值使用
  • %rdi、%rsi、%rdx、%rcx、%r8、%r9等寄存器常用于存放函数参数
  • %rsp、%rbp用于栈操作

lldb常用指令

继续阅读