今日的行程:
辦公室:8:50 - 18:00
讀書室:19:00 - 20:30
今日的記錄:
N: negative
Z: zero
C: carry
V: overflow
// Add immediate
add x0, x1, #1 // x0 = x1 + 1
add x0, x1, #1, LSL #12 // x0 = x1 + (1 << 12)
// Add two registers
add x0, x1, x2 // x0 = x1 + x2
add x0, x1, x2, UXTB // x0 = x1 + Unsigned_extend_byte(x2)
// Shifting add
add x0, x1, x2, LSL #3 // x0 = x1 + (x2 << 3)
// similiar: adds、adc
mov x1, 0xffff_ffff_ffff_ffff
adds x0, x1, #2 // x0 = x1 + 2, carry
mrs x2, nzcv // x2 == 0x2000_0000 (29th bit: C)
mov x1, 0xffff_ffff_ffff_ffff
mov #2
adc x0, x1, x2 // x0 = x1 + 2 + C
mrs x3, nzcv // C bit is set
一樣要注意的是 immediate 或是 shift 的大小
sub x0, x1, x2 // x0 = x1 - x2
sub x0, x1, x2, LSL #2 // x0 = x1 - (x2 << 2)
sub x0, x1, x2, SXTB // x0 = x1 - Signed_extend_byte(x2)
sub x0, x1, x2, LSL #3 // x0 = x1 - (x2 << 3)
// subs
mov x1, #0x3
mov x2, #0x1
subs x0, x1, x2 // x0 = x1 + not(x2) + 1 = 0x3 + not(0x1) + 0x1
// = 0x3 + 0xffff_ffff_ffff_fffe + 0x1 (carry)
mrs x3, nzcv // x3 == 0x2000_0000
mov x1, #0x3
mov x2, #0x3
subs x0, x1, x2 // x0 = 0x3 + not(0x3) + 0x1
// = 0x3 + 0xffff_ffff_ffff_fffc + 0x1 = 0x0 (carry)
mrs x3, nzcv // c,z bit both set
// sbc
mov x1, #3
mov x2, #1
sbc x0, x1, x2 // x0 = x1 + not(x2) + c = 0x3 + not(0x1) + c
// = 0x3 + 0xffff_ffff_ffff_fffe + c (0x3 + 0xff... carry!, so c == 1)
= 0x3 + 0xffff_ffff_ffff_fffe + 1 = 0x2
mrs x3, nzcv // c bit set
LSL: logic shift left
LSR: logic shift right (0 extend)
ASR: arithmetic shift right (sign extend)
ROR: rotate right
ldr w1, =0x8000_008a
asr w2, w1, 1 // w2 == 0xc000_0045
lsr w3, w1, 1 // w3 == 0x4000_0045
// and, ands
mov x1, #0x3
mov x2, #0
ands x3, x1, x2 // x3 = x1 & x2 = 0
mrs x0, nzcv // z bit set
// orr, eor(exclusive or)
// bic (bit clear)
// clz (count leading zero)
// bfi, ubfx, sbfx
mov x0, #0
mov x1, #0x5
bfi x0, x1, #4, #4 // x0 的 bit [4+4-1, 4] = 0x5
^^^ ^^^
lsb, width
mov x2, #0x8a
ubfx x0, x2, #4, #4 // x0 的 bit [7,4] = (0x8a) --> x0 == 0x8
sbfx x1, x2, #4, #4 // x1 的 bit [7,4] = 0x8a, 高位做 sign extend;
x1 == 0xffff_ffff_ffff_fff8