arc-assembler

An ARC assembler written in Node.JS.

Usage no npm install needed!

<script type="module">
  import arcAssembler from 'https://cdn.skypack.dev/arc-assembler';
</script>

README

arc-assembler PayPal Version Downloads Get help on Codementor

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 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

:memo: 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.

:yum: How to contribute

Have an idea? Found a bug? See how to contribute.

:cake: Thanks

Back in 2014, I coded this during the Computer Architecture course by @HoreaOros–one of my greatest computer-science teachers. :sparkle: :cake:

:scroll: License

MIT © Ionică Bizău