Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MIPS 200 assembler please help

Status
Not open for further replies.

Deathlich

Newbie level 6
Joined
Oct 11, 2006
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
Hello everyone, I have project to make a c/c++ program acts like MIPS assembler, in other words I have to implement ISA using software.

To make it clear, the user write a .txt file including some MIPS instructions (e.g "ADD $t9,$a0,$t5"), and I should read instructions and perform execute it on registers (variables in my program), My main problem in branch and jump instructions. Also I did the scanner, where I put all the user file in an array, but I am thinking to change this to take one instruction at a time (one line).

One last thing, the memory instructions. how to implement memory? using array of structs?

any idea, helps, links to make this clear.
thanx in advance
 

Deathlich,

I'm doing somethile like this at the moment, i'm developing a component for C++ Builder that can execut a script (program), this strict is generated form anoder program....

I prefer to use the spript in hex format, not ascii. With Hex I can declare my memory, for example:

unsigned __int16 MemoryMap[64 * 1024]; //For a 64K memory...

Than I define address (indexes of array) from 0x0000 to 0x0FFF to be the data memory and the others (0x1000 to 0xFFFF) to the program memory.

The registers was declared like this:
typedef union Regs
{
__int16 b16;
__int8 b8[2];
}TRegs;

typedef struct Registers
{
TRegs PC;
TRegs SP;
TRegs R2;
TRegs R3;
TRegs R4;
TRegs R5;
TRegs R6;
TRegs R7;
TRegs R8;
TRegs R9;
TRegs R10;
TRegs R11;
TRegs R12;
TRegs R13;
TRegs R14;
TRegs R15;
}TCPURegs;

TCPURegs Registers;

With this you can analize with a switch the value of MemoryMap[Registers.PC], and decid wat to do, move something to an register, move somthin to memory position increment, decrement or test register/memory position.

To me it works, but the program is not writen uning a text editor, you have to made an compiler (you write the assembler and tho compiler convert it to hex values, like borland TASM do with assembler for 8088).

Is it, i'd like to helped you....

Deathlich said:
Hello everyone, I have project to make a c/c++ program acts like MIPS assembler, in other words I have to implement ISA using software.

To make it clear, the user write a .txt file including some MIPS instructions (e.g "ADD $t9,$a0,$t5"), and I should read instructions and perform execute it on registers (variables in my program), My main problem in branch and jump instructions. Also I did the scanner, where I put all the user file in an array, but I am thinking to change this to take one instruction at a time (one line).

One last thing, the memory instructions. how to implement memory? using array of structs?

any idea, helps, links to make this clear.
thanx in advance
 

    Deathlich

    Points: 2
    Helpful Answer Positive Rating
thnx alot, this was very usefull to me, but still, the implementation of the jmp and branch instructions are confusing, or its the huge amount of instructions confusing me :p
 

Well.. The jump instruction is very simple, just like the others...

Code:
#define BRANCH                    0x0003
#define JUMP                         0x0004
#define OTHER_INSTRUCION  0x0005

//Put this conde inside a Thread
while (1)
{
  switch(MemoryMap[Registers.PC.b16])
  {
    case BRANCH:
      Registers.PC.b16 = MemoryMap[Registers.PC.b16 + 1]; //Do the Branch instruction
    break;

    case JUMP:
      Registers.PC.b16 += (int)MemoryMap[Registers.PC.b16 + 1]; //Do the relative jump instruction
    break;

    case OTHER_INSTRUCION:
    //Put the code of another instruction here (like MOVE, BITSET BITCLEAR...)

      Registers.PC.b16 += 3; //Increment the number of words of this instruction (Conde (one word) +  Argument (0 or 1 or 2 or ... or n Words)
    break;
  }
}

In my opinion it is very simple, and this Idea is adaptable to string list comand list...
You need to have something indexing the atual instrunction, after execute the instruction you change this pointer to index the other instrunction, in Branch instrunction you change the index directly...

Att

Deathlich said:
thnx alot, this was very usefull to me, but still, the implementation of the jmp and branch instructions are confusing, or its the huge amount of instructions confusing me :p
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top