-
Notifications
You must be signed in to change notification settings - Fork 298
/
codesnippets.s
70 lines (59 loc) · 1.93 KB
/
codesnippets.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// This file contains the various code
// snippets from Chapter 2. This ensures
// they compile and gives you a chance
// to single step through them.
// They are labeled, so you can set a
// breakpoint at the one you are interested in.
.global _start
.align 4
_start:
l1: ADD X0, XZR, X1
MOV X0, X1
ORR X0, XZR, X1
// Load X2 with 0x1234FEDC4F5D6E3A first using MOV and MOVK
l2: MOV X2, #0x6E3A
MOVK X2, #0x4F5D, LSL #16
MOVK X2, #0xFEDC, LSL #32
MOVK X2, #0x1234, LSL #48
l3: LSL X1, X2, #1 // Logical shift left
LSR X1, X2, #1 // Logical shift right
ASR X1, X2, #1 // Arithmetic shift right
ROR X1, X2, #1 // Rotate right
l4: LSL X1, X2, #1 // Logical shift left
LSR X1, X2, #1 // Logical shift right
ASR X1, X2, #1 // Arithmetic shift right
ROR X1, X2, #1 // Rotate right
l5: // Too big for #imm16
MOV X1, #0xAB000000
// Uncomment the next line if you want to see the
// Assembler error for a constant that can't be
// represented.
// MOV X1, #0xABCDEF11 // Too big for #imm16 and can’t be represented.
l6: // the immediate value can be 12-bits, so 0-4095
// X2 = X1 + 4000
ADD X2, X1, #4000
// the shift on an immediate can be 0 or 12
// X2 = X1 + 0x20000
ADD X2, X1, #0x20, LSL 12
// simple addition of two registers
// X2 = X1 + X0
ADD X2, X1, X0
// addition of a register with a shifted register
// X2 = X1 + (X0 * 4)
ADD X2, X1, X0, LSL 2
// With register extension options
// X2 = X1 + signed extended byte(X0)
ADD X2, X1, W0, SXTB
// X2 = X1 + zero extended halfword(X0) * 4
ADD X2, X1, W0, UXTH 2
l8: ADDS X0, X0, #1
l9: ADDS X1, X3, X5 // Lower order 64-bits
ADC X0, X2, X4 // Higher order 64-bits
// Setup the parameters to exit the program
// and then call the kernel to do it.
MOV X0, #0 // Use 0 return code
MOV X16, #1 // System call number 1 terminates this program
SVC #0x80 // Call kernel to terminate the program
.data
helloworld: .ascii "Hello World!"