The aim of this coding challenge is to create a hardware stack module which has the ability to push, pop and peek according to a given instruction. In order to attempt the coding challenge, fork this branch of the repository and attempt the challenge. Upon completion, create a PDF file consisting of the link to your fork, the code (with the mention of file name) you have written and the output you recieved.
The StackModule is the name of the hardware stack to be implemented. This main module must be written in src/main/scala/stack/StackModule.scala. The StackModule must be parameterized with the following parameters.
- dataWidth: The bitwidth of a single element to be stored in the stack.
- len: The length of the stack.
- io.in: A
dataWidthwide input port. Used to input instructions.
- io.out: A
dataWidthwide input port. Used to output values from the stack. - io.underflow: A 1-bit port used to indicate underflow flag of the
popandpeekinstructions. - io.overflow: A 1-bit port used to indicate overflow flag of the
pushinstructions. - io.isEmpty: A 1-bit port used to indicate that the stack is empty.
- io.isFull: A 1-bit port used to indicate that the stack is full.
- io.popped: A 1-bit port used to indicate that the successful popping of a value from the stack.
- io.peeked: A 1-bit port used to indicate that the successful peeking of a value from the stack.
Based on the following instructions and their encodings, the StackModule will perform operations.
| instruction | instruction[31:7] (imm[24:0]) | instruction[6:0] (opcode) |
|---|---|---|
| push | imm[24:0] | 0100111 |
| pop | 0000000000000000000000000 | 1000011 |
| peek | 0000000000000000000000000 | 1000000 |
- push: The push instruction inserts the
dataWidth-bit zero-extended immediate to the stack. Theio.isFulloutput is asserted when the stack becomes full. If the stack is already full,io.overflowwill be asserted. - pop: The pop instruction removes the
dataWidth-bit value from the top of the stack and sends it toio.outwhile also assertingio.popped.io.isEmptyis asserted if the stack becomes empty. If the stack is already empty,io.underflowwill be asserted and the value 0 will be read.. - peek: The peek instruction reads the
dataWidth-bit value from the top of the stack and sends it toio.outwhile also assertingio.peeked. If the stack is already empty,io.underflowwill be asserted and the value 0 will be read.
In order to run tests, you need to have cocotb and bitstring installed.
pip install 'cocotb~=1.9'
pip install bitstringTo simulate and run the tests on your DUT, run:
python3 run_tests.py