memoryarchitecturefpgaaddressing

how Byte Address memory in Altera FPGA?


I worked with megafunctions to generate 32bit data memory in the fpga.but the output was addressed 32bit (4 bytes) at time , how to do 1 byte addressing ? i have Altera Cyclone IV ep4ce6e22c8.


Solution

  • I'm designing a 32bit CPU in fpga ,

    Nowadays every CPU address bus works in bytes. Thus to access your 32-bit wide memory you should NOT connect the LS 2 address bits. You can use the A[1:0] address bits to select a byte (or half word using A[1] only) from the memory when your read.

    You still will need four byte write enable signals. This allows you to write word, half-words or bytes.

    Have a look at existing CPU buses or existing connection standards like AHB or AXI.


    Post edit:

    but reading address 0001 , i get 0x05060708 but the desired value is 0x02030405.

    What you are trying to do is read a word from a non-aligned address. There is no existing 32-bit wide memory that supports that. I suggest you have a look at how a 32-bit wide memory works.

    The old Motorola 68020 architecture supported that. It requires a special memory controller which first reads the data from address 0 and then from address 4 and re-combines the data into a new 32-bit word.

    With the cost of memory dropping and reducing CPU cycles becoming more important, no modern CPU supports that. They throw an exception: non-aligned memory access.

    You have several choices:

    1. Build a special memory controller which supports unaligned accesses.

    2. Adjust your expectations.

    I would go for the latter. In general it is based on the wrong idea how a memory works. As consolidation: You are not the first person on this website who thinks that is how you read words from memory.