Electronics > FPGA

ALU in MIPS

<< < (3/3)

prophoss:
@rstofer
I have been thinking about what you  have been doing. I could copy and paste the code but implementing the MIPS core on my dev board is kind of the point. I have been learning more about MIPS for the past week or so. I did not realize how different the assembly code was for each kind of processor. The assembly I learned in class was for an STM32 kind of processor. All the basics are there but the actual code is different enough that I had to go looking to see what each op-code was doing. To be honest I still don't quite know what sliu is doing for this implementation.
Doing all the reading has got me wondering what would be the best way to learn the architecture? I love learning about how it all works and playing with the assembly code. It seems like a good way to see what each part of the code actually does. Kind of like figuring out how the abstraction layer was created. Just thought I'd see what you thought about it.

rstofer:
I'm not certain of the mnemonic for sliu but if you look in control_unit file, sliu sets up alu-op to '10'.  Then follow this into ALU_control and see where ALU_control is set to '100' and then follow along into ALU to see where it says if a<b then destination  becomes x"0001" else x"0000".

So, it does a comparison on the two source registers and puts a logical value into the result register.

There's not a lot of architecture involved.  You have memory, a control unit, some registers and an ALU.  You don't have TRAP instructions, there is no interrupt structure, DMA is completely out the window...  There just isn't a lot to it.  One way to draw the architecture is to draw rectangular blocks for all the entities and draw some interconnecting lines.  Everything goes through MIPS_VHDL so all the signals are at least routed through there whether they are used in that component or not.

This is a minimal CPU and it might be worthwhile for that feature alone but 256 words of RAM isn't much of a machine.

Once again, I'm going to bring up LC3 - a RISC processor that has terrific documentation as well as a book.  Google for 'LC3' and you will find a lot of universities using this book/CPU as an undergrad course in computer architecture.  In the meantime, look at the appendices:

https://www.cs.utexas.edu/users/fussell/courses/cs310h/lectures/Lecture_10-310h.pdf
https://www.cs.colostate.edu/~cs270/.Spring21/resources/PattPatelAppA.pdf

http://people.cs.georgetown.edu/~squier/Teaching/HardwareFundamentals/LC3-trunk/docs/LC3-uArch-PPappendC.pdf

Appendix C gives the block diagram and the state transition diagram as well as a coding form for the microcode for those who use the author's approach.  I used a case statement written exactly like the transition diagram but I really like the idea of using loadable microcode.  Either way...

At line 437 in LC3.vhd (in attached .zip file), you can see the beginning of the case statement..  Note how everything follows exactly from that diagram.  Easy!

If you look at Figure C-4, you can see the block diagram and when you compare it to LC3.vhd, the code should pretty much match.  All the muxen(tm) are laid out exactly according to the block diagram.  There is also a .hex file that contains a core load for an initial program.  It just implements interrupt driven IO over a serial port.  The important part is that the interrupt system works.  Check LC3.lst for the source program.  Lower memory is reserved for traps and interrupt vectors so it drags on a little.  There is an assembler manual here:

http://www.cs.binghamton.edu/~tbarten1/CS120_Summer_2013/ClassNotes/L10-LC3_RR.htm

There's an assembler out there somewhere.  I had it but I think I may have lost it momentarily.  Google for 'LC3 tools'

Here is the 3rd edition of the book, it is newer than the one I used (2d edition).  Mine has a blue cover and it matches the appendices that I linked above.

https://www.alibris.com/Introduction-to-Computing-Systems-From-Bits-and-Gates-to-C-C-Beyond-Yale-N-Patt/book/42539098

At some point, the authors changed to byte addressable memory and the new project is LC3b and you can find that project out on the Internet as well.  I haven't implemented it although I do have the newer book.  I'm not sure about tools for that project.  Is there a different assembler?  Beats me!

 

rstofer:

--- Quote from: prophoss on September 20, 2021, 12:01:43 am ---@rstofer
I have been thinking about what you  have been doing. I could copy and paste the code but implementing the MIPS core on my dev board is kind of the point. I have been learning more about MIPS for the past week or so. I did not realize how different the assembly code was for each kind of processor. The assembly I learned in class was for an STM32 kind of processor. All the basics are there but the actual code is different enough that I had to go looking to see what each op-code was doing.

--- End quote ---

Whether I am writing in assembly code or Fortran, I find it helpful to lay out the blocks with some kind of pseudo-code.  The relationship between pseudo operations and any particular instruction is pretty flexible.  Later, when I understand the nature of the various blocks, I start writing the actual code.

There's a programming practice known as "Top Down Design" which I follow up with "Bottom Up Coding".  I get the UART working first and leave the fancy stuff for later.  Once I can get debug output, I'm on my way.  Next up?  Functions to print formatted IO.  Not necessarily a full-blown printf() but things like putstr(), atoi(), some kind of hex output for nibbles, bytes, shorts and words.  That kind of thing.  I grab all of my string functions from "The C Programming Language" by Kernighan and Ritchie.

https://www.techopedia.com/definition/9744/top-down-design

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version