A concurrent, thread-safe x86_64 assembly implementation of a Reverse Polish Notation (RPN) calculator operating on 64-bit hexadecimal numbers.
Noteć is a stack-based calculator that can run N parallel instances simultaneously, each in its own thread. The calculator uses the processor's hardware stack for computations and implements thread synchronization using spinlocks.
- Reverse Polish Notation: Stack-based expression evaluation
- Hexadecimal arithmetic: Operations on 64-bit numbers in base-16
- Concurrent execution: Multiple calculator instances running in parallel
- Thread synchronization: Custom spinlock implementation for the
Woperation - Hardware stack: Direct use of CPU stack for calculations
0-9, A-F, a-f: Hex digits (automatic number accumulation mode)=: Exit number input mode
+: Addition*: Multiplication-: Negation (unary)
&: AND|: OR^: XOR~: NOT (bitwise negation)
Y: Duplicate top valueX: Swap top two valuesZ: Remove top value
N: Push total number of Noteć instancesn: Push current instance numberg: Call external debug functionW: Thread synchronization - exchange values between two Noteć instances
uint64_t notec(uint32_t n, char const *calc);n: Instance number (0 to N-1)calc: ASCIIZ string containing calculation- Returns: Value from top of stack after execution
# Assemble
nasm -DN=$N -f elf64 -w+all -w+error -o notec.o notec.asm
# Compile example
gcc -DN=$N -c -Wall -Wextra -O2 -std=c11 -o example.o example.c
# Link
gcc notec.o example.o -lpthread -o exampleWhere $N is the number of concurrent Noteć instances.
// Calculate: (~((0xab - 0x12) * 3) & 0xfff) | 0xcde09
notec(0, "6N8ZXab=12-+3*~FFF&cDe09|g");
// Exchange values between instances using thread synchronization
notec(0, "nY1^W"); // XOR instance number with 1, exchange with that instance- Pure x86_64 assembly implementation
- No external libraries
- ABI-compliant register and stack usage
- Spinlock-based synchronization without bus locking
- All arithmetic modulo 2^64
Created in 2021 for the Operating Systems course at the University of Warsaw.