Metadata-Version: 2.4
Name: tiny_assembler
Version: 0.1.0
Summary: A basic assembler for educational processors.
Project-URL: Homepage, https://github.com/arta-ns/tiny_assembler
Project-URL: Bug Tracker, https://github.com/arta-ns/tiny_assembler/issues
Project-URL: Documentation, https://github.com/arta-ns/tiny_assembler/tree/main/src/tiny_assembler/html/tiny_assembler/index.html
Author-email: "N. Sertac Artan" <artans.github@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# Tiny Assembler 

![Tiny Assembler](logo.png)

![PyPI - Version](https://img.shields.io/pypi/v/tiny-assembler) ![PyPI - License](https://img.shields.io/pypi/l/tiny-assembler)

A basic assembler for educational processors.

This project is licensed under the terms of the MIT license.

# Installation

Install with pip

```bash
    pip install tiny_assembler
```

# Usage

To assemble `example.asm` based on `isa.json`. The output will be written to `example.mem`.

```bash
    assemble isa.json example.asm
```

# Instruction Set Architecture (ISA)

ISAs are defined in a `json` file:

```json
	"metadata":{
		"version": "0.1.0"
	},
	"properties":{
		"INST_WIDTH": 16,
		"DATA_WIDTH": 16,
		"OPCODE_WIDTH": 4,
		"REG_COUNT": 16,
		"LABEL_WIDTH": 10,
		"IMM_WIDTH": 8
	},
	"opcodes":{
		"ADD" : 0,
		"SLL" : 1,
		"SLR" : 2,
		"NOT" : 3,
		"AND" : 4,
		"OR"  : 5,
		"XOR" : 6,
		"NOP" : 7,
		"JMP"  : 8,
		"JZ"   : 8,
		"JNZ"  : 8,
		"LD"   : 10,
		"ST"   : 11,
		"ADDI" : 12,
		"SLLI" : 13,
		"SLRI" : 14,
		"NOTI" : 15
	},
	"subopcodes":{
		"JMP": 0,
		"JZ":  1,
		"JNZ": 2
	},
	"grammar":{
		"RRR":["ADD", "SLL", "SLR", "AND", "OR", "XOR"],
		"RR": ["NOT", "LD", "ST"],
		"RI": ["ADDI", "SLL", "SLR", "NOT"],
		"SL": ["JMP", "JZ", "JNZ"],
		"NON": ["NOP"]
	}
}
```

# Assembly File Example

```asm
start:
NOP 
NOP
ADDI R1, #1 ; Address Incrementer
ADDI R5, #4 ; Upper address limit

read:
LD R3, R4 ; Load Mem[R4] to R3
ADD R4, R4, R1 ; R4 is the loop variable
XOR R6, R5, R4 ; See if we reach the address limit (R4 == R5)
JNZ $read
XOR R4, R4, R4; Clear R4

write:
; First read the content of the destination (Mem[2])
ADDI R2, #2; Address
LD R3, R2 ; Load Mem[R2] to R3
ADD R4, R4, R1; Data to store (incremented by 1 every step
ST R4, R2 ; Store the new data back to Mem[2]
XOR R6, R5, R4 ; See if we reach the end of loop (R4 == R5)
JNZ $write
JMP $start
```

