{"id":207,"date":"2014-10-28T21:12:07","date_gmt":"2014-10-29T05:12:07","guid":{"rendered":"http:\/\/www.beyond-circuits.com\/wordpress\/?p=207"},"modified":"2014-10-29T06:23:15","modified_gmt":"2014-10-29T14:23:15","slug":"dual-lifo-2","status":"publish","type":"post","link":"https:\/\/www.beyond-circuits.com\/wordpress\/2014\/10\/dual-lifo-2\/","title":{"rendered":"Dual LIFO"},"content":{"rendered":"\r\n<div class=\"article\"><div class=\"toc\"><p><b>Table of Contents<\/b><\/p><dl class=\"toc\"><dt><span class=\"section\"><a href=\"#idm477508516336\">1. Interface<\/a><\/span><\/dt><dd><dl><dt><span class=\"section\"><a href=\"#idm477507531056\">1.1. Module declaration<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507528112\">1.2. Stack ports<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#sect.parameters\">1.3. Parameters<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507509856\">1.4. Definitions<\/a><\/span><\/dt><\/dl><\/dd><dt><span class=\"section\"><a href=\"#idm477507505136\">2. Functions<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507502352\">3. Logic common to all implementations<\/a><\/span><\/dt><dd><dl><dt><span class=\"section\"><a href=\"#idm477507501712\">3.1. Determine read and write signals<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507498096\">3.2. Determine count value for stack A<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507494848\">3.3. Determine count value for stack B<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507492656\">3.4. Generate empty<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507490336\">3.5. Generate full<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507487472\">3.6. Conditionally generate the full logic<\/a><\/span><\/dt><\/dl><\/dd><dt><span class=\"section\"><a href=\"#idm477507484032\">4. BRAM implementation<\/a><\/span><\/dt><dd><dl><dt><span class=\"section\"><a href=\"#idm477507483008\">4.1. The data memory<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507481600\">4.2. Maintain address pointers<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507476976\">4.3. Top-of-stack<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507470320\">4.4. Perform memory reads<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507467776\">4.5. Perform memory writes<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507465712\">4.6. BRAM implementation body<\/a><\/span><\/dt><\/dl><\/dd><dt><span class=\"section\"><a href=\"#idm477507460720\">5. Shift register implementation<\/a><\/span><\/dt><dd><dl><dt><span class=\"section\"><a href=\"#idm477507460080\">5.1. Shift register implementation of stack A<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507449168\">5.2. Shift register implementation of stack B<\/a><\/span><\/dt><\/dl><\/dd><dt><span class=\"section\"><a href=\"#idm477507444032\">6. Undefined implementation<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507442496\">7. The main module<\/a><\/span><\/dt><dt><span class=\"appendix\"><a href=\"#idm477507433840\">A. Front matter<\/a><\/span><\/dt><dd><dl><dt><span class=\"section\"><a href=\"#idm477507433200\">1. Header<\/a><\/span><\/dt><dt><span class=\"section\"><a href=\"#idm477507431312\">2. Copyright<\/a><\/span><\/dt><\/dl><\/dd><dt><span class=\"appendix\"><a href=\"#idm477507429776\">B. Downloads<\/a><\/span><\/dt><\/dl><\/div><p>\r\n    The <code class=\"literal\">lifo2<\/code> module implements a dual Last In First\r\n    Out stack data structure. The two stack structures share a single\r\n    block RAM, or may optionally be constructed from shift registers.\r\n\r\n    This module forms the heart of a stack based micro-controller. One\r\n    of the stacks is used as a data stack while the other is used as a\r\n    subroutine call stack. By implementing these in a single BRAM we\r\n    can save a lot of space.\r\n  <\/p><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477508516336\"><\/a>1.\u00a0Interface<\/h2><\/div><\/div><\/div><p>\r\n      The module interface consists of a clock and reset signal, and a\r\n      control interface for each stack. \r\n    <\/p><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507531056\"><\/a>1.1.\u00a0Module declaration<\/h3><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"module.declaration\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a71.1.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\nmodule lifo2\r\n  <a class=\"fragref\" href=\"#module.parameters\" title=\"Parameters\"><i>\u00a71.3.1. Parameters<\/i><\/a>\r\n  (\r\n   input clk,\r\n   input reset,\r\n   <a class=\"fragref\" href=\"#port.a.pins\" title=\"Stack port A\"><i>\u00a71.2.1.1. Stack port A<\/i><\/a>,\r\n   <a class=\"fragref\" href=\"#port.b.pins\" title=\"Stack port B\"><i>\u00a71.2.2.1. Stack port B<\/i><\/a>\r\n   );\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507528112\"><\/a>1.2.\u00a0Stack ports<\/h3><\/div><\/div><\/div><p>\r\n\tThe two ports use the suffix <code class=\"literal\">a<\/code> and\r\n\t<code class=\"literal\">b<\/code> to distinguish interface signals.\r\n\r\n\tA <em class=\"replaceable\"><code>push<\/code><\/em> input indicates that data from the\r\n\t<em class=\"replaceable\"><code>push_data<\/code><\/em> input should be pushed onto the stack.\r\n\r\n\tA <em class=\"replaceable\"><code>pop<\/code><\/em> input indicates that data should be\r\n\tpopped from the stack. Popped data should be read from the\r\n\t<em class=\"replaceable\"><code>tos<\/code><\/em> output during the same cycle that\r\n\t<em class=\"replaceable\"><code>pop<\/code><\/em> is valid.\r\n\r\n\tIt is completely normal to push and pop data on the same clock\r\n\tcycle.\r\n      <\/p><p>\r\n\tStatus signals <em class=\"replaceable\"><code>empty<\/code><\/em> and\r\n\t<em class=\"replaceable\"><code>full<\/code><\/em> indicate if the stack is empty or full.\r\n\r\n\tThe <em class=\"replaceable\"><code>count<\/code><\/em> output provides the number of valid\r\n\tentries currently on the stack.\r\n      <\/p><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507522608\"><\/a>1.2.1.\u00a0Stack port A<\/h4><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"port.a.pins\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a71.2.1.1<\/b>: <a href=\"#\">\u00a71.1.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n   input push_a,\r\n   input pop_a,\r\n   output reg empty_a,\r\n   output reg full_a,\r\n   output reg `CNT_T count_a,\r\n   output `DATA_T tos_a,\r\n   input `DATA_T push_data_a\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507521024\"><\/a>1.2.2.\u00a0Stack port B<\/h4><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"port.b.pins\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a71.2.2.1<\/b>: <a href=\"#\">\u00a71.1.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n   input push_b,\r\n   input pop_b,\r\n   output reg empty_b,\r\n   output reg full_b,\r\n   output reg `CNT_T count_b,\r\n   output `DATA_T tos_b,\r\n   input `DATA_T push_data_b\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"sect.parameters\"><\/a>1.3.\u00a0Parameters<\/h3><\/div><\/div><\/div><p>\r\n\tA <em class=\"parameter\"><code>depth<\/code><\/em> parameter specifies the depth\r\n\tfor each of the stacks. \r\n\r\n\tFor the BRAM implementation, the size of the RAM is just the\r\n\tsum of the two <em class=\"parameter\"><code>depth<\/code><\/em> parameters.\r\n\r\n\tFor the shift register implementation each stack uses its\r\n\t<em class=\"parameter\"><code>depth<\/code><\/em> parameter independently.\r\n\r\n\tThe <em class=\"parameter\"><code>width<\/code><\/em> parameter specifies the data\r\n\twidth. This is the same for both stacks.\r\n      <\/p><p>\r\n\tThe <em class=\"parameter\"><code>implementation<\/code><\/em> parameter may be set\r\n\tto <code class=\"literal\">\"BRAM\"<\/code> or <code class=\"literal\">\"SRL\"<\/code> to\r\n\tselect between BRAM and shift register implementations. Note\r\n\tthat the quotes are required.\r\n      <\/p><p>\r\n\tThe <em class=\"parameter\"><code>full_checking<\/code><\/em> specifies whether the\r\n\tlogic that generates the <em class=\"replaceable\"><code>full<\/code><\/em> outputs should\r\n\tbe generated.\r\n\r\n\tIn the case of the shift register implementation the concept\r\n\tof full is easy to implement and sensible. With this\r\n\timplementation, there really are two independent stacks.\r\n\r\n\tHowever, with the BRAM implementation the concept of full is a\r\n\tlittle harder to pin down. Is the stack full when the number\r\n\tof elements is equal to its <em class=\"parameter\"><code>depth<\/code><\/em>\r\n\tparameter? This seems overly restrictive since there may still\r\n\tbe plenty of room for it to grow. But if it does grow then it\r\n\tdoes so at the expense of the other stack.\r\n\r\n\tThere is a further difficulty if both stacks are almost\r\n\tfull. If you push to both stacks then you will overflow one of\r\n\tthe stacks. Which one? The one that is already over its posted\r\n\tlimit? The logic to implement this seems needlessly complex.\r\n\r\n\tSo the compromise here is to implement the strict full\r\n\tchecking for the BRAM implementation when the\r\n\t<em class=\"parameter\"><code>full_checking<\/code><\/em> parameter is true and to\r\n\tnot generate any full checking logic at all if it is false.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"module.parameters\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a71.3.1<\/b>: <a href=\"#\">\u00a71.1.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  #(\r\n    parameter depth_a = 512,\r\n    parameter depth_b = 512,\r\n    parameter width = 32,\r\n    parameter implementation = \"SRL\",\r\n    parameter full_checking = 0,\r\n    parameter depth = depth_a+depth_b\r\n    )\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507509856\"><\/a>1.4.\u00a0Definitions<\/h3><\/div><\/div><\/div><p>\r\n\tHere are some definitions that we can make use of\r\n\tlater. <code class=\"literal\">DATA_T<\/code> is used for data\r\n\tvalues. <code class=\"literal\">PTR_T<\/code> is used for pointers like the\r\n\ttop of stack pointer. The <code class=\"literal\">CNT_T<\/code> definition\r\n\tis suitable for holding a count. Note that this value needs to\r\n\thold a value of 0 as well as a value of\r\n\t<em class=\"parameter\"><code>depth<\/code><\/em> so it may be larger than the\r\n\t<code class=\"literal\">PTR_T<\/code> value.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"type.definitions\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a71.4.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n`define DATA_T [width-1:0]\r\n`define PTR_T [log2(depth)-1:0]\r\n`define CNT_T [log2(depth+1)-1:0]\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507505136\"><\/a>2.\u00a0Functions<\/h2><\/div><\/div><\/div><p>\r\n      The <code class=\"function\">log2<\/code> function computes the log base 2\r\n      of its input value. This function is used to computer widths of\r\n      pointer and count values.\r\n    <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"log2.function\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a72.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n   function integer log2;\r\n      input [31:0] value;\r\n      begin\r\n\t value = value-1;\r\n\t for (log2=0; value&gt;0; log2=log2+1)\r\n\t   value = value&gt;&gt;1;\r\n      end\r\n   endfunction\r\n    <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507502352\"><\/a>3.\u00a0Logic common to all implementations<\/h2><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507501712\"><\/a>3.1.\u00a0Determine read and write signals<\/h3><\/div><\/div><\/div><p>\r\n\tThe <em class=\"replaceable\"><code>writing<\/code><\/em> signals indicate that we are\r\n\twriting to the corresponding stack. This occurs when the push\r\n\tsignal is asserted and there is space on the stack or if the\r\n\tpush signal is asserted and a pop is asserted as well. In this\r\n\tcase we can perform the operation even though the stack is\r\n\tfull.\r\n      <\/p><p>\r\n\tThe <em class=\"replaceable\"><code>reading<\/code><\/em> signal indicates that\r\n\twe are reading from the corresponding stack. It is just the\r\n\tpop signal qualified with not empty.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"generate.reading.and.writing.signals\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a73.1.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  wire writing_a = push_a &amp;&amp; (!full_a || pop_a);\r\n  wire writing_b = push_b &amp;&amp; (!full_b || pop_b);\r\n  wire reading_a = pop_a &amp;&amp; !empty_a;\r\n  wire reading_b = pop_b &amp;&amp; ! empty_b;\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507498096\"><\/a>3.2.\u00a0Determine count value for stack A<\/h3><\/div><\/div><\/div><p>\r\n\tWe first generate the <em class=\"replaceable\"><code>next_count_a<\/code><\/em>\r\n\tvalue. Incrementing if we are writing but not reading,\r\n\tdecrementing if we are reading and not writing and leaving the\r\n\tcount the same if we are both reading and writing or neither\r\n\treading or writing.\r\n\r\n\tWe use a separate combinational always block to generate a\r\n\tnext value signal <em class=\"replaceable\"><code>next_count_a<\/code><\/em>. This signal\r\n\tis used by later code to determine empty and full conditions.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"generate.count.for.stack.a\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a73.2.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  reg `CNT_T next_count_a;\r\n  always @(*)\r\n    if (writing_a &amp;&amp; !reading_a)\r\n      next_count_a = count_a + 1;\r\n    else if (reading_a &amp;&amp; !writing_a)\r\n      next_count_a = count_a - 1;\r\n    else\r\n      next_count_a = count_a;\r\n\r\n  always @(posedge clk)\r\n    if (reset)\r\n      count_a &lt;= 0;\r\n    else\r\n      count_a &lt;= next_count_a;\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507494848\"><\/a>3.3.\u00a0Determine count value for stack B<\/h3><\/div><\/div><\/div><p>\r\n\tHere we generate the count values for stack B.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"generate.count.for.stack.b\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a73.3.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  reg `CNT_T next_count_b;\r\n  always @(*)\r\n    if (writing_b &amp;&amp; !reading_b)\r\n      next_count_b = count_b + 1;\r\n    else if (reading_b &amp;&amp; !writing_b)\r\n      next_count_b = count_b - 1;\r\n    else\r\n      next_count_b = count_b;\r\n  \r\n  always @(posedge clk)\r\n    if (reset)\r\n      count_a &lt;= 0;\r\n    else\r\n      count_b &lt;= next_count_b;\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507492656\"><\/a>3.4.\u00a0Generate empty<\/h3><\/div><\/div><\/div><p>\r\n\tHere we generate the logic for determining if either stack is\r\n\tempty. The stack is empty if on the next clock its count will\r\n\tbe zero.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"generate.empty\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a73.4.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  always @(posedge clk)\r\n    if (reset)\r\n      empty_a &lt;= 1;\r\n    else\r\n      empty_a &lt;= next_count_a == 0;\r\n\r\n  always @(posedge clk)\r\n    if (reset)\r\n      empty_b &lt;= 1;\r\n    else\r\n      empty_b &lt;= next_count_b == 0;\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507490336\"><\/a>3.5.\u00a0Generate full<\/h3><\/div><\/div><\/div><p>\r\n\tFull is pretty simple as well. We go full when the next count\r\n\tvalue will be equal to the <em class=\"parameter\"><code>depth<\/code><\/em>\r\n\tparameter of the stack. Writes will not occur when the stack\r\n\tis full so there can never be a case when the next count value\r\n\tis greater than the depth.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"generate.full.when.enabled\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a73.5.1<\/b>: <a href=\"#\">\u00a73.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  always @(posedge clk)\r\n    if (reset)\r\n      full_a &lt;= 0;\r\n    else\r\n      full_a &lt;= next_count_a == depth_a;\r\n\r\n  always @(posedge clk)\r\n    if (reset)\r\n      full_b &lt;= 0;\r\n    else\r\n      full_b &lt;= next_count_b == depth_b;\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507487472\"><\/a>3.6.\u00a0Conditionally generate the full logic<\/h3><\/div><\/div><\/div><p>\r\n\tAs discussed in <a class=\"xref\" href=\"#sect.parameters\" title=\"1.3.\u00a0Parameters\">Section\u00a01.3, &#8220;Parameters&#8221;<\/a>, based on\r\n\tthe value of the <em class=\"parameter\"><code>full_checking<\/code><\/em>\r\n\tparameter we either create the checking logic or just stub the\r\n\tfull signals out to always false.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"generate.full\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a73.6.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  generate\r\n    if (full_checking)\r\n      begin\r\n        <a class=\"fragref\" href=\"#generate.full.when.enabled\" title=\"Generate full\"><i>\u00a73.5.1. Generate full<\/i><\/a>\r\n      end\r\n    else\r\n      begin\r\n\tinitial full_a = 0;\r\n\tinitial full_b = 0;\r\n      end\r\n  endgenerate\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507484032\"><\/a>4.\u00a0BRAM implementation<\/h2><\/div><\/div><\/div><p>\r\n      This section describes the BRAM implementation of the dual LIFO.\r\n    <\/p><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507483008\"><\/a>4.1.\u00a0The data memory<\/h3><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"memory\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.1.1<\/b>: <a href=\"#\">\u00a74.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  reg `DATA_T mem [depth-1:0];\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507481600\"><\/a>4.2.\u00a0Maintain address pointers<\/h3><\/div><\/div><\/div><div class=\"figure\"><a name=\"bd_lifo2\"><\/a><p class=\"title\"><b>Figure\u00a01.\u00a0The pointer to the top of the A stack grows down while\r\n\tthe pointer to the top of the B stack grows up<\/b><\/p><div class=\"figure-contents\"><div class=\"mediaobject\"><object type=\"image\/svg+xml\" data=\"https:\/\/www.beyond-circuits.com\/files\/fig_lifo2_bram_ptr.svg\"><\/object><\/div><\/div><\/div><br class=\"figure-break\"><p>\r\n\tHere we maintain the address pointers into the RAM. The\r\n\tpointer for stack A starts at address zero and works up, while\r\n\tthe pointer for stack B starts at the last address and works\r\n\tdown.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"tos.pointers\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.2.1<\/b>: <a href=\"#\">\u00a74.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  wire `PTR_T ptr_a = writing_a ? count_a `PTR_T : (count_a `PTR_T)-1;\r\n  wire `PTR_T ptr_b = (depth-1)-(writing_b ? count_b `PTR_T\r\n                                           : (count_b `PTR_T)-1);\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507476976\"><\/a>4.3.\u00a0Top-of-stack<\/h3><\/div><\/div><\/div><p>\r\n\tOne limitation of the BRAM implementation is that we only have\r\n\ttwo ports. One port must be used for each stack since both\r\n\tstacks can operate simultaneously.\r\n\r\n\tThe solution to this problem is to recognize that if we are\r\n\tboth pushing and popping the stack then we are really only\r\n\toperating on the top element. This element can be stored in a\r\n\tregister and no actual memory operation needs to occur.\r\n      <\/p><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507475536\"><\/a>4.3.1.\u00a0Top-of-stack shadow registers<\/h4><\/div><\/div><\/div><p>\r\n\t  The <em class=\"replaceable\"><code>tos_shadow<\/code><\/em> registers hold the latest\r\n\t  value pushed onto the stack.\r\n\t<\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"tos.shadow.registers\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.3.1.1<\/b>: <a href=\"#\">\u00a74.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  reg `DATA_T tos_shadow_a;\r\n  always @(posedge clk)\r\n    if (reset)\r\n      tos_shadow_a &lt;= 0;\r\n    else if (writing_a)\r\n      tos_shadow_a &lt;= push_data_a;\r\n\r\n  reg `DATA_T tos_shadow_b;\r\n  always @(posedge clk)\r\n    if (reset)\r\n      tos_shadow_b &lt;= 0;\r\n    else if (writing_b)\r\n      tos_shadow_b &lt;= push_data_b;\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507472608\"><\/a>4.3.2.\u00a0Select between top-of-stack shadow registers and memory read values<\/h4><\/div><\/div><\/div><p>\r\n\t  Here we determine if we should use the memory read value or\r\n\t  the top-of-stack shadow register to provide the top-of-stack\r\n\t  value.\r\n\r\n\t  If we are popping the stack then the new top-of-stack value\r\n\t  should come from the memory read. Otherwise we should just\r\n\t  use the value in the top-of-stack shadow register.\r\n\t<\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"assign.tos\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.3.2.1<\/b>: <a href=\"#\">\u00a74.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  reg use_mem_rd_a;\r\n  always @(posedge clk)\r\n    if (reset)\r\n      use_mem_rd_a &lt;= 0;\r\n    else if (writing_a)\r\n      use_mem_rd_a &lt;= 0;\r\n    else if (reading_a)\r\n      use_mem_rd_a &lt;= 1;\r\n\r\n  reg use_mem_rd_b;\r\n  always @(posedge clk)\r\n    if (reset)\r\n      use_mem_rd_b &lt;= 0;\r\n    else if (writing_b)\r\n      use_mem_rd_b &lt;= 0;\r\n    else if (reading_b)\r\n      use_mem_rd_b &lt;= 1;\r\n\r\n  assign tos_a = use_mem_rd_a ? mem_rd_a : tos_shadow_a;\r\n\r\n  assign tos_b = use_mem_rd_b ? mem_rd_b : tos_shadow_b;\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507470320\"><\/a>4.4.\u00a0Perform memory reads<\/h3><\/div><\/div><\/div><p>\r\n\tHere we read from the stack. The values read will be the\r\n\ttop-of-stack outputs if we are reading from the stack but not\r\n\twriting to it.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"perform.memory.reads\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.4.1<\/b>: <a href=\"#\">\u00a74.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  reg `DATA_T mem_rd_a;\r\n  always @(posedge clk)\r\n    if (reading_a)\r\n      mem_rd_a &lt;= mem[ptr_a];\r\n\r\n  reg `DATA_T mem_rd_b;\r\n  always @(posedge clk)\r\n    if (reading_b)\r\n      mem_rd_b &lt;= mem[ptr_b];\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507467776\"><\/a>4.5.\u00a0Perform memory writes<\/h3><\/div><\/div><\/div><p>\r\n\tConversely if we are writing to the stack but not reading then\r\n\twe perform a memory write.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"perform.memory.writes\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.5.1<\/b>: <a href=\"#\">\u00a74.6.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  always @(posedge clk)\r\n    if (writing_a &amp;&amp; !reading_a)\r\n      mem[ptr_a] &lt;= tos_a;\r\n\r\n  always @(posedge clk)\r\n    if (writing_b &amp;&amp; !reading_b)\r\n      mem[ptr_b] &lt;= tos_b;\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507465712\"><\/a>4.6.\u00a0BRAM implementation body<\/h3><\/div><\/div><\/div><p>\r\n\tHere we collect all the components of the BRAM implementation.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"bram.implementation\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a74.6.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  <a class=\"fragref\" href=\"#memory\" title=\"The data memory\"><i>\u00a74.1.1. The data memory<\/i><\/a>\r\n  <a class=\"fragref\" href=\"#tos.pointers\" title=\"Maintain address pointers\"><i>\u00a74.2.1. Maintain address pointers<\/i><\/a>\r\n  <a class=\"fragref\" href=\"#perform.memory.reads\" title=\"Perform memory reads\"><i>\u00a74.4.1. Perform memory reads<\/i><\/a>\r\n  <a class=\"fragref\" href=\"#perform.memory.writes\" title=\"Perform memory writes\"><i>\u00a74.5.1. Perform memory writes<\/i><\/a>\r\n  <a class=\"fragref\" href=\"#tos.shadow.registers\" title=\"Top-of-stack shadow registers\"><i>\u00a74.3.1.1. Top-of-stack shadow registers<\/i><\/a>\r\n  <a class=\"fragref\" href=\"#assign.tos\" title=\"Select between top-of-stack shadow registers and memory read values\"><i>\u00a74.3.2.1. Select between top-of-stack shadow registers and memory read values<\/i><\/a>\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507460720\"><\/a>5.\u00a0Shift register implementation<\/h2><\/div><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507460080\"><\/a>5.1.\u00a0Shift register implementation of stack A<\/h3><\/div><\/div><\/div><p>\r\n\tThere may be situations where two stacks are needed but we\r\n\tdon't want to use a block RAM, or if both stacks don't need to\r\n\tbe very large and we want to save the overhead of the RAM\r\n\timplementation. This alternate shift register implementation\r\n\tmay be used instead.\r\n      <\/p><p>\r\n\tThe basic idea of the shift register implementation is to use\r\n\ta shift register for each bit of the data word. We then\r\n\tconcatenate the head of the shift registers together to form\r\n\tthe top of the stack.\r\n      <\/p><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507458160\"><\/a>5.1.1.\u00a0Pop data off the shift register<\/h4><\/div><\/div><\/div><p>\r\n\t  Here we shift the register left, shifting in a zero value.\r\n\t<\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"srl.pop.data\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a75.1.1.1<\/b>: <a href=\"#\">\u00a75.1.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\nsrl &lt;= {srl[depth-2:0],1'b0}\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507456368\"><\/a>5.1.2.\u00a0Push data onto the shift register<\/h4><\/div><\/div><\/div><p>\r\n\t  Here we shift the push data onto the shift register. This\r\n\t  will only happen when the shift register is not full.\r\n\t<\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"srl.push.data\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a75.1.2.1<\/b>: <a href=\"#\">\u00a75.1.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\nsrl &lt;= {push_data_a[i],srl[depth_a-1:1]}\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h4 class=\"title\"><a name=\"idm477507454336\"><\/a>5.1.3.\u00a0Swap data at the top of the shift register<\/h4><\/div><\/div><\/div><p>\r\n\t  Here we just replace the leftmost value in the shift\r\n\t  register with the new pushed value.\r\n\t<\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"srl.swap.data\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a75.1.3.1<\/b>: <a href=\"#\">\u00a75.1.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\nsrl &lt;= {push_data_a[i],srl[depth_a-2:0]}\r\n\t<\/pre><\/td><\/tr><\/table><\/div><\/div><p>\r\n\tWe use a generate for loop to implement each shift register\r\n\tand a case statement to update it based on the push and pop\r\n\tconditions.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"srl.implement.stack.a\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a75.1.1<\/b>: <a href=\"#\">\u00a75.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\nfor (i=0; i&lt;width; i=i+1)\r\n  begin : srl_a\r\n    reg [depth_a-1:0] srl;\r\n    always @(posedge clk)\r\n      case ({writing_a,reading_a})\r\n\t2'b01: <a class=\"fragref\" href=\"#srl.pop.data\" title=\"Pop data off the shift register\"><i>\u00a75.1.1.1. Pop data off the shift register<\/i><\/a>;\r\n\t2'b10: <a class=\"fragref\" href=\"#srl.push.data\" title=\"Push data onto the shift register\"><i>\u00a75.1.2.1. Push data onto the shift register<\/i><\/a>;\r\n\t2'b11: <a class=\"fragref\" href=\"#srl.swap.data\" title=\"Swap data at the top of the shift register\"><i>\u00a75.1.3.1. Swap data at the top of the shift register<\/i><\/a>;\r\n      endcase\r\n\r\n      assign tos_a[i] = srl[depth_a-1];\r\n  end\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507449168\"><\/a>5.2.\u00a0Shift register implementation of stack B<\/h3><\/div><\/div><\/div><p>\r\n\tThe implementation for stack B is the same as for stack A but\r\n\twith the appropriate name changes.\r\n      <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"srl.implement.stack.b\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a75.2.1<\/b>: <a href=\"#\">\u00a75.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\nfor (i=0; i&lt;width; i=i+1)\r\n  begin : srl_b\r\n    reg [depth_b-1:0] srl;\r\n    always @(posedge clk)\r\n      case ({writing_b,reading_b})\r\n\t2'b01: srl &lt;= {srl[depth_b-2:0],1'b0};\r\n\t2'b10: srl &lt;= {push_data_b[i],srl[depth_b-1:1]};\r\n\t2'b11: srl &lt;= {push_data_b[i],srl[depth_b-2:0]};\r\n      endcase\r\n      assign tos_b[i] = srl[depth_b-1];\r\n  end\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><p>\r\n      For the shift register implementation we just declare the\r\n      generate loop variable and then instantiate the two stacks.\r\n    <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"srl.implementation\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a75.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n  genvar i;\r\n  <a class=\"fragref\" href=\"#srl.implement.stack.a\" title=\"Shift register implementation of stack A\"><i>\u00a75.1.1. Shift register implementation of stack A<\/i><\/a>\r\n  <a class=\"fragref\" href=\"#srl.implement.stack.b\" title=\"Shift register implementation of stack B\"><i>\u00a75.2.1. Shift register implementation of stack B<\/i><\/a>\r\n    <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507444032\"><\/a>6.\u00a0Undefined implementation<\/h2><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"undefined.implementation\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a76.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n\tinitial\r\n\t  begin\r\n\t    $display(\"***ERROR: %m: Undefined implementation \\\"%0s\\\".\",implementation);\r\n\t    $finish;\r\n\t  end\r\n    <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507442496\"><\/a>7.\u00a0The main module<\/h2><\/div><\/div><\/div><p>\r\n      This is where we tie everything together.\r\n    <\/p><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"lifo2.v\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a77.1<\/b><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n<a class=\"fragref\" href=\"#header\" title=\"Header\"><i>\u00a71.1. Header<\/i><\/a>\r\n<a class=\"fragref\" href=\"#copyright\" title=\"Copyright\"><i>\u00a72.1. Copyright<\/i><\/a>\r\n\r\n`timescale 1ns\/1ns\r\n<a class=\"fragref\" href=\"#type.definitions\" title=\"Definitions\"><i>\u00a71.4.1. Definitions<\/i><\/a>\r\n\r\n<a class=\"fragref\" href=\"#module.declaration\" title=\"Module declaration\"><i>\u00a71.1.1. Module declaration<\/i><\/a>\r\n\r\n<a class=\"fragref\" href=\"#log2.function\" title=\"Functions\"><i>\u00a72.1. Functions<\/i><\/a>\r\n\r\n<a class=\"fragref\" href=\"#generate.reading.and.writing.signals\" title=\"Determine read and write signals\"><i>\u00a73.1.1. Determine read and write signals<\/i><\/a>\r\n\r\n<a class=\"fragref\" href=\"#generate.count.for.stack.a\" title=\"Determine count value for stack A\"><i>\u00a73.2.1. Determine count value for stack A<\/i><\/a>\r\n<a class=\"fragref\" href=\"#generate.count.for.stack.b\" title=\"Determine count value for stack B\"><i>\u00a73.3.1. Determine count value for stack B<\/i><\/a>\r\n\r\n<a class=\"fragref\" href=\"#generate.empty\" title=\"Generate empty\"><i>\u00a73.4.1. Generate empty<\/i><\/a>\r\n<a class=\"fragref\" href=\"#generate.full\" title=\"Conditionally generate the full logic\"><i>\u00a73.6.1. Conditionally generate the full logic<\/i><\/a>\r\n\r\n`ifndef SYNTHESIS\r\n   initial\r\n     $display(\"***INFO: %m: lifo2.v implementation=\\\"%0s\\\".\",implementation);\r\n`endif\r\n  generate\r\n    if (implementation == \"BRAM\")\r\n      begin : bram_implementation\r\n        <a class=\"fragref\" href=\"#bram.implementation\" title=\"BRAM implementation body\"><i>\u00a74.6.1. BRAM implementation body<\/i><\/a>\r\n      end\r\n    else if (implementation == \"SRL\")\r\n      begin : srl_implementation\r\n        <a class=\"fragref\" href=\"#srl.implementation\" title=\"Shift register implementation\"><i>\u00a75.1. Shift register implementation<\/i><\/a>\r\n      end\r\n    else\r\n      begin\r\n        <a class=\"fragref\" href=\"#undefined.implementation\" title=\"Undefined implementation\"><i>\u00a76.1. Undefined implementation<\/i><\/a>\r\n      end\r\n  endgenerate\r\nendmodule\r\n    <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"appendix\"><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507433840\"><\/a>A.\u00a0Front matter<\/h2><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507433200\"><\/a>1.\u00a0Header<\/h3><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"header\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a71.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n\/\/-----------------------------------------------------------------------------\r\n\/\/ Title         : Dual LIFO stack\r\n\/\/ Project       : Common\r\n\/\/-----------------------------------------------------------------------------\r\n\/\/ File          : lifo2.v\r\n\/\/-----------------------------------------------------------------------------\r\n\/\/ Description :\r\n\/\/ \r\n\/\/ Two Synchronous LIFO stacks using a single BRAM.\r\n\/\/\r\n\/\/ The stacks start at each end and grow to the middle.\r\n\/\/\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><div class=\"section\"><div class=\"titlepage\"><div><div><h3 class=\"title\"><a name=\"idm477507431312\"><\/a>2.\u00a0Copyright<\/h3><\/div><\/div><\/div><div xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" class=\"src-fragment\"><a name=\"copyright\"><\/a><table border=\"1\" width=\"100%\"><tr><td><p><b>\u00a72.1<\/b>: <a href=\"#\">\u00a77.1<\/a><\/p><\/td><\/tr><tr><td><pre class=\"src:fragment\">\r\n\/\/-----------------------------------------------------------------------------\r\n\/\/ Copyright 2009 Beyond Circuits. All rights reserved.\r\n\/\/\r\n\/\/ Redistribution and use in source and binary forms, with or without modification,\r\n\/\/ are permitted provided that the following conditions are met:\r\n\/\/   1. Redistributions of source code must retain the above copyright notice, \r\n\/\/      this list of conditions and the following disclaimer.\r\n\/\/   2. Redistributions in binary form must reproduce the above copyright notice, \r\n\/\/      this list of conditions and the following disclaimer in the documentation \r\n\/\/      and\/or other materials provided with the distribution.\r\n\/\/\r\n\/\/ THIS SOFTWARE IS PROVIDED BY THE BEYOND CIRCUITS ``AS IS'' AND ANY EXPRESS OR \r\n\/\/ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \r\n\/\/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT \r\n\/\/ SHALL BEYOND CIRCUITS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r\n\/\/ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\r\n\/\/ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r\n\/\/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, \r\n\/\/ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY \r\n\/\/ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n\/\/------------------------------------------------------------------------------\r\n      <\/pre><\/td><\/tr><\/table><\/div><\/div><\/div><div class=\"appendix\"><h2 class=\"title\" style=\"clear: both\"><a name=\"idm477507429776\"><\/a>B.\u00a0Downloads<\/h2><p>\r\n      The Verilog code for <code class=\"literal\">lifo2.v<\/code> can be\r\n      downloaded <a class=\"ulink\" href=\"https:\/\/www.beyond-circuits.com\/files\/lifo2.v\" target=\"_top\">here<\/a>. Since\r\n      this post is so long I have also included a link the article in\r\n      PDF form <a class=\"ulink\" href=\"https:\/\/www.beyond-circuits.com\/files\/lifo2.pdf\" target=\"_top\">here<\/a>.\r\n    <\/p><\/div><\/div>\r\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3,4],"tags":[],"class_list":["post-207","post","type-post","status-publish","format-standard","hentry","category-fpga","category-hdl","category-verilog"],"_links":{"self":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/posts\/207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/comments?post=207"}],"version-history":[{"count":10,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":218,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/posts\/207\/revisions\/218"}],"wp:attachment":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/media?parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/categories?post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/tags?post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}