MATLAB DESIGN HDL CODER RELEASE NOTES User's Guide Page 69

  • Download
  • Add to my manuals
  • Print
  • Page
    / 410
  • Table of contents
  • TROUBLESHOOTING
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 68
System Generator for DSP User Guide www.xilinx.com 69
UG640 (v 12.2) July 23, 2010
Compiling MATLAB into an FPGA
RPN Calculator
This example shows how to use the MCode block to model a RPN calculator which is a
stack machine. The block is synthesizable.
The following function models the RPN calculator.
function [q, active] = rpn_calc(d, rst, en)
d_nbits = xl_nbits(d);
% the first bit indicates whether it's a data or operator
is_oper = xl_slice(d, d_nbits-1, d_nbits-1)==1;
din = xl_force(xl_slice(d, d_nbits-2, 0), xlSigned, 0);
% the lower 3 bits are operator
op = xl_slice(d, 2, 0);
% acc the the A register
persistent acc, acc = xl_state(0, din);
% the stack is implemented with a RAM and
% an up-down counter
persistent mem, mem = xl_state(zeros(1, 64), din);
persistent acc_active, acc_active = xl_state(false, {xlBoolean});
persistent stack_active, stack_active = xl_state(false, ...
{xlBoolean});
stack_pt_prec = {xlUnsigned, 5, 0};
persistent stack_pt, stack_pt = xl_state(0, {xlUnsigned, 5, 0});
% when en is true, it's action
OP_ADD = 2;
OP_SUB = 3;
OP_MULT = 4;
OP_NEG = 5;
Page view 68
1 2 ... 64 65 66 67 68 69 70 71 72 73 74 ... 409 410

Comments to this Manuals

No comments