6 ms·
A book teaching assembly language programming on the ARM 64 bit ISA
- Sirened 4y agoFor all those learning (or even those who've learned :P), my favorite cheatsheet that I always pull up while writing ARMv8-A assembly is this one [1] from the University of Washington. ARMv8-A has a lot of fairly complex instructions and sometimes it's hard to remember all the odds and ends. [1] https://courses.cs.washington.edu/courses/cse469/19wi/arm64.pdf https://courses.cs.washington.edu/courses/cse469/19wi/arm64....
- ryao 4y agoDo you have one that can explain the operand syntax for the instructions that have operands starting with 'v' here: https://gcc.godbolt.org/z/16a91n4zc https://gcc.godbolt.org/z/16a91n4zc
- murderfs 4y agoThose are NEON registers. v0.2d is the vector register v0, interpreted as two double words (i.e. two 64-bit elements). ARM's documentation for this kind of thing is fairly good if you can find it: https://developer.arm.com/documentation/102474/0100/Fundamentals-of-Armv8-Neon-technology https://developer.arm.com/documentation/102474/0100/Fundamen...
- PainfullyNormal 4y ago> You will need to run a ARM Linux VM on the Macintosh - even on ARM-based Macs. Why? Apple. That's why. I'm going to need a better answer than that. The whole reason I want to learn ARM is to get closer to the machine I'm actually using, not to get closer to a linux virtual machine that I will never use again running on the machine I'm actually using.
- canis-fam 4y agoCriticism appreciated. Reasons are now explained in the README. We promise a future chapter to bridge what is used elsewhere back to the Mac M1. And also, a chapter bridging to what is used on Windows ARM machines.
- pmontra 4y agohttps://github.com/below/HelloSilicon https://github.com/below/HelloSilicon
- PainfullyNormal 4y agoOh, awesome. Thanks!
- saagarjha 4y agoBecause they probably have Linux syscall numbers in their examples and those won’t work on macOS.
- ryao 4y agohttps://www.qemu.org/docs/master/user/main.html#linux-user-space-emulator https://www.qemu.org/docs/master/user/main.html#linux-user-s... QEMU can fix that.
- pm215 4y agoNo, it can't -- QEMU's usermode emulator translates Linux-to-Linux only, it does not let you run Linux binaries on macos. And since it's an emulator it's arguably taking you even further from the bare metal than running a VM, which (assuming hypervisor.framework or equivalent) is at least executing the guest instructions directly on the real CPU.
- pmontra 4y agoTwo notes to the author: 1. It would be nice to explain how to install an assembler (part of gcc?), how to run it on source code, how to run the program. Googled, not tested: as -o prog.o prog.s ld -o prog prog.o ./prog 2. Apparently GitHub accepts commits in the future because the last ones in this repo are timestamped Dec 23 2023.
- masklinn 4y ago> Apparently GitHub accepts commits in the future Of course. And this is made very annoying by github also insisting on reordering commits “chronologically” rather than topologically. If someone fucks up their local date (because they wanted to test something and forgot to reset it) you get a commit permanently pinned at the top of a branch until that date passes.
- ryao 4y agoI am not the author, but I suspect qemu-user would be helpful here: https://www.qemu.org/docs/master/user/main.html https://www.qemu.org/docs/master/user/main.html He would just need to say how to get an assembler that would work. llvm-as might work, but I am not sure how to get it to produce code for another architecture offhand.
- ptspts 4y agoOn my Ubuntu, there are many cross-assemblers (including ARM, RISC-V and PowerPC) and linkers available in packages. These packages have binutils in their name. Once installed, the assembler command has -as at the end of its name, and the linker has -ld there.
- canis-fam 4y agoCriticism appreciated. The main README now contains install and build instructions. The main body of the book will, over time, be updated to include build instructions for each example. As per date... I'm at a loss. I believe my own machines are set correctly.
- Kwpolska 4y agoWhy would GitHub prevent commits from the future? Git allows commit dates from the future and from before git was invented, and GitHub's job is to store git repositories.
- ryao 4y ago> In fact, we would argue that the study of assembly language is extremely important to the building of competent software engineers. Further, we would argue that teaching the x86 instruction set is cruel as that ISA was born in the 1970s and has simply gotten more muddled with age. > The MIPS instruction set is another ISA that is often covered in College level courses. While kinder and gentler than the x86 ISA, the MIPS processor isn't nearly as relevant as the ARM family. I disagree. My university taught me MIPS assembly and its only utility has been in enabling me to understand x86_64 assembly poorly. When I look at the disassembly of my code, it is in x86_64 assembly, yet I realized yesterday that I have no clue what the difference is between signed and unsigned subtraction on x86_64. Had that been covered in my university class, I would not be in a position where I need to reverse engineer how that works by working out the math based on the very succinct documentation. I only recently dabbled with aarch64 and POWER9 because I felt inspired to try to make ZFS' fletcher4 checksum algorithm run faster on various architectures. I had no success on POWER9 due to the Talos II workstation being severely memory bandwidth limited, but had fairly good success on x86_64 and aarch64, although the PRs with that code are still works in progress. A guide for NEON and SVE would be great, since that is the only aspect of the aarch64 assembly that I did not understand well enough to muddle through it in my recent fletcher4 adventures, but that does not appear to be here. Thankfully, Clang did an awesome job compiling GNU C dialect vector extensions into efficient, easy to understand NEON assembly (even if I had no clue about the notation used for registers), so I did not need to learn the syntax. For students, I would suggest learning x86_64, since that is what they are going to be using and if they can learn that, they can learn just about any assembly language (although the RISC-V Vector Extension might pose some trouble). The broader industry shift from x86_64 to aarch64 is still years away and ARM seems determined to kill it before it is here by suing Qualcomm for wanting to build ARM processors under the license they already paid ARM to give them. ARM can say whatever they want in court, but at the end of the day, ARM IP now looks toxic. I hope RISC-V can take the baton from aarch64. It could very well be our only hope for a x86_64-free future given ARM's major strategic mistake.
- masklinn 4y ago> ARM seems determined to kill it before it is here by suing Qualcomm for wanting to build ARM processors under the license they already paid ARM to give them That is not what they are doing at all and it’s very dishonest of you to pretend it is.
- uptakeinhibitor 4y agoYou might be interested in this repo that converts asmtutor to Arm64. It's not the most faithful port though: https://github.com/lirorc/arm-asm-examples https://github.com/lirorc/arm-asm-examples
- boberoni 4y agoI’m a noob at assembly and this was something that I never figured out: For assembly languages, how does package management work? As an example, how would I “import” code from my co-worker or from an open source library on GitHub? My first thought is that “maybe this is what a linker does…”, but what sort of toolchains exist for dependency management in assembly programming? What’s the analogy to pip, npm, cargo, etc.?
- robinsonb5 4y agoThe idea of having dependency and package management system as an inherent part of a language's ecosystem is pretty new, and there isn't really any such thing even for C, let alone assembly language. So the short answer is "that's your problem", to solve however you wish! Personally I use git submodules.
- AshamedCaptain 4y agoYour operating system's package manager is the one going to do that.
- flohofwoe 4y ago> What’s the analogy to pip, npm, cargo, etc.? mkdir and cp basically (or git submodules if you want to get fancy)
- dboreham 4y agoIt's what the linker does.
- shadowofneptune 4y agoEven being able to use that assembly source as listed is not a guarantee. There's no standard macro language, even if two assemblers share most of their syntax. As other posts have said, binary compatibility is more important.
- wyldfire 4y agoThe way you can interact with other code is via symbolic references. Indeed, the linker resolves most of these references. These are stored in an object file as a "relocation". It's considerably less convenient than a package system.
- canis-fam 4y agoThank you for the post here. Interest in the book has exploded. I've already implemented some of the criticism written here. It is appreciated. -- book's author