Posts

Showing posts from March, 2025

Project Stage 1

Image
In this project, I set out to create a custom GCC pass that analyzed GIMPLE files by iterating through every function, counting the basic blocks, and tallying the number of GIMPLE statements. I successfully integrated this pass into the GCC build system and tested it on a simple C program. Here’s how I did it. 1. Writing the Pass Code I began by writing the pass code in C++ and saved it in a file named tree-my-new-pass.cc within the gcc subdirectory of my GCC source. My pass, which I named "my_new_pass", was designed to run during the GIMPLE phase. The code looked like this: #include "config.h" #include "system.h" #include "coretypes.h" #include "backend.h" #include "tree-pass.h" #include "pass_manager.h" #include "context.h" #include "diagnostic-core.h" #include "tree.h" #include "tree-core.h" #include "basic-block.h" #include "gimple.h" #include "gimp...

Lab 5 - Part 1 - Aarch 64

Image
In this lab, my goal is to dive into assembly programming on both the x86_64 and AArch64 platforms. For Task 1, 1. I will closely examine how the AArch64 assembly source code—written in a human-readable format—is transformed into an object file containing machine code. This investigation will help me understand the assembly process by highlighting the differences between the high-level source instructions and the low-level binary output generated by the assembler. Source file Object file 2 : Constructing a Loop That Prints “Loop” Six Times In this task, I need to adapt the assembly code on the aarch64 server so that it outputs the word “Loop” exactly six times. Starting with the provided code, I will introduce a counter in one of the general-purpose registers, initialize it to zero, and increment it after each print. Once the counter reaches six, the loop will terminate. This requires adjusting the assembly instructions to compare the loop counter against a maximum value, calling the a...

Lab 5 - Part 2 - x86

Image
  For the second part of this lab, I will further explore x86_64 assembly programming, building on what was done in Part 1. 1.  I'll compare the assembly source code with its generated object file to understand how the human-readable instructions are translated into machine code. This exercise will highlight the differences between the code we write and the low-level output produced by the assembler. Source code Object file 2. Revise an x86 assembly loop program so that it outputs "loop" six times. Below is the revised Makefile I used, which includes a rule for building loop-gas . I simply added another entry in the BINARIES list and replicated the same build steps used for hello-gas.s : BINARIES=hello-nasm hello-gas loop-gas all: ${BINARIES} AS_ARGS=-g hello-nasm: hello-nasm.s nasm -g -o hello-nasm.o -f elf64 hello-nasm.s ld -o hello-nasm hello-nasm.o hello-gas: hello-gas.s as ${AS...