Skip to content

Commit f803b69

Browse files
committed
Proofread readme
1 parent f37e958 commit f803b69

File tree

9 files changed

+25
-26
lines changed

9 files changed

+25
-26
lines changed

Chapter 02/addexamp1.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Examples of the ADD/MOVN instructions.
33
//
44
.global _start // Provide program starting address to linker
5-
.align 2
5+
.align 4
66

77
// Multiply 2 by -1 by using MOVN and then adding 1
88
_start: MOVN W0, #2

Chapter 02/addexamp2.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Example of 128-Bit addition with the ADD/ADC instructions.
33
//
44
.global _start // Provide program starting address to linker
5-
.align 2
5+
.align 4
66

77
// Load the registers with some data
88
// First 64-bit number is 0x0000000000000003FFFFFFFFFFFFFFFF

Chapter 02/movexamps.s

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Examples of the MOV instruction.
33
//
44
.global _start // Provide program starting address to linker
5-
.align 2
5+
.align 4
66

77
// Load X2 with 0x1234FEDC4F5D6E3A first using MOV and MOVK
88
_start: MOV X2, #0x6E3A
@@ -17,14 +17,14 @@ _start: MOV X2, #0x6E3A
1717
// This does not appear to work with the clang assembler
1818
// MOV X1, X2, LSL #1 // Logical shift left
1919
// MOV X1, X2, LSR #1 // Logical shift right
20-
// MOV X1, X2, ASR #1 //Arithmetic shift right
20+
// MOV X1, X2, ASR #1 // Arithmetic shift right
2121
// MOV X1, X2, ROR #1 // Rotate right
2222

2323
// Repeat the above shifts using the Assembler mnemonics.
2424

2525
LSL X1, X2, #1 // Logical shift left
2626
LSR X1, X2, #1 // Logical shift right
27-
ASR X1, X2, #1 //Arithmetic shift right
27+
ASR X1, X2, #1 // Arithmetic shift right
2828
ROR X1, X2, #1 // Rotate right
2929

3030
// Example that works with 8 bit immediate and shift
@@ -36,7 +36,7 @@ _start: MOV X2, #0x6E3A
3636

3737
// Example of MVN
3838
MOVN W1, #45
39-
39+
4040
// Example of a MOV that the Assembler will change to MVN
4141
MOV W1, #0xFFFFFFFE // (-2)
4242

@@ -45,4 +45,3 @@ _start: MOV X2, #0x6E3A
4545
MOV X0, #0 // Use 0 return code
4646
MOV X16, #1 // System call number 1 terminates this program
4747
SVC #0x80 // Call kernel to terminate the program
48-

Chapter 04/case.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
.global _start // Provide program starting address
28-
.align 2
28+
.align 4
2929

3030
_start: // this is the switch portion of the case statement
3131
// branching to select1, select2, select3 or default

Chapter 04/printdword.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212

1313
.global _start // Provide program starting address
14-
.align 2
14+
.align 4
1515

1616
_start: MOV X4, #0x6E3A
1717
MOVK X4, #0x4F5D, LSL #16

Chapter 06/mainmacro.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
.include "uppermacro.s"
1313

1414
.global _start // Provide program starting address to linker
15-
.align 2
15+
.align 4
1616

1717
_start:
1818
// Convert tststr to uppercase

Chapter 06/upper.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010

1111
.global toupper // Allow other files to call this routine
12-
.align 2
12+
.align 4
1313

1414
toupper: MOV X4, X1
1515
// The loop is until byte pointed to by X1 is non-zero

Chapter 12/codesnippets.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ l4: FADD H1, H2, H3 // H1 = H2 + H3
3535
FMUL D1, D2, D3 // D1 = D2 * D3
3636
FDIV D1, D2, D3 // D1 = D2 / D3
3737
FMADD D1, D2, D3, D4 // D1 = D4 + D2 * D3
38-
FMSUB D1, D2, D3, D4 // D1 = D4 D2 *D3
38+
FMSUB D1, D2, D3, D4 // D1 = D4 - D2 * D3
3939
FNEG D1, D2 // D1 = - D2
4040
FABS D1, D2 // D1 = Absolute Value( D2 )
4141
FMAX D1, D2, D3 // D1 = Max( D2, D3 )

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# HelloSilicon
22

3-
An introduction to assembly on Apple Silicon Macs.
3+
An introduction to assembly on Apple silicon Macs.
44

55
## Introduction
66

7-
In this repository, I will code along with the book [Programming with 64-Bit ARM Assembly Language](https://link.springer.com/book/10.1007/978-1-4842-5881-1?source=shoppingads&locale=de&cjsku=9781484258804), adjusting all sample code for Apple's ARM64 line of computers. While Apple's marketing material seems to avoid a name for the platform and talks only about the M1 processor, the developer documentation uses the term "Apple Silicon". I will use this term in the following.
7+
In this repository, I will code along with the book [Programming with 64-Bit ARM Assembly Language](https://link.springer.com/book/10.1007/978-1-4842-5881-1?source=shoppingads&locale=de&cjsku=9781484258804), adjusting all sample code for Apple's ARM64 line of computers. While Apple's marketing material seems to avoid a name for the platform and talks only about the M1 processor, the developer documentation uses the term "Apple silicon". I will use this term in the following.
88

9-
The original sourcecode can be found [here](https://github.com/Apress/programming-with-64-bit-ARM-assembly-language).
9+
The original source code can be found [here](https://github.com/Apress/programming-with-64-bit-ARM-assembly-language).
1010

1111
## Prerequisites
1212

@@ -16,7 +16,7 @@ While I pretty much assume that people who made it here meet most if not all req
1616

1717
* All application samples also require at least [macOS Big Sur](https://developer.apple.com/macos/), [iOS 14](https://developer.apple.com/ios/) or their respective watchOS or tvOS equivalents. Especially for the later three systems it is not a necessity per-se (neither is Xcode 12.2), but it makes things a lot simpler.
1818

19-
* Finally, while all samples can be adjusted to work on the iPhone and all other of Apple's ARM64 devices, for best results you should have access to an [Apple Silicon Mac](https://www.apple.com/newsroom/2020/11/introducing-the-next-generation-of-mac/), formerly known as the MWMNSA, the _Machine We Must Not Speak About_.
19+
* Finally, while all samples can be adjusted to work on the iPhone and all other of Apple's ARM64 devices, for best results you should have access to an [Apple silicon Mac](https://www.apple.com/newsroom/2020/11/introducing-the-next-generation-of-mac/).
2020

2121

2222
## Acknowledgments
@@ -29,7 +29,7 @@ With the exception of the existing iOS samples, the book is based on the Linux o
2929

3030
Linux and Darwin, which were both inspired by [AT&T Unix System V](http://www.unix.org/what_is_unix/history_timeline.html), are significantly different at the level we are looking at. For the listings in the book, this mostly concerns system calls (i.e. when we want the Kernel to do someting for us), and the way Darwin accesses memory.
3131

32-
This file is organized so that you can read the book, and read about the differences for Apple Silicon side by side. The headlines in this document follow those in the book.
32+
This file is organized so that you can read the book, and read about the differences for Apple silicon side by side. The headlines in this document follow those in the book.
3333

3434
## Chapter 1: Getting Started
3535

@@ -68,7 +68,7 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault
6868

6969
If you are reading this, I assume you already knew that the macOS Terminal can be found in _Applications → Utilities → Terminal.app_. But if you didn't I feel honored to tell you and I wish you lots of fun on this journey! Don't be afraid to ask questions.
7070

71-
To make "Hello World" run on Apple Silicon, first the changes from page 78 (Chapter 3) have to be applied to account for the differences between Darwin and the Linux kernel.
71+
To make "Hello World" run on Apple silicon, first the changes from page 78 (Chapter 3) have to be applied to account for the differences between Darwin and the Linux kernel.
7272
To silence the warning, I insert `.align 4` (or `.p2align 2`), because Darwin likes things to be aligned on even boundaries. The books mentions this in Aligning Data in Chapter 5, page 114.
7373

7474
System calls in Linux and macOS have several differences due to the unique conventions of each system. Here are some key distinctions:
@@ -96,12 +96,12 @@ We know the `-o` switch, let's examine the others:
9696
* `-lSystem` tells the linker to link our executable with `libSystem.dylib`. We do that to add the `LC_MAIN` load command to the executable. Generally, Darwin does not support [statically linked executables](https://developer.apple.com/library/archive/qa/qa1118/_index.html). It is [possible](https://stackoverflow.com/questions/32453849/minimal-mach-o-64-binary/32659692#32659692), if not especially elegant to create executables without using `libSystem.dylib`. I will go deeper into that topic when time permits. For people who read _Mac OS X Internals_ I will just add that this replaced `LC_UNIXTHREAD` as of MacOS X 10.7.
9797
* `-sysroot`: In order to find `libSystem.dylib`, it is mandatory to tell our linker where to find it. It seems this was not necessary on macOS 10.15 because _"New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem."_. We use `xcrun -sdk macosx --show-sdk-path` to dynamically use the currently active version of Xcode.
9898
* `-e _start`: Darwin expects an entrypoint `_main`. In order to keep the sample both as close as possible to the book, and to allow it's use within the C-Sample from _Chapter 3_, I opted to keep `_start` and tell the linker that this is the entry point we want to use
99-
* `-arch arm64` for good measure, let's throw in the option to cross-compile this from an Intel Mac. You can leave this off when running on Apple Silicon.
99+
* `-arch arm64` for good measure, let's throw in the option to cross-compile this from an Intel Mac. You can leave this off when running on Apple silicon.
100100

101101

102102
### Reverse Engineering Our Program
103103

104-
While the objdump command line programm works just as well on Darwin and produces the expected output, also try the --macho (or “-m”) option, which causes objdump to use the Mach-O specific object file parser.
104+
While the `objdump` command line program works just as well on Darwin and produces the expected output, also try the `--macho` (or `-m`) option, which causes objdump to use the Mach-O specific object file parser.
105105

106106
## Chapter 2: Loading and Adding
107107

@@ -113,11 +113,11 @@ The gcc assembler accepts `MOV X1, X2, LSL #1`, which is not defined by the [ARM
113113

114114
### Register and Extension
115115

116-
Clang requires the source register to be 32-Bit. This makes sense because with these extensions, the upper 32 Bit of a 64-Bit register will never be touched:
116+
Clang requires the source register to be 32-bit. This makes sense because with these extensions, the upper 32 Bit of a 64-bit register will never be touched:
117117
```
118118
ADD X2, X1, W0, SXTB
119119
```
120-
The GNU Assembler seems to ignore this and allows you to specifiy a 64-Bit source register.
120+
The GNU Assembler seems to ignore this and allows you to specifiy a 64-bit source register.
121121

122122
## Chapter 3: Tooling Up
123123

@@ -254,7 +254,7 @@ bl _printf // call printf
254254
add SP, SP, #32 // Clean up stack
255255
```
256256

257-
So first, we are growing the stack downwards 32 bytes to make room for three 64-Bit values. We are creating space for a fourth value for padding because, as pointed out on page 137 in the book, ARM hardware requires the stack pointer to always be 16-byte aligned.
257+
So first, we are growing the stack downwards 32 bytes to make room for three 64-bit values. We are creating space for a fourth value for padding because, as pointed out on page 137 in the book, ARM hardware requires the stack pointer to always be 16-byte aligned.
258258

259259
In the same command, **X1** is stored at the new location of the stack pointer.
260260

@@ -288,7 +288,7 @@ Also, the size of one variable had to be changed from int to long to make the co
288288

289289
### Listing 9-9
290290

291-
While the `uppertst5.py` file only needed a minimal change, calling the code is a little more challenging. On Apple Silicon Macs, Python is a Mach-O universal binary with two architectures, x86\_64 and arm64e:
291+
While the `uppertst5.py` file only needed a minimal change, calling the code is a little more challenging. On Apple silicon Macs, Python is a Mach-O universal binary with two architectures, x86\_64 and arm64e:
292292

293293
```
294294
% lipo -info /usr/bin/python3
@@ -375,10 +375,10 @@ All that can be said is that clang automatically enables position-independent ex
375375
## Additional references
376376

377377
* [Writing ARM64 Code for Apple Platforms](https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms), documentation how Apple platforms diverge from the standard 64-bit ARM architecture
378-
* [Mach-O Programming Topics](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/MachOTopics/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40001827-SW1), an excellent introduction to the Mach-O executable format and how it differs from ELF. Even if it still refrences PowerPC 64-Bit architecture and says nothing about ARM, most of it is still true.
378+
* [Mach-O Programming Topics](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/MachOTopics/0-Introduction/introduction.html#//apple_ref/doc/uid/TP40001827-SW1), an excellent introduction to the Mach-O executable format and how it differs from ELF. Even if it still refrences PowerPC 64-bit architecture and says nothing about ARM, most of it is still true.
379379
* [What is required for a Mach-O executable to load?](https://stackoverflow.com/a/42399119/1600891)
380380
* [Mac OS X Internals, A Systems Approach](https://www.pearson.ch/Informatik/Macintosh/EAN/9780134426549/Mac-OS-X-Internals) Amit Singh, 2007. For better or worse, this is still the definite compendium on the core of macOS and it's siblings.
381-
* [WWDC20: Explore the new system architecture of Apple Silicon Macs](https://developer.apple.com/videos/play/wwdc2020/10686/) A system overview of the new Apple Silicon machines
381+
* [WWDC20: Explore the new system architecture of Apple silicon Macs](https://developer.apple.com/videos/play/wwdc2020/10686/) A system overview of the new Apple silicon machines
382382
* [Darwin Source Code](https://opensource.apple.com/source/xnu/)
383383
* [ARM Architecture Reference Manual](https://developer.arm.com/documentation/ddi0487/latest/)
384384

0 commit comments

Comments
 (0)