Stack bugfixes
authoradam <adam@megacz.com>
Mon, 26 Feb 2007 11:56:08 +0000 (12:56 +0100)
committeradam <adam@megacz.com>
Mon, 26 Feb 2007 11:56:08 +0000 (12:56 +0100)
ships/Stack.ship
tests/stack/stack-test.fleet

index 58d5e12..a3bb7ef 100644 (file)
@@ -37,21 +37,25 @@ process any new {\tt pop} operations.
 
   reg    [(`DATAWIDTH-1):0] mem [4:0];
   reg    [5:0]              depth;
+  reg    skip;
+  initial depth = 0;
 
   always @(posedge clk) begin
-    if (depth < 32) begin
-      `onread(push_r, push_a)
-        pop_d       = push_d;
-        mem[depth] <= push_d;
-        depth       = depth + 1;
-      end
-    end
+    skip = 0;
     if (depth > 0) begin
-      `onwrite(pop_r, pop_d)
-        depth = depth - 1;
-        if (depth > 0) begin
-          pop_d = mem[depth];
+      `onwrite(pop_r, pop_a)
+        if (depth > 1) begin
+          pop_d <= mem[depth-2];
         end
+        depth <= depth - 1;
+        skip = 1;
+      end
+    end
+    if (!skip && depth < 32) begin
+      `onread(push_r, push_a)
+        pop_d      <= push_d;
+        mem[depth] <= push_d;
+        depth      <= depth + 1;
       end
     end
   end
index 835ffc0..8cd24b1 100644 (file)
@@ -7,15 +7,18 @@
 #expect 1
 #expect 0
 
+debug.in:  [*] take, deliver;
 stack.push: [5] take, deliver; notify stack.pop;
 
+stack.pop: wait; [*] take, sendto debug.in;
+
 0: sendto stack.push;
 1: sendto stack.push;
 2: sendto stack.push;
 3: sendto stack.push;
 4: sendto stack.push;
 
-stack.pop: wait; [*] take, sendto debug.in;
-debug.in:  [*] take, deliver;
+
+