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/.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/.gitignore b/.gitignore new file mode 100644 index 0000000..b30a728 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +bin 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 new file mode 100644 index 0000000..31c5663 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +BIN := bin +TARGET := $(BIN)/asmatrix +OBJ := $(BIN)/asmatrix.o + +UNAME_S := $(shell uname -s) + +ifeq ($(UNAME_S),Darwin) + # 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 + ASM_FORMAT := elf64 + ASM_FLAGS := + LDFLAGS := -no-pie + LDLIBS := -lncurses +endif + +all: $(TARGET) + +$(TARGET): $(OBJ) + gcc $(LDFLAGS) $(OBJ) -o $(TARGET) $(LDLIBS) + +$(OBJ): asmatrix.asm + mkdir -p $(BIN) + nasm -f $(ASM_FORMAT) $(ASM_FLAGS) asmatrix.asm -o $(OBJ) + +clean: + rm -rf $(BIN) diff --git a/asmatrix.asm b/asmatrix.asm new file mode 100644 index 0000000..19c37e3 --- /dev/null +++ b/asmatrix.asm @@ -0,0 +1,56 @@ +global main + +; imports +extern initscr +extern cbreak +extern noecho +extern printw +extern refresh +extern getch +extern endwin +extern keypad +extern stdscr + +section .data + ; msg = ["a", "s", "s", "\n" (10), "\0" (0)] + msg db "ass", 10, 0 + +section .text +default rel + +main: + ; stack alignment + sub rsp, 8 + + ; initialise the screen + call initscr + call cbreak + call noecho + + ; keypad (stdscr, TRUE) +%ifdef MACOS + mov rdi, [stdscr wrt ..gotpcrel] + mov rdi, [rdi] +%else + mov rdi, [stdscr] +%endif + mov esi, 1 + call keypad + + ; 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 + call endwin + + ; restore stack pointer + add rsp, 8 + xor eax, eax + ret