Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* make sure you have `nasm` (duh !)

```bash
make
./bin/asmatrix
```
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
bin
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
56 changes: 56 additions & 0 deletions asmatrix.asm
Original file line number Diff line number Diff line change
@@ -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