In this lab, each group was tasked with writing assembly code. We had to write a simple hello world program, extending on it, and running it on the x86_64 and aarch64 servers. We also had to write the assembly for 2 types of assemblers; GNU and NASM. As easy as writing a simple hello world program sounds, it was a tough challenge writing it in assembly. An average programmer using one of the high-level programming languages (C, C++, Java, C#, etc) would probably take about 10 seconds to write it. It took us about 30 mins. And to make it even more challenging, we were tasked with writing a simple loop that would print the loop counter every iteration from 0 – 10 appending to a statically coded string “Loop”. This task alone took us about a half of the next class. And to even expand it, we had to write code to make the program print 2 digits instead of 1 from every iteration between 0 – 10. So the results would look like: Loop 00, Loop 01, Loop 02, Loop 03,…. Loop 30. And this also took about a half of the class. We couldn’t even finish it because we kept getting segmentation-fault and we tried to debug but no success. This entire program, using a high-level programming language, would probably take 1 min or less. But in assembly, you’re in a completely different environment. One of the things I learned that writing in assembly requires you to really know what you’re writing because it’s so easy to mess up and have your program crash. And it also requires you to know what type of registers to use, how many bytes should be allocated, etc. All of this is required because you don’t have a compiler that will do this stuff for you. You have to take care of it and that is much easier said than done.
As for debugging, syntax errors are easy to correct but logical errors are much harder to correct in assembly especially if you’re new to this. You have the debugger available to you and it will show you where your program catches a seg-fault and crashes but to understand why it’s causing the seg-fault may not be clear, making it extremely difficult to fix.
My overall experience was challenging yet meaningful. I got to understand how the computer works at the low-level details as well as key concepts such as the different types of registers for different architectures, different syntax for different architectures, and how you write assembly in general. I can, with confidence, say that writing in assembly is a pain and an awful way to write code and I’m sure many people, if not all, would agree with me. But to understand how assembly works is something I think everyone should know and understand.
My group only manage to finish the x86_64 portion of the lab so here’s the source code for the GNU Assembler (GAS):