Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 4.11 KB

README.md

File metadata and controls

37 lines (25 loc) · 4.11 KB

Apple-Silicon-ASM-Examples

Example Assembly Programs for Apple Silicon (M1)


tl;dr -- These are self-contained example programs written in assembly for the Apple M1 chip (Apple Silicon). Use the included makefile and follow the instructions included inside each file to compile and run.


What You Will Find Here

Here are several simple programs written in assembly for Apple's M1 processor (Apple Silicon). Each program is intended to demonstrate some basic assembly instruction or programming concept (such as Loop and Switch). Each are self-contained and can be compiled on an Apple Silicon machine using the included makefile. Compilation instructions and execution instructions are included inside each file.

Using These Files

To try any of these files, download the file of interest and the makefile to your own computer, then use the Terminal to execute the command given inside the file. To run the program, again, use the command given inside the file. Please note, however, that the included makefile expectes to find a file named temp.s. Thus, you will need to either rename the file you wish to compile, or modify the makefile to compile and link the correct filename.

Example:
file = add.two.values.s
(1) Rename to temp.s
(2) Compile with: make
(3) Run with: ./temp ; echo $?
(4) Output given: 20

Sources Used

I originally created this collection of small example programs while watching a series of Assembly programming tutorials on YouTube by Derek Banas. There are four videos in his "Assembly Language Tutorial"" series. However, this tutorial series is aimed at assembly programming for the Raspberry Pi architecture, not Apple Silicon.

Seeing as I mostly work on M1 Apple Machines, I had an interest in learning how to take what I had just learned and apply it to the machines I use in my daily life. However, I was not able to find any clear or simple examples of Apple Silicon Assembly (ASM) code. The only readily available examples I could find were found in Alexander von Below's amazing "HelloSilicon" repository on GitHub, though I found them a bit difficult to search through to find the example I needed.

So, in the end, with a lot of googling, the occasional glance at HelloSilicon, a lot of searching through the ARM Developer website, a ton of trial-and-error, and some last minute help from Peter Cordes and Siguza over at StackOverflow to help me figure out how scanf works on Apple Silicon, I managed to port all of my little Raspberry Pi ASM examples over to Apple Silicon ASM. Whew.

Why This Repository Exists

I made these example programs publically available in the simple hope that someone else wishing to get started with Apple Silicon ASM programming will not have to go through the same trouble I had in finding easy-to-understand code examples to help them get started. Look at them, tinker with them, and then go one to create bigger and better things!

About Me

I'm a simple hobbiest who is interested in learning about a variety of things. I think computers are pretty neat, though I am not a professional programmer. In truth, I am an Associate Professor of English at a university in Japan. I started learning Python about four or five years ago, then I started learning C++ before I quickly switched to C. I enjoy the low-level aspect of working in pure C. This interest led me (only about ten days ago, actually) to take a peek at assembly programming. And thus I watched the four Assebly Language Tutorial videos mentioned above.

Which all goes to say, please don't think I'm some coding expert! I'm simply fumbling my way along as I tinker and play, and I'm happy to share what little I've found along the way.