Copper is a assembly interpreter. It It was created for educational purposes. It is a simple language with basic operations. It is a 32-bit architecture with 4 registers. It has a stack and 1024 addressable memory positions of 32 bits. It has a simple syntax and a simple instruction set making it easy to learn and use to get introduced to assembly.
git clone https://github.com/P4UL-M/Copper.git
cd Copper
cargo build
$env:Path += ";$pwd\target\debug"
export PATH="$PATH:$pwd/target/debug"
export PATH="$PATH:$pwd/target/debug"
cargo run \<filename\>
To utilize Copper, follow the command line syntax and available options.
copper <filename>
Options:
- -h, --help: Print this help message.
- -V, --version: Print version information.
- -v, --verbose: Enable verbose mode.
- -d, --debug: Enable debug mode.
Commands:
Run Program:
copper run <filename>
Execute the Copper program specified by .
Export Program:
copper export <filename> [<outputfile>]
Export the Copper program to a binary file. Optionally, you can specify an output file name. If no output file is provided, the default name is used.
Examples:
Run a Copper program:
copper program.co
Run a Copper program with verbose output:
copper -v run program.co
Export a Copper program to the default binary file:
copper export program.co
Export a Copper program to a specific binary file:
copper export program.co program.bin
Refer to the instruction sets below to find the specific functionalities and syntax of Copper.
Load register reg1 with the contents of either the contents of reg2, or the memory var or a constant const. Memory regions loads (load into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Store in the memory position referred by var the value of register reg or a constant const. Register stores (store into register t0, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 10 bits for the address of the variable
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for he constant or the address of the register No store from variable to variable allowed
Push to the top of the stack the contents of reg or var or a constant const.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Pop from the top of the stack and store the value on reg. Storing in a memory region is NOT ALLOWED.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs a logical AND operation between reg1 and a register reg2, a variable var or a constant const, and store the result on register reg1. Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs a logical OR operation between reg1 and a register reg2, a variable var or a constant const, and store the result on register reg1. Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs a logical NOT operation on register reg and store the result on register reg. Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
Performs the addition operation of reg1 and a register reg2, a variable var or a constant const, and store the result on register reg1. Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs the subtraction operation of reg1 and a register reg2, a variable var or a constant const, and store the result on register reg1. The operation is given by second argument minus the first argument (i.e., reg2 – reg1). Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs the integer division operation of reg1 and a register reg2, a variable var or a constant const, and store the result on register reg1. The operation is given by second argument divided by the first argument (i.e., reg2 / reg1). Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs the integer multiplication operation of reg1 and a register reg2, a variable var or a constant const, and store the result on register reg1. Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Performs the integer modulo operation of reg1 and a register reg2, a variable var or a constant cont, and store the result on register reg1. The operation is given by second argument modulo the first argument (i.e., reg2 mod reg1). Memory regions stores (store result into a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
Increments the value of a register reg. Memory increments (incrementing a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
Decrements the value of a register reg. Memory increments (decrementing a variable, for instance) are NOT ALLOWED.
- 5 bits for instruction
- 2 bits for the address of the register
Performs a comparison between two values, given by registers, variables or constants. Any combination is permitted. If they are equal, jump to the address defined by the label LABEL.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the register
- 12 bits for second parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
- 3 bits for the address of the jump
Performs a comparison between two values, given by registers, variables or constants. Any combination is permitted. If they are different, jump to the address defined by the label LABEL.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the register
- 12 bits for second parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
- 3 bits for the address of the jump
Performs a comparison between two values, given by registers, variables or constants. Any combination is permitted. If the first parameter is bigger than the second parameter, jump to the address defined by the label LABEL.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the register
- 12 bits for second parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
- 3 bits for the address of the jump
Performs a comparison between two values, given by registers, variables or constants. Any combination is permitted. If the first parameter is smaller than the second parameter, jump to the address defined by the label LABEL.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the register
- 12 bits for second parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the second register
- 3 bits for the address of the jump
Jump to the address defined by the label LABEL.
- 5 bits for instruction
- 3 bits for the address of the jump
This operation takes the value in reg and performs a logical shift left of the number of bits defined by the constant const. For instance, the value 0001 left shifted 1 time becomes.
- 5 bits for instruction
- 2 bits for the address of the register
- 10 bits for the constant
This operation takes the value in reg and performs a logical shift right of the number of bits defined by the constant const. For instance, the value 1000 right shifted 1 time becomes.
- 5 bits for instruction
- 2 bits for the address of the register
- 10 bits for the constant
End the program execution.
- 5 bits for instruction
This operation take a value of the input stream and assign it to the parameter.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the register
This operation take the value from the parameter such as a constant, a variable or a register and write it in the output stream.
- 5 bits for instruction
- 12 bits for parameter
- 2 bits for type of the parameter
- 10 bits for the address in the memory, the constant or the address of the register
This operation mark the destination of a jump or a conditional jump.
- 5 bits for instruction
- 3 bits for label name
- 5 bits for instruction
- 2 bits for category name
- 1 bits for data type
- 10 bits for variable name
- 10 bits for constant data
- 1 bits for data type
- 10 bits for array name
- 10 bits for array size
- 10 bits for constant data