Skip to main content

A basic assembler for educational processors.

Project description

Tiny Assembler

Tiny Assembler

PyPI - Version PyPI - License

A basic assembler for educational processors.

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

Installation

Install with pip

    pip install tiny_assembler

Usage

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

    assemble isa.json example.asm

Instruction Set Architecture (ISA)

ISAs are defined in a json file:

	"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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiny_assembler-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tiny_assembler-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file tiny_assembler-0.1.0.tar.gz.

File metadata

  • Download URL: tiny_assembler-0.1.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tiny_assembler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b4d053610e51ba3b61ba1567a436607fbc9fb0a2ee639ae0a4317f4c03fd31da
MD5 427130769a1d1e52fd3bcd2a6ca240a3
BLAKE2b-256 41ea07c567a30375f01bcdd77fe9bddebb72c64d32caebb1cca7051f17ebe6bf

See more details on using hashes here.

File details

Details for the file tiny_assembler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tiny_assembler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tiny_assembler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac26e208643dff4d9dd8d7e217580513ec22ae7b092172d2cebe8f8762cd8aff
MD5 f8e22a8cfdbf6a372c7ec1fd1add7dfe
BLAKE2b-256 6cf3772c4a3e302866f3b6b245abb4edcf5b0eaae9afcaacd342af98e8c4e617

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page