Shop OBEX P1 Docs P2 Docs Learn Events
Write a MIPS simulator using SPIM — Parallax Forums

Write a MIPS simulator using SPIM

kostas0z0000kostas0z0000 Posts: 2
edited 2012-05-01 14:32 in Propeller 1
I am trying to solve the problem below:

Write a simulator for a subset of the MIPS instruction set
using MIPS instructions and the SPIM simulator. Your
simulator should execute hand-assembled programs that are located in the data
segment of the SPIM simulator and should use
$v0 and $v1 for input and output.
Other portions of the data segment can be used for storing the memory contents
and register values of your virtual machine. Your implementation can use any of
the MIPS instructions, but your simulator need only support a smaller subset of
the instruction set, as add, addi, mul div, lw, sw, and, ori, nor, sll, j, beq, bne, jal.

I would like to give me an example to understand how to read data segment, recognise the function (add), move the real data in the registers that i'll use and how to store them back in data segment!

Thanks in advance!!!

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2012-05-01 07:50
    I think you may be trying to get your homework assignment done on the wrong forum.

    Parallax has nothing to do with MIPS processors or the SPIM simulator.

    Parallax does manufacture a Propeller microcontroller that has as it's native language, something called SPIN...but this is nothing like SPIM.

    Sorry, I think you need to go back to Google and Wikipedia and do a little more research!

    Good luck on your assignment!!
  • ctwardellctwardell Posts: 1,716
    edited 2012-05-01 07:59
    So it just now hit me that SPIM is the reverse of MIPS...

    C.W.
  • mindrobotsmindrobots Posts: 6,506
    edited 2012-05-01 08:04
    So we need a tool called NIPS that changes bytecodes back to SPIN source? :lol:

    By the way, kostas0z0000, I forgot to welcome you to the forum. Welcome, hope you can stay around and learn about Parallax products!
  • LeonLeon Posts: 7,620
    edited 2012-05-01 08:11
    kostas0z0000,

    I use the PIC32 occasionally, which has a MIPS core, and have played with the SPIM simulator. I spent about half a day, a few months ago, working out how to write an assembler program for the PIC32. My test program might be of interest:
    	.global main
    	.data
    var1:	.word	0x2222
    var2:	.word	0xFFFF
    	.text
    	.ent 		main
    
    main:
    loop:
    	nop
    	lw		$t1,var1
    	lw		$t2,var2
    	add		$t0,$t1,$t2	# $t0 = $t1 + $t2
    	mult		$t1,$t2		# (Hi,Lo) = $t1 * $t2
    	div		$t2,$t1		# Lo = $t2 / $t1 Hi = $t2 mod $t1
    	nop
    	j		loop
    
    .end main
    

    It runs OK under the Microchip PIC32 simulator, and on an actual PIC32 chip with the ICD 3 debugger. I can't remember if it works with SPIM, though.
  • jazzedjazzed Posts: 11,803
    edited 2012-05-01 09:32
    Propeller has something of a history of emulating other processors. I've always thought that a MIPS3 emulator would be interesting to have.
  • ctwardellctwardell Posts: 1,716
    edited 2012-05-01 09:50
    jazzed wrote: »
    Propeller has something of a history of emulating other processors. I've always thought that a MIPS3 emulator would be interesting to have.

    It can't be done.

    There, I said it, now someone can go ahead and prove me wrong.

    C.W.
  • bruceebrucee Posts: 239
    edited 2012-05-01 12:08
    Oh, I'm sure it could be done, but by the time you emulate the memory management and expanded memory it would be incredibly slow.

    Probably more interesting to write a SPIN interpreter on a MIPS.
  • ctwardellctwardell Posts: 1,716
    edited 2012-05-01 13:01
    Hey brucee, welcome to the forum.

    It seems like every time something comes up and someone says it isn't possible on the prop, someone goes and makes it work.

    I was just doing my part and planting that seed.

    C.W.
  • Heater.Heater. Posts: 21,230
    edited 2012-05-01 13:12
    Jazzed,
    Propeller has something of a history of emulating other processors.

    Actually it does not. There is my ZiCog 8080/Z80 emulator and there is Pulmol's Z80 emulator. I was looking forward to a 6502 emulator and I made a stab at the 6809 which proved to be too much for me.

    Then there is ZOG which is not so much an emulator as there never was such a thing as the ZPU chip.
  • rod1963rod1963 Posts: 752
    edited 2012-05-01 13:50
    There are FPGA implementations of Zylin. One in just released a couple of weeks ago is done on a $64.00 board(32bit Zylin). Looks neat.
    Great time to be a computer/electronic hobbyist.

    see:
    http://alvie.com/zpuino/
  • jazzedjazzed Posts: 11,803
    edited 2012-05-01 14:01
    brucee wrote: »
    Oh, I'm sure it could be done, but by the time you emulate the memory management and expanded memory it would be incredibly slow.

    Probably more interesting to write a SPIN interpreter on a MIPS.

    HAHAHAHAHAHAHA :)

    Welcome aboard!

    BTW, we have a couple of different propeller simulators on the PC and Linux that run spin just fine. All you need is Linux on MIPS.
  • Heater.Heater. Posts: 21,230
    edited 2012-05-01 14:07
    Yes, yes, of course there are VHDL/verilog implementations of the ZPU. That is the whole idea, put a CPU on the silicon using the least space. Turns out to be nice to implement on the Prop with its severe COG memory constraints.
  • jazzedjazzed Posts: 11,803
    edited 2012-05-01 14:32
    Heater. wrote: »
    Yes, yes, of course there are VHDL/verilog implementations of the ZPU. That is the whole idea, put a CPU on the silicon using the least space. Turns out to be nice to implement on the Prop with its severe COG memory constraints.

    Yes, it is nice. As I remember code is about the same size as SPIN code and maybe a little faster. Did you finish the little-endian implementation?
  • kostas0z0000kostas0z0000 Posts: 2
    edited 2012-05-01 14:32
    mindrobots wrote: »
    I think you may be trying to get your homework assignment done on the wrong forum.

    Parallax has nothing to do with MIPS processors or the SPIM simulator.

    Parallax does manufacture a Propeller microcontroller that has as it's native language, something called SPIN...but this is nothing like SPIM.

    Sorry, I think you need to go back to Google and Wikipedia and do a little more research!

    Good luck on your assignment!!

    Sorry for the misunderstanding! By the way is not exactly my homework assignment, my teacher just proposed some exercises and I found it interesting.
    However i will give up, I can't find something to start with!
Sign In or Register to comment.