-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathmovexamps.s
47 lines (37 loc) · 1.44 KB
/
movexamps.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
//
// Examples of the MOV instruction.
//
.global _start // Provide program starting address to linker
.align 4
// Load X2 with 0x1234FEDC4F5D6E3A first using MOV and MOVK
_start: MOV X2, #0x6E3A
MOVK X2, #0x4F5D, LSL #16
MOVK X2, #0xFEDC, LSL #32
MOVK X2, #0x1234, LSL #48
// Just move W2 into W1
MOV W1, W2
// Now lets see all the shift versions of MOV
// This does not appear to work with the clang assembler
// MOV X1, X2, LSL #1 // Logical shift left
// MOV X1, X2, LSR #1 // Logical shift right
// MOV X1, X2, ASR #1 // Arithmetic shift right
// MOV X1, X2, ROR #1 // Rotate right
// Repeat the above shifts using the Assembler mnemonics.
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
// Example that works with 8 bit immediate and shift
MOV X1, #0xAB000000 // Too big for #imm16
// Example that can't be represented and results in an error
// Uncomment the instruction if you want to see the error
// MOV X1, #0xABCDEF11 // Too big for #imm16 and can’t be represented.
// Example of MVN
MOVN W1, #45
// Example of a MOV that the Assembler will change to MVN
MOV W1, #0xFFFFFFFE // (-2)
// 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