From e019c0ebbc0ed73cfa1013796401b87ed13521f4 Mon Sep 17 00:00:00 2001 From: Saurav Maheshkar Date: Sat, 24 Jan 2026 18:49:11 +0000 Subject: [PATCH 1/3] let us begin --- .github/README.md | 6 ++++++ .gitignore | 2 ++ Makefile | 15 +++++++++++++++ asmatrix.asm | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 .github/README.md create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 asmatrix.asm diff --git a/.github/README.md b/.github/README.md new file mode 100644 index 0000000..1255014 --- /dev/null +++ b/.github/README.md @@ -0,0 +1,6 @@ +* make sure you have `nasm` (duh !) + +```bash +make +./bin/asmatrix +``` diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b30a728 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..90c1310 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +BIN := bin +TARGET := $(BIN)/asmatrix +OBJ := $(BIN)/asmatrix.o + +all: $(TARGET) + +$(TARGET): $(OBJ) + gcc -no-pie $(OBJ) -o $(TARGET) -lncurses + +$(OBJ): asmatrix.asm + mkdir -p $(BIN) + nasm -f elf64 asmatrix.asm -o $(OBJ) + +clean: + rm -rf $(BIN) diff --git a/asmatrix.asm b/asmatrix.asm new file mode 100644 index 0000000..07e522e --- /dev/null +++ b/asmatrix.asm @@ -0,0 +1,39 @@ +global main + +extern initscr +extern cbreak +extern noecho +extern printw +extern refresh +extern getch +extern endwin +extern keypad +extern stdscr + +section .data + msg db "ass", 10, 0 + +section .text +main: + sub rsp, 8 ; stack alignment + + call initscr + call cbreak + call noecho + + ; keypad(stdscr, TRUE) + mov rdi, [rel stdscr] ; WINDOW *win + mov esi, 1 ; TRUE + call keypad + + lea rdi, [rel msg] + xor eax, eax ; variadic ABI rule + call printw + + call refresh + call getch ; blocks + call endwin + + add rsp, 8 + xor eax, eax + ret From 82d6532802a88ca1b839e534acc4f60e204b8df4 Mon Sep 17 00:00:00 2001 From: x0prc Date: Sun, 25 Jan 2026 01:16:52 +0530 Subject: [PATCH 2/3] feat: add macOS support style: add pre-commit --- .pre-commit-config.yaml | 9 +++++++++ Makefile | 19 +++++++++++++++++-- asmatrix.asm | 33 +++++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..24bdd0e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-yaml + - id: check-merge-conflict + - id: detect-private-key diff --git a/Makefile b/Makefile index 90c1310..f0251d0 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,29 @@ BIN := bin TARGET := $(BIN)/asmatrix OBJ := $(BIN)/asmatrix.o +# Detect operating system +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S),Darwin) + # macOS settings + ASM_FORMAT := macho64 + ASM_FLAGS := --prefix _ -DMACOS + LDFLAGS := -arch x86_64 +else + # Linux settings + ASM_FORMAT := elf64 + ASM_FLAGS := + LDFLAGS := -no-pie +endif + all: $(TARGET) $(TARGET): $(OBJ) - gcc -no-pie $(OBJ) -o $(TARGET) -lncurses + gcc $(LDFLAGS) $(OBJ) -o $(TARGET) -lncurses $(OBJ): asmatrix.asm mkdir -p $(BIN) - nasm -f elf64 asmatrix.asm -o $(OBJ) + nasm -f $(ASM_FORMAT) $(ASM_FLAGS) asmatrix.asm -o $(OBJ) clean: rm -rf $(BIN) diff --git a/asmatrix.asm b/asmatrix.asm index 07e522e..19c37e3 100644 --- a/asmatrix.asm +++ b/asmatrix.asm @@ -1,5 +1,6 @@ global main +; imports extern initscr extern cbreak extern noecho @@ -11,29 +12,45 @@ extern keypad extern stdscr section .data + ; msg = ["a", "s", "s", "\n" (10), "\0" (0)] msg db "ass", 10, 0 section .text +default rel + main: - sub rsp, 8 ; stack alignment + ; stack alignment + sub rsp, 8 + ; initialise the screen call initscr call cbreak call noecho - ; keypad(stdscr, TRUE) - mov rdi, [rel stdscr] ; WINDOW *win - mov esi, 1 ; TRUE + ; keypad (stdscr, TRUE) +%ifdef MACOS + mov rdi, [stdscr wrt ..gotpcrel] + mov rdi, [rdi] +%else + mov rdi, [stdscr] +%endif + mov esi, 1 call keypad - lea rdi, [rel msg] - xor eax, eax ; variadic ABI rule - call printw + ; load address of msg + lea rdi, [msg] + ; since printw is a variadic function, + ; we must declare number of registers used. + ; xor eax, eax := 0 since we are using + ; printw with 0 arguments + xor eax, eax + call printw call refresh - call getch ; blocks + call getch call endwin + ; restore stack pointer add rsp, 8 xor eax, eax ret From 1ec48c67d8ba46cd32637cb7314fa74536077108 Mon Sep 17 00:00:00 2001 From: x0prc Date: Sun, 25 Jan 2026 21:27:15 +0530 Subject: [PATCH 3/3] feat : add CI Co-authored-by: Saurav --- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++++++++++++++++ Makefile | 15 +++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..edf33b8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + branches: [main] + paths: + - "**.asm" + - ".github/workflows/ci.yml" + pull_request: + branches: [main] + paths: + - "**.asm" + - ".github/workflows/ci.yml" + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + # https://github.com/actions/runner-images?tab=readme-ov-file#available-images + os: [macos-latest, macos-15-intel, ubuntu-slim] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install NASM on macOS + if: runner.os == 'macOS' + run: brew install nasm + + - name: Install NASM on Linux + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y nasm libncurses-dev + + - name: Build + run: make + shell: bash diff --git a/Makefile b/Makefile index f0251d0..31c5663 100644 --- a/Makefile +++ b/Makefile @@ -2,25 +2,32 @@ BIN := bin TARGET := $(BIN)/asmatrix OBJ := $(BIN)/asmatrix.o -# Detect operating system UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) - # macOS settings + # macOS ASM_FORMAT := macho64 ASM_FLAGS := --prefix _ -DMACOS LDFLAGS := -arch x86_64 + LDLIBS := -lncurses +else ifneq (,$(findstring MINGW,$(UNAME_S))) + # Windows (MinGW) + ASM_FORMAT := elf64 + ASM_FLAGS := -DWINDOWS + LDFLAGS := -no-pie + LDLIBS := -lpdcurses else - # Linux settings + # Linux ASM_FORMAT := elf64 ASM_FLAGS := LDFLAGS := -no-pie + LDLIBS := -lncurses endif all: $(TARGET) $(TARGET): $(OBJ) - gcc $(LDFLAGS) $(OBJ) -o $(TARGET) -lncurses + gcc $(LDFLAGS) $(OBJ) -o $(TARGET) $(LDLIBS) $(OBJ): asmatrix.asm mkdir -p $(BIN)