arc-assembler
An ARC assembler written in Node.JS.
Presentation
Click here to see the presentation of the project.
Installation
# Install the assembler $ npm install -g arc-asm# Install the interpreter $ npm install -g arc-int
Also, you can checkout the online version.
Usage
Checkout the assembler and interpreter docs
Example
Here we go through the process of assembling a file and then interpreting it.
Write the following content in a file (e.g. hello-world.asm
).
! ======================================= !! Hello World Program written in Assembly !! --------------------------------------- !! This program prints in console the text !! "Hello World" !! ======================================= ! .begin .org 2048 main: ld [h_start], %r1 ld [length], %r2 call loop ! Load characters one by one ! and print them in the consoleloop: ld %r1, %r3 addcc %r1, 4, %r1 addcc %r2, -1, %r2 printc %r3 be done ba loop done: jmpl %r15+4, %r0 h_start: 3000length: 12 ! "Hello World" ASCII codes .org 3000 72 101 108 108 111 32 87 111 114 108 100 10 .end
Assemble this the assembly file using the assembler command line tool. This will generate a executable.
$ arc-asm -s hello-world.asm -o hello1100 0010 0000 0111 0010 1000 0011 1100 << Line 111100 0100 0000 0000 0010 1000 0100 0000 << Line 120100 0000 0000 0000 0000 1000 0001 1000 << Line 131100 0110 0000 0000 0100 0000 0000 0000 << Line 171000 0010 1000 0000 0110 0000 0000 0100 << Line 181000 0100 1000 0000 1011 1111 1111 1111 << Line 191100 0110 0100 1000 1100 0000 0000 0000 << Line 200000 0010 1000 0000 0000 1000 0011 0100 << Line 210001 0000 1000 0000 0000 1000 0001 1000 << Line 221000 0001 1100 0011 1110 0000 0000 0100 << Line 240000 0000 0000 0000 0000 1011 1011 1000 << Line 260000 0000 0000 0000 0000 0000 0000 1100 << Line 270000 0000 0000 0000 0000 0000 0100 1000 << Line 310000 0000 0000 0000 0000 0000 0110 0101 << Line 320000 0000 0000 0000 0000 0000 0110 1100 << Line 330000 0000 0000 0000 0000 0000 0110 1100 << Line 340000 0000 0000 0000 0000 0000 0110 1111 << Line 350000 0000 0000 0000 0000 0000 0010 0000 << Line 360000 0000 0000 0000 0000 0000 0101 0111 << Line 370000 0000 0000 0000 0000 0000 0110 1111 << Line 380000 0000 0000 0000 0000 0000 0111 0010 << Line 390000 0000 0000 0000 0000 0000 0110 1100 << Line 400000 0000 0000 0000 0000 0000 0110 0100 << Line 410000 0000 0000 0000 0000 0000 0000 1010 << Line 42
Then run it as executable (you have to make sure you installed the interpreter globally):
$ ./helloHello World
Or interpret it with the arc-int
tool:
$ arc-int helloHello World
📝 Documentation
Supported Instructions
Branch
be
be label
If the z
bit from the PSR
register is 1
, the subrutine located at label
address is called.
bneg
bneg label
If the n
bit from the PSR
register is 1
, the subrutine located at label
address is called.
bcs
bcs label
If the c
bit from the PSR
register is 1
, the subrutine located at label
address of is called.
bvs
bvs label
If the v
bit from the PSR
register is 1
, the subrutine located at label
address is called.
ba
ba label
Branch always the subrutine located at label
address.
CALL
call
call label
Calls a subrutine located at label
address and stores the current address in r15
.
jpml
jmpl %r15+4, %r0
Jumps at the address indicated by r15
register value and stores the result in r0
.
Arithmetic
addcc
addcc %r1, %r2, %r3
Sums the values of r1
and r2
in r3
.
andcc
andcc %r1, %r2, %r3
Bitwise AND between r1
and r2
, storing the result in r3
.
andncc
andncc %r1, %r2, %r3
Bitwise NOT AND between r1
and r2
, storing the result in r3
.
orcc
orcc %r1, %r2, %r3
Bitwise OR between r1
and r2
, storing the result in r3
.
orncc
orncc %r1, %r2, %r3
Bitwise NOR between r1
and r2
, storing the result in r3
.
xorcc
xorcc %r1, %r2, %r3
Bitwise XOR between r1
and r2
, storing the result in r3
.
Memory
ld
ld [x], %r1
Load value from x
address into r1
.
st
ld %r1, [x]
Stores r1
value into x
address.
Output
printn
printn %r1
Prints in console the decimal number from %r1
.
printc
printc %r1
Prints in console the character from %r1
.
Supported pseudo-operations
.begin
.begin
Start assembling.
.end
.end
Stop assembling.
.org
.org 2048
Changes location counter to 2048
.
😋 How to contribute
Have an idea? Found a bug? See how to contribute.
🍰 Thanks
Back in 2014, I coded this during the Computer Architecture course by @HoreaOros–one of my greatest computer-science teachers. ❇️ 🍰