Page 91 - ARM 64 Bit Assembly Language
P. 91
76 Chapter 3
8 stp x29, x30, [sp, #-16]!
9
10 // w9 = getchar()
11 bl getchar
12 mov w9, w0
13
14 // printf("char: %c\n", x9)
15 ldr x0, =formatString
16 mov w1, w9
17 bl printf
18
19 // return 0
20 mov w0, 0
21 ldp x29, x30, [sp], #16
22 ret
23 .size main, (. - main)
3.5.4 Compare and branch
These instructions are used to branch conditionally if a register is zero or nonzero (or if a bit
is zero or nonzero):
cbz Compare and Branch if Zero,
cbnz Compare and Branch if Nonzero,
tbz Test Bit and Branch if Zero, and
tbnz Test Bit and Branch if Nonzero.
3.5.4.1 Syntax
cb{n}z Rt, <label>
tb{n}z Rt, #imm6, <label>
• The cbz and cbnz instructions have a range of ±1MB(encodedin19bits).
• The range of the tbz and tbnz instructions is ±32 KB (encoded in 14 bits).
• imm6 specifies which bit to test (0 to 63).
• The <label> must always be word-aligned.
3.5.4.2 Operations
Name Effect Description
cbz if Rt = 0 then Conditionally branch to label if Rt is
pc ← label zero.
end if
continued on next page