cpprisc16  June 16, 2020
Typedefs | Functions | Variables
cpprisc16 Namespace Reference

Typedefs

typedef std::uint16_t immed_t
 Type for immediate value. More...
 
typedef std::uint16_t word16_t
 Type for register and memory items. More...
 

Functions

void x_add32 (unsigned int a2, unsigned int a1, unsigned int b2, unsigned int b1, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3)
 R[a2]:R[a1] <– R[a2]:R[a1] + R[b2]:R[b1]. More...
 
void x_addc (unsigned int a, unsigned int b, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3)
 R[b]:R[a] <– R[a] + R[b]. More...
 
void x_and_to (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] & R[b]. More...
 
void x_inc32 (unsigned int a2, unsigned int a1)
 R[a2]:R[a1] <– R[a2]:R[a1] + 1. More...
 
void x_is_lower_to (unsigned int result, unsigned int a, unsigned int b, unsigned int tmp)
 R[result] <– (positive value) if a < b, 0 else. More...
 
void x_lshift (unsigned int a)
 R[a] <– R[a] << 1 (== R[a]*2) More...
 
void x_lshift_to (unsigned int result, unsigned int a)
 R[result] <– R[a] << 1 (== R[a]*2) More...
 
void x_lshift32 (unsigned int a2, unsigned int a1, unsigned int tmp)
 R[a2]:R[a1] <– (R[a2]:R[a1]) << 1 (== (R[a2]:R[a1])*2) More...
 
void x_lshift_8 (unsigned int a)
 R[a] <– R[a] << 8 (== R[a]*256) More...
 
void x_lshift_8_to (unsigned int result, unsigned int a)
 R[result] <– R[a] << 8 (== R[a]*256) More...
 
void x_lshift32_8 (unsigned int a2, unsigned int a1, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3)
 R[a2]:R[a1] <– (R[a2]:R[a1]) << 8 (== (R[a2]:R[a1])*256) More...
 
void x_mask0x8000 (unsigned int a, unsigned int tmp)
 R[a] <– R[a] & 0x8000 (== R[a] & 0b1000000000000000 == R[a] & 32768) More...
 
void x_mask0x8000_to (unsigned int result, unsigned int a)
 R[result] <– R[a] & 0x8000 (== R[a] & 0b1000000000000000 == R[a] & 32768) More...
 
void x_mov (unsigned int result, unsigned int a)
 R[result] <– R[a]. More...
 
void x_mul (unsigned int a, unsigned int b, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3, unsigned int tmp4, unsigned int tmp5)
 R[b]:R[a] <– R[a] * R[b] by standard algorithm: https://en.wikipedia.org/wiki/Multiplication_algorithm#Long_multiplication. More...
 
void x_mul_karatsuba (unsigned int a, unsigned int b, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3, unsigned int tmp4, unsigned int tmp5)
 R[b]:R[a] <– R[a] * R[b] by Karatsuba algorithm: https://en.wikipedia.org/wiki/Karatsuba_algorithm. More...
 
void x_mul8_to (unsigned int result, unsigned int a, unsigned int b, unsigned int tmp1, unsigned int tmp2)
 R[result] <– R[a] * R[b]. More...
 
void x_neg (unsigned int a)
 R[a] <– -R[a] (two's complement) More...
 
void x_not (unsigned int a)
 R[a] <– ~R[a]. More...
 
void x_not_to (unsigned int result, unsigned int a)
 R[result] <– ~R[a]. More...
 
void x_or_to (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] | R[b]. More...
 
void x_rshift_to (unsigned int result, unsigned int a, unsigned int tmp1, unsigned int tmp2)
 R[result] <– R[a] >> 1 (== R[a]/2) More...
 
void x_rshift_8_to (unsigned int result, unsigned int a, unsigned int tmp1, unsigned int tmp2)
 R[result] <– R[a] >> 8 (== R[a]/256) More...
 
void x_rshift_8_duo_to (unsigned int resulta, unsigned int a, unsigned int resultb, unsigned int b, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3)
 R[resulta] <– R[a] >> 8 (== R[a]/256) R[resultb] <– R[b] >> 8. More...
 
void x_rshift_8_signed_to (unsigned int result, unsigned int a, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3)
 R[result] <– R[a] >> 8 with extension of the sign. More...
 
void x_set0 (unsigned int a)
 R[a] <– 0. More...
 
void x_set0x8000 (unsigned int result)
 R[result] <– 0x8000 (== 0b1000000000000000 == 32768) More...
 
void x_sqr (unsigned int a, unsigned int result2, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3, unsigned int tmp4, unsigned int tmp5)
 R[result2]:R[a] <– R[a]*R[a]. More...
 
void x_sqr8_to (unsigned int result, unsigned int a, unsigned int tmp1, unsigned int tmp2, unsigned int tmp3)
 R[result] <– R[a] * R[a]. More...
 
void x_sub_from (unsigned int a, unsigned int b)
 R[a] <– -R[a] + R[b]. More...
 
void x_sub_to (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] - R[b]. More...
 
void x_swap (unsigned int a, unsigned int b, unsigned int tmp)
 R[a], R[b] <– R[b], R[a]. More...
 
bool is1_add (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] + R[b]. More...
 
void is1_nor (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] NOR R[b] (== ~(a | b)) More...
 
bool is1_sha (unsigned int result, unsigned int a, unsigned int b)
 (SHift Arithmetic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b]) More...
 
bool is1_shl (unsigned int result, unsigned int a, unsigned int b)
 (SHift Logic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b]) More...
 
void is1_shifti (unsigned int result, unsigned int a, immed_t immed7)
 (Shift Immediate) R[result] <– (R[a] << immed5) or (R[a] >> -immed5) More...
 
bool is1_sub (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] - R[b]. More...
 
void is1_xor (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] XOR R[b] (== ~(a ^ b)) More...
 
bool is2_add (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] + R[b]. More...
 
void is2_mul (unsigned int result, unsigned int a, unsigned int b)
 R[result - 1]:R[result] <– R[a]*R[b]. More...
 
void is2_nor (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] NOR R[b] (== ~(a | b)) More...
 
bool is2_sha (unsigned int result, unsigned int a, unsigned int b)
 (SHift Arithmetic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b]) More...
 
bool is2_shl (unsigned int result, unsigned int a, unsigned int b)
 (SHift Logic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b]) More...
 
void is2_shifti (unsigned int result, unsigned int a, immed_t immed7)
 (Shift Immediate) R[result] <– (R[a] << immed5) or (R[a] >> -immed5) More...
 
bool is2_sub (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] - R[b]. More...
 
void is2_xor (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] XOR R[b] (== ~(a ^ b)) More...
 
void i_add (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] + R[b]. More...
 
void i_addi (unsigned int result, unsigned int a, immed_t immed6)
 (ADD Immediate) R[result] <– R[a] + immed6 More...
 
void i_jalr (unsigned int result, unsigned int a)
 (Jump And Link using Register) In the real RiSC16: R[result] <– PC + 1 (where PC = Program Counter), PC <– R[a] (jump to R[a]) but impossible to implement that in this C++ library. More...
 
void i_lui (unsigned int result, immed_t immed10)
 (Load Upper Immediate) R[result] <– immed10 << 6 More...
 
void i_lw (unsigned int result, unsigned int a, immed_t immed6)
 (Load Word) R[result] <– Memory[R[a] + immed6] More...
 
void i_nand (unsigned int result, unsigned int a, unsigned int b)
 R[result] <– R[a] NAND R[b] (== ~(a & b)) More...
 
void i_sw (unsigned int a, unsigned int result, immed_t immed6)
 (Store Word) Memory[R[result] + immed6] <– R[a] More...
 
void p_halt (bool print=true)
 If print then call println_all() More...
 
void p_movi (unsigned int result, immed_t immed)
 (MOV Immediate) R[result] <– immed More...
 
void p_nop ()
 Do nothing. More...
 
void p_reset ()
 In the real RiSC16: R[result] <– PC + 1 (where PC = Program Counter), PC <– 0 (jump to 0) but impossible to implement that in this C++ library. More...
 
void clear_memory ()
 Reset to 0 all memory items and mark them as not used. More...
 
void clear_nb_executed ()
 Reset the number of executed instructions. More...
 
void clear_registers ()
 Reset to 0 all registers. More...
 
void print_mem (unsigned int i)
 Print ith memory item M[i] (without newline). More...
 
void print_reg (unsigned int a)
 Print the register R[a] (without newline). More...
 
void print_reg2 (unsigned int a2, unsigned int a1)
 Print the 32 bits value of R[a2]:R[a1] (without newline). More...
 
void print_value16 (std::uint16_t n)
 Print to stdout the 16 bits value n: hexadecimal representation = binary = decimal = signed decimal (without newline). More...
 
void print_value32 (std::uint32_t n)
 Print to stdout the 32 bits value n: hexadecimal representation = binary = decimal = signed decimal (without newline). More...
 
void println_all ()
 Print infos, registers and memory (if used). More...
 
void println_infos ()
 Print to stdout the number of executed instructions. More...
 
void println_mem (unsigned int i)
 Print ith memory item M[i]. More...
 
void println_memory (unsigned int size=0)
 Print memory items. More...
 
void println_reg (unsigned int a)
 Print the register R[a]. More...
 
void println_reg2 (unsigned int a2, unsigned int a1)
 Print the 32 bits value of R[a2]:R[a1]. More...
 
void println_registers ()
 Print all registers items. More...
 
void println_value16 (std::uint16_t n)
 Print to stdout the 16 bits value n: hexadecimal representation = binary = decimal = signed decimal. More...
 
void println_value32 (std::uint32_t n)
 Print to stdout the 32 bits value n: hexadecimal representation = binary = decimal = signed decimal. More...
 

Variables

const unsigned int nb_registers = 8
 Number of registers: 8 word16_t items. More...
 
const unsigned int size_memory = 256
 Size of the memory: 256 word16_t items. More...
 
unsigned int after_last_memory_acceded = 0
 Index following the last memory item used. More...
 
word16_t memory [256]
 Memory items. More...
 
uint64_t nb_executed = 0
 Number of instructions executed. More...
 
word16_t registers [8] = {0}
 Registers. More...
 

Typedef Documentation

◆ immed_t

typedef std::uint16_t cpprisc16::immed_t

Type for immediate value.

Definition at line 48 of file cpprisc16.hpp.

◆ word16_t

typedef std::uint16_t cpprisc16::word16_t

Type for register and memory items.

Definition at line 54 of file cpprisc16.hpp.

Function Documentation

◆ clear_memory()

void cpprisc16::clear_memory ( )

Reset to 0 all memory items and mark them as not used.

Definition at line 191 of file cpprisc16.cpp.

◆ clear_nb_executed()

void cpprisc16::clear_nb_executed ( )

Reset the number of executed instructions.

Definition at line 200 of file cpprisc16.cpp.

◆ clear_registers()

void cpprisc16::clear_registers ( )

Reset to 0 all registers.

Definition at line 206 of file cpprisc16.cpp.

◆ i_add()

void cpprisc16::i_add ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] + R[b].

Count for 1 instruction.

Definition at line 51 of file cpprisc16.cpp.

◆ i_addi()

void cpprisc16::i_addi ( unsigned int  result,
unsigned int  a,
immed_t  immed6 
)

(ADD Immediate) R[result] <– R[a] + immed6

Parameters
result
a
immed6<= 0x3F (== 0b111111 == 63) (size of 6 bits)

FIXME! In fact must be immediate 7-bit signed value (-64 to 63)

Count for 1 instruction.

Definition at line 64 of file cpprisc16.cpp.

◆ i_jalr()

void cpprisc16::i_jalr ( unsigned int  result,
unsigned int  a 
)

(Jump And Link using Register) In the real RiSC16: R[result] <– PC + 1 (where PC = Program Counter), PC <– R[a] (jump to R[a]) but impossible to implement that in this C++ library.

Count for 1 instruction.

Warning
Not implemented!
Parameters
result
a

Definition at line 77 of file cpprisc16.cpp.

◆ i_lui()

void cpprisc16::i_lui ( unsigned int  result,
immed_t  immed10 
)

(Load Upper Immediate) R[result] <– immed10 << 6

Count for 1 instruction.

Parameters
result
immed10<= 0x3FF (== 0b1111111111 == 1023) (size of 10 bits)

Definition at line 91 of file cpprisc16.cpp.

◆ i_lw()

void cpprisc16::i_lw ( unsigned int  result,
unsigned int  a,
immed_t  immed6 
)

(Load Word) R[result] <– Memory[R[a] + immed6]

Count for 1 instruction.

Parameters
result
a
immed6<= 0x3F (== 0b111111 == 63) (size of 6 bits)

FIXME! In fact must be immediate 7-bit signed value (-64 to 63)

Definition at line 103 of file cpprisc16.cpp.

◆ i_nand()

void cpprisc16::i_nand ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] NAND R[b] (== ~(a & b))

Count for 1 instruction.

Definition at line 120 of file cpprisc16.cpp.

◆ i_sw()

void cpprisc16::i_sw ( unsigned int  a,
unsigned int  result,
immed_t  immed6 
)

(Store Word) Memory[R[result] + immed6] <– R[a]

Count for 1 instruction.

Parameters
a
result
immed6<= 0x3F (== 0b111111 == 63) (size of 6 bits)

FIXME! In fact must be immediate 7-bit signed value (-64 to 63)

Definition at line 133 of file cpprisc16.cpp.

◆ is1_add()

bool cpprisc16::is1_add ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] + R[b].

See macro is1_add_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 22 of file cppis1.cpp.

◆ is1_nor()

void cpprisc16::is1_nor ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] NOR R[b] (== ~(a | b))

Count for 1 instruction.

Definition at line 42 of file cppis1.cpp.

◆ is1_sha()

bool cpprisc16::is1_sha ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

(SHift Arithmetic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])

If R[b] >= 0 then shift to the left, else shift to the right with duplication of the sign bit.

See macro is1_sha_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 55 of file cppis1.cpp.

◆ is1_shifti()

void cpprisc16::is1_shifti ( unsigned int  result,
unsigned int  a,
immed_t  immed7 
)

(Shift Immediate) R[result] <– (R[a] << immed5) or (R[a] >> -immed5)

6 5 43210 immed7 is decomposed in x:M:immed5 where: x is 1 bit unused M is 1 bit: 0 for logic mode, 1 for arithmetic mode immed5 is 5 signed bits

If immed5 >= 0 then shift to the left, else shift to the right (with duplication of the sign bit if arithmetic mode).

Count for 1 instruction.

Definition at line 131 of file cppis1.cpp.

◆ is1_shl()

bool cpprisc16::is1_shl ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

(SHift Logic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])

If R[b] >= 0 then shift to the left, else shift to the right.

See macro is1_shl_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 93 of file cppis1.cpp.

◆ is1_sub()

bool cpprisc16::is1_sub ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] - R[b].

See macro is1_sub_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 170 of file cppis1.cpp.

◆ is1_xor()

void cpprisc16::is1_xor ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] XOR R[b] (== ~(a ^ b))

Count for 1 instruction.

Definition at line 188 of file cppis1.cpp.

◆ is2_add()

bool cpprisc16::is2_add ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] + R[b].

See macro is2_add_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 24 of file cppis2.cpp.

◆ is2_mul()

void cpprisc16::is2_mul ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result - 1]:R[result] <– R[a]*R[b].

Count for 1 instruction.

Parameters
result>= 1
a
b

Definition at line 34 of file cppis2.cpp.

◆ is2_nor()

void cpprisc16::is2_nor ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] NOR R[b] (== ~(a | b))

Count for 1 instruction.

Definition at line 53 of file cppis2.cpp.

◆ is2_sha()

bool cpprisc16::is2_sha ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

(SHift Arithmetic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])

If R[b] >= 0 then shift to the left, else shift to the right with duplication of the sign bit.

See macro is2_sha_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 63 of file cppis2.cpp.

◆ is2_shifti()

void cpprisc16::is2_shifti ( unsigned int  result,
unsigned int  a,
immed_t  immed7 
)

(Shift Immediate) R[result] <– (R[a] << immed5) or (R[a] >> -immed5)

6 5 43210 immed7 is decomposed in x:M:immed5 where: x is 1 bit unused M is 1 bit: 0 for logic mode, 1 for arithmetic mode immed5 is 5 signed bits

If immed5 >= 0 then shift to the left, else shift to the right (with duplication of the sign bit if arithmetic mode).

Count for 1 instruction.

Definition at line 83 of file cppis2.cpp.

◆ is2_shl()

bool cpprisc16::is2_shl ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

(SHift Logic) R[result] <– (R[a] << R[b]) or (R[a] >> -R[b])

If R[b] >= 0 then shift to the left, else shift to the right.

See macro is2_shl_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 73 of file cppis2.cpp.

◆ is2_sub()

bool cpprisc16::is2_sub ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] - R[b].

See macro is2_sub_bo() for jump if overflow.

Count for 1 instruction.

Returns
true iff overflow

Definition at line 93 of file cppis2.cpp.

◆ is2_xor()

void cpprisc16::is2_xor ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] XOR R[b] (== ~(a ^ b))

Count for 1 instruction.

Definition at line 103 of file cppis2.cpp.

◆ p_halt()

void cpprisc16::p_halt ( bool  print = true)

If print then call println_all()

Stop the program.

Count for 1 instruction.

Definition at line 154 of file cpprisc16.cpp.

◆ p_movi()

void cpprisc16::p_movi ( unsigned int  result,
immed_t  immed 
)

(MOV Immediate) R[result] <– immed

Pseudo-instruction for i_lui(result, immed10); i_addi(result, result, immed6); with immed = immed10:immed6, immed10 = immed >> 6, immed6 = immed & 0x3F.

Count for 2 instructions.

Definition at line 166 of file cpprisc16.cpp.

◆ p_nop()

void cpprisc16::p_nop ( )

Do nothing.

Pseudo-instruction for i_add(0, 0, 0);

Count for 1 instruction.

Definition at line 175 of file cpprisc16.cpp.

◆ p_reset()

void cpprisc16::p_reset ( )

In the real RiSC16: R[result] <– PC + 1 (where PC = Program Counter), PC <– 0 (jump to 0) but impossible to implement that in this C++ library.

Pseudo-instruction for i_jalr(0, 0);

Count for 1 instruction.

Warning
Not implemented!

Definition at line 181 of file cpprisc16.cpp.

◆ print_mem()

void cpprisc16::print_mem ( unsigned int  i)

Print ith memory item M[i] (without newline).

Definition at line 215 of file cpprisc16.cpp.

◆ print_reg()

void cpprisc16::print_reg ( unsigned int  a)

Print the register R[a] (without newline).

Definition at line 220 of file cpprisc16.cpp.

◆ print_reg2()

void cpprisc16::print_reg2 ( unsigned int  a2,
unsigned int  a1 
)

Print the 32 bits value of R[a2]:R[a1] (without newline).

Definition at line 229 of file cpprisc16.cpp.

◆ print_value16()

void cpprisc16::print_value16 ( std::uint16_t  n)

Print to stdout the 16 bits value n: hexadecimal representation = binary = decimal = signed decimal (without newline).

Definition at line 240 of file cpprisc16.cpp.

◆ print_value32()

void cpprisc16::print_value32 ( std::uint32_t  n)

Print to stdout the 32 bits value n: hexadecimal representation = binary = decimal = signed decimal (without newline).

Definition at line 250 of file cpprisc16.cpp.

◆ println_all()

void cpprisc16::println_all ( )

Print infos, registers and memory (if used).

Definition at line 260 of file cpprisc16.cpp.

◆ println_infos()

void cpprisc16::println_infos ( )

Print to stdout the number of executed instructions.

Definition at line 271 of file cpprisc16.cpp.

◆ println_mem()

void cpprisc16::println_mem ( unsigned int  i)

Print ith memory item M[i].

Definition at line 277 of file cpprisc16.cpp.

◆ println_memory()

void cpprisc16::println_memory ( unsigned int  size = 0)

Print memory items.

If size == 0 then print all items until last item used, else print size first items.

Definition at line 284 of file cpprisc16.cpp.

◆ println_reg()

void cpprisc16::println_reg ( unsigned int  a)

Print the register R[a].

Definition at line 294 of file cpprisc16.cpp.

◆ println_reg2()

void cpprisc16::println_reg2 ( unsigned int  a2,
unsigned int  a1 
)

Print the 32 bits value of R[a2]:R[a1].

Definition at line 303 of file cpprisc16.cpp.

◆ println_registers()

void cpprisc16::println_registers ( )

Print all registers items.

Definition at line 313 of file cpprisc16.cpp.

◆ println_value16()

void cpprisc16::println_value16 ( std::uint16_t  n)

Print to stdout the 16 bits value n: hexadecimal representation = binary = decimal = signed decimal.

Definition at line 321 of file cpprisc16.cpp.

◆ println_value32()

void cpprisc16::println_value32 ( std::uint32_t  n)

Print to stdout the 32 bits value n: hexadecimal representation = binary = decimal = signed decimal.

Definition at line 328 of file cpprisc16.cpp.

◆ x_add32()

void cpprisc16::x_add32 ( unsigned int  a2,
unsigned int  a1,
unsigned int  b2,
unsigned int  b1,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3 
)

R[a2]:R[a1] <– R[a2]:R[a1] + R[b2]:R[b1].

a2, a1, b2, b1, tmp1, tmp2, tmp3 must be different

Definition at line 20 of file cppextendedrisc16.cpp.

◆ x_addc()

void cpprisc16::x_addc ( unsigned int  a,
unsigned int  b,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3 
)

R[b]:R[a] <– R[a] + R[b].

a, b, tmp1, tmp2, tmp3 must be different

Definition at line 55 of file cppextendedrisc16.cpp.

◆ x_and_to()

void cpprisc16::x_and_to ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] & R[b].

Definition at line 104 of file cppextendedrisc16.cpp.

◆ x_inc32()

void cpprisc16::x_inc32 ( unsigned int  a2,
unsigned int  a1 
)

R[a2]:R[a1] <– R[a2]:R[a1] + 1.

a2, a1 must be different

Definition at line 120 of file cppextendedrisc16.cpp.

◆ x_is_lower_to()

void cpprisc16::x_is_lower_to ( unsigned int  result,
unsigned int  a,
unsigned int  b,
unsigned int  tmp 
)

R[result] <– (positive value) if a < b, 0 else.

Definition at line 140 of file cppextendedrisc16.cpp.

◆ x_lshift()

void cpprisc16::x_lshift ( unsigned int  a)

R[a] <– R[a] << 1 (== R[a]*2)

Definition at line 185 of file cppextendedrisc16.cpp.

◆ x_lshift32()

void cpprisc16::x_lshift32 ( unsigned int  a2,
unsigned int  a1,
unsigned int  tmp 
)

R[a2]:R[a1] <– (R[a2]:R[a1]) << 1 (== (R[a2]:R[a1])*2)

a1, a2, tmp must be different

Definition at line 206 of file cppextendedrisc16.cpp.

◆ x_lshift32_8()

void cpprisc16::x_lshift32_8 ( unsigned int  a2,
unsigned int  a1,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3 
)

R[a2]:R[a1] <– (R[a2]:R[a1]) << 8 (== (R[a2]:R[a1])*256)

a1, a2, tmp1, tmp2, tmp3 must be different

Definition at line 276 of file cppextendedrisc16.cpp.

◆ x_lshift_8()

void cpprisc16::x_lshift_8 ( unsigned int  a)

R[a] <– R[a] << 8 (== R[a]*256)

Definition at line 235 of file cppextendedrisc16.cpp.

◆ x_lshift_8_to()

void cpprisc16::x_lshift_8_to ( unsigned int  result,
unsigned int  a 
)

R[result] <– R[a] << 8 (== R[a]*256)

Definition at line 254 of file cppextendedrisc16.cpp.

◆ x_lshift_to()

void cpprisc16::x_lshift_to ( unsigned int  result,
unsigned int  a 
)

R[result] <– R[a] << 1 (== R[a]*2)

Definition at line 194 of file cppextendedrisc16.cpp.

◆ x_mask0x8000()

void cpprisc16::x_mask0x8000 ( unsigned int  a,
unsigned int  tmp 
)

R[a] <– R[a] & 0x8000 (== R[a] & 0b1000000000000000 == R[a] & 32768)

If (MSB of R[a]) == 1 then the result is 0x8000, else the result is 0.

Parameters
a!= tmp
tmp

Definition at line 305 of file cppextendedrisc16.cpp.

◆ x_mask0x8000_to()

void cpprisc16::x_mask0x8000_to ( unsigned int  result,
unsigned int  a 
)

R[result] <– R[a] & 0x8000 (== R[a] & 0b1000000000000000 == R[a] & 32768)

If (MSB of R[a]) == 1 then the result is 0x8000, else the result is 0.

result, a must be different

Definition at line 321 of file cppextendedrisc16.cpp.

◆ x_mov()

void cpprisc16::x_mov ( unsigned int  result,
unsigned int  a 
)

R[result] <– R[a].

Definition at line 336 of file cppextendedrisc16.cpp.

◆ x_mul()

void cpprisc16::x_mul ( unsigned int  a,
unsigned int  b,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3,
unsigned int  tmp4,
unsigned int  tmp5 
)

R[b]:R[a] <– R[a] * R[b] by standard algorithm: https://en.wikipedia.org/wiki/Multiplication_algorithm#Long_multiplication.

a, b, tmp1, tmp2, tmp3, tmp4, tmp5 must be different

Side effect: Use memory 0x0 to 0x3 (included) to save temporary work.

Definition at line 348 of file cppextendedrisc16.cpp.

◆ x_mul8_to()

void cpprisc16::x_mul8_to ( unsigned int  result,
unsigned int  a,
unsigned int  b,
unsigned int  tmp1,
unsigned int  tmp2 
)

R[result] <– R[a] * R[b].

result, a, b, tmp1, tmp2 must be different

Parameters
result
aR[a] <= 0xFF (== 0b11111111 == 255)
bR[b] <= 0xFF
tmp1
tmp2

Definition at line 572 of file cppextendedrisc16.cpp.

◆ x_mul_karatsuba()

void cpprisc16::x_mul_karatsuba ( unsigned int  a,
unsigned int  b,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3,
unsigned int  tmp4,
unsigned int  tmp5 
)

R[b]:R[a] <– R[a] * R[b] by Karatsuba algorithm: https://en.wikipedia.org/wiki/Karatsuba_algorithm.

a, b, tmp1, tmp2, tmp3, tmp4, tmp5 must be different

Side effect: Use memory 0x0 to 0x5 (included) to save temporary work.

Definition at line 448 of file cppextendedrisc16.cpp.

◆ x_neg()

void cpprisc16::x_neg ( unsigned int  a)

R[a] <– -R[a] (two's complement)

Definition at line 615 of file cppextendedrisc16.cpp.

◆ x_not()

void cpprisc16::x_not ( unsigned int  a)

R[a] <– ~R[a].

Definition at line 625 of file cppextendedrisc16.cpp.

◆ x_not_to()

void cpprisc16::x_not_to ( unsigned int  result,
unsigned int  a 
)

R[result] <– ~R[a].

Definition at line 634 of file cppextendedrisc16.cpp.

◆ x_or_to()

void cpprisc16::x_or_to ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] | R[b].

Parameters
result
a!= 0 and != b
b!= 0

Definition at line 646 of file cppextendedrisc16.cpp.

◆ x_rshift_8_duo_to()

void cpprisc16::x_rshift_8_duo_to ( unsigned int  resulta,
unsigned int  a,
unsigned int  resultb,
unsigned int  b,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3 
)

R[resulta] <– R[a] >> 8 (== R[a]/256) R[resultb] <– R[b] >> 8.

resulta, a, resultb, b, tmp1, tmp2, tmp3 must be different

Side effect: change R[tmp1], R[tmp2], R[tmp3]

Definition at line 830 of file cppextendedrisc16.cpp.

◆ x_rshift_8_signed_to()

void cpprisc16::x_rshift_8_signed_to ( unsigned int  result,
unsigned int  a,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3 
)

R[result] <– R[a] >> 8 with extension of the sign.

result, a, tmp1, tmp2, tmp3 must be different

Side effect: change R[tmp1], R[tmp2], R[tmp3]

Definition at line 1061 of file cppextendedrisc16.cpp.

◆ x_rshift_8_to()

void cpprisc16::x_rshift_8_to ( unsigned int  result,
unsigned int  a,
unsigned int  tmp1,
unsigned int  tmp2 
)

R[result] <– R[a] >> 8 (== R[a]/256)

result, a, tmp1, tmp2 must be different

Side effect: change R[tmp1], R[tmp2]

Definition at line 705 of file cppextendedrisc16.cpp.

◆ x_rshift_to()

void cpprisc16::x_rshift_to ( unsigned int  result,
unsigned int  a,
unsigned int  tmp1,
unsigned int  tmp2 
)

R[result] <– R[a] >> 1 (== R[a]/2)

result, a, tmp1, tmp2 must be different

Side effect: change R[a], R[tmp1], R[tmp2]

Definition at line 664 of file cppextendedrisc16.cpp.

◆ x_set0()

void cpprisc16::x_set0 ( unsigned int  result)

R[a] <– 0.

Definition at line 1094 of file cppextendedrisc16.cpp.

◆ x_set0x8000()

void cpprisc16::x_set0x8000 ( unsigned int  a)

R[result] <– 0x8000 (== 0b1000000000000000 == 32768)

Definition at line 1103 of file cppextendedrisc16.cpp.

◆ x_sqr()

void cpprisc16::x_sqr ( unsigned int  a,
unsigned int  result2,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3,
unsigned int  tmp4,
unsigned int  tmp5 
)

R[result2]:R[a] <– R[a]*R[a].

a, result2, tmp1, tmp2, tmp3, tmp4, tmp5 must be different

Side effect: Use memory 0x0 to 0x1 (included) to save temporary work.

Definition at line 1112 of file cppextendedrisc16.cpp.

◆ x_sqr8_to()

void cpprisc16::x_sqr8_to ( unsigned int  result,
unsigned int  a,
unsigned int  tmp1,
unsigned int  tmp2,
unsigned int  tmp3 
)

R[result] <– R[a] * R[a].

result, a, tmp1, tmp2, tmp3 must be different

Parameters
result
aR[a] <= 0xFF (== 0b11111111 == 255)
tmp1
tmp2
tmp3

Definition at line 1179 of file cppextendedrisc16.cpp.

◆ x_sub_from()

void cpprisc16::x_sub_from ( unsigned int  a,
unsigned int  b 
)

R[a] <– -R[a] + R[b].

Definition at line 1225 of file cppextendedrisc16.cpp.

◆ x_sub_to()

void cpprisc16::x_sub_to ( unsigned int  result,
unsigned int  a,
unsigned int  b 
)

R[result] <– R[a] - R[b].

Definition at line 1240 of file cppextendedrisc16.cpp.

◆ x_swap()

void cpprisc16::x_swap ( unsigned int  a,
unsigned int  b,
unsigned int  tmp 
)

R[a], R[b] <– R[b], R[a].

Definition at line 1258 of file cppextendedrisc16.cpp.

Variable Documentation

◆ after_last_memory_acceded

unsigned int cpprisc16::after_last_memory_acceded = 0

Index following the last memory item used.

Definition at line 37 of file cpprisc16.cpp.

◆ memory

word16_t cpprisc16::memory

Memory items.

Definition at line 39 of file cpprisc16.cpp.

◆ nb_executed

uint64_t cpprisc16::nb_executed = 0

Number of instructions executed.

Definition at line 41 of file cpprisc16.cpp.

◆ nb_registers

const unsigned int cpprisc16::nb_registers = 8

Number of registers: 8 word16_t items.

Definition at line 28 of file cpprisc16.cpp.

◆ registers

word16_t cpprisc16::registers = {0}

Registers.

Definition at line 43 of file cpprisc16.cpp.

◆ size_memory

const unsigned int cpprisc16::size_memory = 256

Size of the memory: 256 word16_t items.

Definition at line 30 of file cpprisc16.cpp.