cpprisc16  March 16, 2017
 All Namespaces Files Functions Variables Typedefs Macros
main.cpp
Go to the documentation of this file.
1 /* -*- coding: latin-1 -*- */
2 
3 /** \file main.cpp (March 14, 2017)
4  * \brief Simple example program.
5  *
6  * Piece of cpprisc16.
7  * https://bitbucket.org/OPiMedia/cpprisc16
8  *
9  * GPLv3 --- Copyright (C) 2017 Olivier Pirson
10  * http://www.opimedia.be/
11  */
12 
13 #include <cstdlib>
14 
15 #include "cpprisc16/cpprisc16.hpp"
17 
18 using namespace cpprisc16;
19 
20 
21 int
22 main() {
24  clear_memory();
25 
26  const word16_t a = 0x7FFF;
27  const word16_t b = 0x010F;
28 
29  p_movi(1, a);
30  p_movi(2, b);
31 
33 
34  x_mul(1, 2, 3, 4, 5, 6, 7);
35  println_all();
36 
37 
39  clear_memory();
40 
41  p_movi(1, a);
42  p_movi(2, b);
43 
45 
46  x_mul_karatsuba(1, 2, 3, 4, 5, 6, 7);
47  p_halt();
48 
49  return EXIT_SUCCESS;
50 }
void p_movi(unsigned int result, immed_t immed)
(MOV Immediate) R[result] <– immed
Definition: cpprisc16.cpp:166
void clear_memory()
Reset to 0 all memory items and mark them as not used.
Definition: cpprisc16.cpp:191
std::uint16_t word16_t
Type for register and memory items.
Definition: cpprisc16.hpp:54
int main()
Definition: main.cpp:22
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.
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_algorit...
Instructions set of RiSC16: 8 instructions i_* and 4 pseudo-instructions p_*.
void clear_registers()
Reset to 0 all registers.
Definition: cpprisc16.cpp:206
void p_halt(bool print)
If print then call println_all()
Definition: cpprisc16.cpp:154
void println_all()
Print infos, registers and memory (if used).
Definition: cpprisc16.cpp:260
void clear_nb_executed()
Reset the number of executed instructions.
Definition: cpprisc16.cpp:200
Extended instructions set: some extra operations x_* implemented with RiSC16.