An ARC assembler written in Node.JS.
Click here to see the presentation of the project.
# Install the assembler
$ npm install -g arc-asm
# Install the interpreter
$ npm install -g arc-int
Also, you can checkout the online version.
Checkout the assembler and interpreter docs
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 console
loop: ld %r1, %r3
addcc %r1, 4, %r1
addcc %r2, -1, %r2
printc %r3
be done
ba loop
done: jmpl %r15+4, %r0
h_start: 3000
length: 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 hello
1100 0010 0000 0111 0010 1000 0011 1100 << Line 11
1100 0100 0000 0000 0010 1000 0100 0000 << Line 12
0100 0000 0000 0000 0000 1000 0001 1000 << Line 13
1100 0110 0000 0000 0100 0000 0000 0000 << Line 17
1000 0010 1000 0000 0110 0000 0000 0100 << Line 18
1000 0100 1000 0000 1011 1111 1111 1111 << Line 19
1100 0110 0100 1000 1100 0000 0000 0000 << Line 20
0000 0010 1000 0000 0000 1000 0011 0100 << Line 21
0001 0000 1000 0000 0000 1000 0001 1000 << Line 22
1000 0001 1100 0011 1110 0000 0000 0100 << Line 24
0000 0000 0000 0000 0000 1011 1011 1000 << Line 26
0000 0000 0000 0000 0000 0000 0000 1100 << Line 27
0000 0000 0000 0000 0000 0000 0100 1000 << Line 31
0000 0000 0000 0000 0000 0000 0110 0101 << Line 32
0000 0000 0000 0000 0000 0000 0110 1100 << Line 33
0000 0000 0000 0000 0000 0000 0110 1100 << Line 34
0000 0000 0000 0000 0000 0000 0110 1111 << Line 35
0000 0000 0000 0000 0000 0000 0010 0000 << Line 36
0000 0000 0000 0000 0000 0000 0101 0111 << Line 37
0000 0000 0000 0000 0000 0000 0110 1111 << Line 38
0000 0000 0000 0000 0000 0000 0111 0010 << Line 39
0000 0000 0000 0000 0000 0000 0110 1100 << Line 40
0000 0000 0000 0000 0000 0000 0110 0100 << Line 41
0000 0000 0000 0000 0000 0000 0000 1010 << Line 42
Then run it as executable (you have to make sure you installed the interpreter globally):
$ ./hello
Hello World
Or interpret it with the arc-int
tool:
$ arc-int hello
Hello World
There are few ways to get help:
- Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
- For bug reports and feature requests, open issues. π
- For direct and quick help, you can use Codementor. π
be label
If the z
bit from the PSR
register is 1
, the subrutine located at label
address is called.
bneg label
If the n
bit from the PSR
register is 1
, the subrutine located at label
address is called.
bcs label
If the c
bit from the PSR
register is 1
, the subrutine located at label
address of is called.
bvs label
If the v
bit from the PSR
register is 1
, the subrutine located at label
address is called.
ba label
Branch always the subrutine located at label
address.
call label
Calls a subrutine located at label
address and stores the current address in r15
.
jmpl %r15+4, %r0
Jumps at the address indicated by r15
register value and stores the result in r0
.
addcc %r1, %r2, %r3
Sums the values of r1
and r2
in r3
.
andcc %r1, %r2, %r3
Bitwise AND between r1
and r2
, storing the result in r3
.
andncc %r1, %r2, %r3
Bitwise NOT AND between r1
and r2
, storing the result in r3
.
orcc %r1, %r2, %r3
Bitwise OR between r1
and r2
, storing the result in r3
.
orncc %r1, %r2, %r3
Bitwise NOR between r1
and r2
, storing the result in r3
.
xorcc %r1, %r2, %r3
Bitwise XOR between r1
and r2
, storing the result in r3
.
ld [x], %r1
Load value from x
address into r1
.
ld %r1, [x]
Stores r1
value into x
address.
printn %r1
Prints in console the decimal number from %r1
.
printc %r1
Prints in console the character from %r1
.
.begin
Start assembling.
.end
Stop assembling.
.org 2048
Changes location counter to 2048
.
Have an idea? Found a bug? See how to contribute.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
-
Starring and sharing the projects you like π
-
βI love books! I will remember you after years if you buy me one. π π
-
βYou can make one-time donations via PayPal. I'll probably buy a
coffeetea. π΅ -
βSet up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
-
BitcoinβYou can send me bitcoins at this address (or scanning the code below):
1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6
Thanks! β€οΈ
Back in 2014, I coded this during the Computer Architecture course by @HoreaOrosβone of my greatest computer-science teachers. βοΈ π°