├── mips
├── obj
│ └── Debug
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ ├── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ │ ├── mips.exe
│ │ ├── mips.pdb
│ │ ├── mips.Form1.resources
│ │ ├── mips.Properties.Resources.resources
│ │ ├── mips.csproj.GenerateResource.Cache
│ │ ├── DesignTimeResolveAssemblyReferences.cache
│ │ ├── mips.csprojResolveAssemblyReference.cache
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ └── mips.csproj.FileListAbsolute.txt
├── push.sh
├── bin
│ └── Debug
│ │ ├── mips.exe
│ │ ├── mips.pdb
│ │ ├── mips.vshost.exe
│ │ ├── mips.exe.config
│ │ ├── mips.vshost.exe.config
│ │ └── mips.vshost.exe.manifest
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Registers
│ ├── a.cs
│ ├── s.cs
│ ├── v.cs
│ ├── t.cs
│ ├── fp.cs
│ ├── lo.cs
│ ├── ra.cs
│ ├── sp.cs
│ ├── hi.cs
│ ├── zero.cs
│ ├── pc.cs
│ └── Regs.cs
├── Program.cs
├── Extension.cs
├── Cpu
│ ├── registers.cs
│ └── mips.cs
├── mips.csproj
├── Form1.cs
├── Form1.resx
└── Form1.Designer.cs
├── mips.v12.suo
├── README.md
└── mips.sln
/mips/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/mips/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/mips/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/mips/push.sh:
--------------------------------------------------------------------------------
1 | git add .
2 | git commit -m "a"
3 | git push origin master
4 |
--------------------------------------------------------------------------------
/mips.v12.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips.v12.suo
--------------------------------------------------------------------------------
/mips/bin/Debug/mips.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/bin/Debug/mips.exe
--------------------------------------------------------------------------------
/mips/bin/Debug/mips.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/bin/Debug/mips.pdb
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/mips.exe
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/mips.pdb
--------------------------------------------------------------------------------
/mips/bin/Debug/mips.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/bin/Debug/mips.vshost.exe
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.Form1.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/mips.Form1.resources
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MIPS-Simulator
2 |
3 |
4 | [MIPS Processor](http://pt.wikipedia.org/wiki/Arquitetura_MIPS) simulator and debugger written in C#.
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.Properties.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/mips.Properties.Resources.resources
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.csproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/mips.csproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/mips/obj/Debug/DesignTimeResolveAssemblyReferences.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/DesignTimeResolveAssemblyReferences.cache
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.csprojResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/mips.csprojResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/mips/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BernardoGO/MIPS-Simulator/HEAD/mips/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/mips/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mips/bin/Debug/mips.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mips/bin/Debug/mips.vshost.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mips/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/mips/Registers/a.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class a : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[4];
14 | }
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/mips/Registers/s.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class s : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[8];
14 | }
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/mips/Registers/v.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class v : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[2];
14 | }
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/mips/Registers/t.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class t : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[10];
14 |
15 | }
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/mips/bin/Debug/mips.vshost.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/mips/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace mips
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new Form1());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/mips/Registers/fp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class fp : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 | }
15 |
16 | public override List getData()
17 | {
18 | List ret = new List();
19 |
20 | ret.Add(new regdm() { registerName = "FP", value = data[0] });
21 |
22 | return ret;
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mips/Registers/lo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class lo : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 | }
15 |
16 | public override List getData()
17 | {
18 | List ret = new List();
19 |
20 | ret.Add(new regdm() { registerName = "LO", value = data[0] });
21 |
22 | return ret;
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mips/Registers/ra.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class ra : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 | }
15 |
16 | public override List getData()
17 | {
18 | List ret = new List();
19 |
20 | ret.Add(new regdm() { registerName = "RA", value = data[0] });
21 |
22 | return ret;
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mips/Registers/sp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class sp : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 | }
15 |
16 | public override List getData()
17 | {
18 | List ret = new List();
19 |
20 | ret.Add(new regdm() { registerName = "SP", value = data[0] });
21 |
22 | return ret;
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/mips/Registers/hi.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class hi : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 |
15 | }
16 |
17 | public override List getData()
18 | {
19 | List ret = new List();
20 |
21 | ret.Add(new regdm() { registerName = "HI", value = data[0] });
22 |
23 | return ret;
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/mips/Registers/zero.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class zero : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 | defaultChar = 1;
15 | }
16 |
17 | public override List getData()
18 | {
19 | return new List();
20 | }
21 |
22 | public override int get()
23 | {
24 | return 0; // $0 sempre retorna zero
25 | }
26 |
27 | public override void set(int Val)
28 | {
29 | set(0); // $0 não aceita novos valores
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/mips/obj/Debug/mips.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\bin\Debug\mips.exe.config
2 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\bin\Debug\mips.exe
3 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\bin\Debug\mips.pdb
4 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\obj\Debug\mips.csprojResolveAssemblyReference.cache
5 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\obj\Debug\mips.Form1.resources
6 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\obj\Debug\mips.Properties.Resources.resources
7 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\obj\Debug\mips.csproj.GenerateResource.Cache
8 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\obj\Debug\mips.exe
9 | C:\Users\Bernardo\Dropbox\Projetos\C#\MIPS\mips\mips\obj\Debug\mips.pdb
10 |
--------------------------------------------------------------------------------
/mips/Extension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ExtensionMethods
8 | {
9 | public static class extends
10 | {
11 | public static string GetLine(this string text, int lineNo)
12 | {
13 | //Converte e divide as linhas em string array
14 | string[] lines = text.Replace("\r", "").Split('\n');
15 |
16 | //retorna a linha X ou null se não existir
17 | return lines.Length >= lineNo ? lines[lineNo] : null;
18 | }
19 |
20 | public static int GetLine(this string text, string content)
21 | {
22 | //Converte e divide as linhas em string array
23 | string[] lines = text.Replace("\r", "").Split('\n');
24 |
25 | //Encontra a linha que contem a string e retorna o indice
26 | return Array.FindIndex(lines, row => row.Contains(content + ":"));
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/mips.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mips", "mips\mips.csproj", "{DB1AED8B-F2FC-493E-93B1-46797DDA8D62}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {DB1AED8B-F2FC-493E-93B1-46797DDA8D62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {DB1AED8B-F2FC-493E-93B1-46797DDA8D62}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {DB1AED8B-F2FC-493E-93B1-46797DDA8D62}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {DB1AED8B-F2FC-493E-93B1-46797DDA8D62}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/mips/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18449
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace mips.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/mips/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("mips")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("mips")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("df20b2ef-5db1-4dba-8e9d-8ad8458187b4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/mips/Registers/pc.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Registers
8 | {
9 | class pc : Regs
10 | {
11 | public override void initialize()
12 | {
13 | data = new int[1];
14 | }
15 |
16 | public override List getData()
17 | {
18 | List ret = new List();
19 |
20 | ret.Add(new regdm() { registerName = "PC", value = data[0] });
21 |
22 | return ret;
23 | }
24 |
25 | public void inc()
26 | {
27 | set(get() + 1);
28 |
29 | }
30 |
31 | public void inc(int x)
32 | {
33 | set(get() + x);
34 | }
35 |
36 | public void dec()
37 | {
38 | set(get() - 1);
39 | }
40 |
41 | public void dec(int x)
42 | {
43 | set(get() - x);
44 | }
45 |
46 | ///
47 | /// Retornará o valor dividido por quatro
48 | ///
49 | /// PC / 4
50 | public override int get()
51 | {
52 | return get(0) / 4;
53 | }
54 |
55 | ///
56 | /// Difinirá o valor multiplicado por quatro
57 | ///
58 | /// valor da linha
59 | public override void set(int Val)
60 | {
61 | set(Val * 4, 0);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/mips/Cpu/registers.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips.Cpu
8 | {
9 | class registers
10 | {
11 | // Prefixo usado para reflection
12 | public string Prefix = "Reg_";
13 |
14 | public Registers.a Reg_a = new Registers.a();
15 | public Registers.s Reg_s = new Registers.s();
16 | public Registers.t Reg_t = new Registers.t();
17 | public Registers.v Reg_v = new Registers.v();
18 |
19 | public Registers.zero Reg_0 = new Registers.zero();
20 |
21 | public Registers.pc Reg_PC = new Registers.pc();
22 | public Registers.fp Reg_FP = new Registers.fp();
23 | public Registers.hi Reg_HI = new Registers.hi();
24 | public Registers.lo Reg_LO = new Registers.lo();
25 | public Registers.ra Reg_RA = new Registers.ra();
26 | public Registers.sp Reg_SP = new Registers.sp();
27 |
28 | public void reset()
29 | {
30 | Reg_a = new Registers.a();
31 | Reg_s = new Registers.s();
32 | Reg_t = new Registers.t();
33 | Reg_v = new Registers.v();
34 | Reg_PC = new Registers.pc(); //Program Counter
35 | Reg_FP = new Registers.fp();
36 | Reg_HI = new Registers.hi();
37 | Reg_LO = new Registers.lo();
38 | Reg_RA = new Registers.ra();
39 | Reg_SP = new Registers.sp();
40 | }
41 |
42 | public List printRegisters()
43 | {
44 | List ret = new List();
45 |
46 | ret.AddRange(Reg_PC.getData());
47 | ret.AddRange(Reg_FP.getData());
48 | ret.AddRange(Reg_HI.getData());
49 | ret.AddRange(Reg_LO.getData());
50 | ret.AddRange(Reg_RA.getData());
51 | ret.AddRange(Reg_SP.getData());
52 | ret.AddRange(Reg_a.getData());
53 | ret.AddRange(Reg_s.getData());
54 | ret.AddRange(Reg_t.getData());
55 | ret.AddRange(Reg_v.getData());
56 |
57 | return ret;
58 |
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/mips/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18449
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace mips.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("mips.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/mips/Registers/Regs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace mips
8 | {
9 |
10 | abstract class Regs
11 | {
12 | public int[] data = new int[0]; //Quantidade de registradores do subconjunto T
13 |
14 | //Identificador para encontrar o registrador
15 | public string regId = "";
16 |
17 | //Valores usados para identificar o registrador
18 | public int defaultChar = 2;
19 | public int defaultCharLength = 1;
20 |
21 | public struct regdm
22 | {
23 | public string registerName { get; set; }
24 | public int value { get; set; }
25 |
26 | }
27 |
28 | public Regs()
29 | {
30 | initialize();
31 | for (int i = 0; i < data.Count(); i++)
32 | {
33 | data[i] = 0;
34 | }
35 |
36 | regId = this.GetType().Name; //Define o nome padrão do registrador baseado no nome da classe
37 | }
38 |
39 | public abstract void initialize();
40 |
41 | public virtual List getData()
42 | {
43 | List ret = new List();
44 |
45 | for (int i = 0; i < data.Count(); i++)
46 | {
47 | //Valor será xY, onde x é o nome do registrador e Y é o seu index no subconjunto
48 | ret.Add(new regdm() { registerName = regId + i, value = data[i] });
49 | }
50 |
51 | return ret;
52 |
53 | }
54 |
55 | public T getId()
56 | {
57 | //Recebe o Id em qualquer tipo
58 | return (T)Convert.ChangeType(regId, typeof(T));
59 | }
60 |
61 | ///
62 | /// Gets o valor do primeiro registrador no subconjunto
63 | ///
64 | ///
65 | public virtual int get()
66 | {
67 | return get(0);
68 | }
69 |
70 | ///
71 | /// Gets o valor de um registrador especifico no subconjunto
72 | ///
73 | ///
74 | ///
75 | public virtual int get(int Index)
76 | {
77 | return data[Index];
78 | }
79 |
80 | ///
81 | /// Define o valor do primeiro registrador do subconjunto
82 | ///
83 | ///
84 | public virtual void set(int Val)
85 | {
86 | set(Val, 0);
87 | }
88 |
89 | ///
90 | /// Define o valor de um registrador especifico no subconjunto
91 | ///
92 | ///
93 | ///
94 | public virtual void set(int Val, int Index)
95 | {
96 | data[Index] = Val;
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/mips/mips.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {DB1AED8B-F2FC-493E-93B1-46797DDA8D62}
8 | WinExe
9 | Properties
10 | mips
11 | mips
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | Form
52 |
53 |
54 | Form1.cs
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | Form1.cs
72 |
73 |
74 | ResXFileCodeGenerator
75 | Resources.Designer.cs
76 | Designer
77 |
78 |
79 | True
80 | Resources.resx
81 |
82 |
83 | SettingsSingleFileGenerator
84 | Settings.Designer.cs
85 |
86 |
87 | True
88 | Settings.settings
89 | True
90 |
91 |
92 |
93 |
94 |
95 |
96 |
103 |
--------------------------------------------------------------------------------
/mips/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 | using ExtensionMethods;
11 |
12 | namespace mips
13 | {
14 | public partial class Form1 : Form
15 | {
16 | Cpu.mips cpu = new Cpu.mips();
17 | public Form1()
18 | {
19 | InitializeComponent();
20 | //Registers.initialize();
21 | cpu.Finished += new EventHandler(finished);
22 | }
23 |
24 | private void finished(object sender, EventArgs e)
25 | {
26 | boxCode.SelectAll();
27 | boxCode.SelectionColor = Color.Black;
28 | last = 0;
29 | didNoop = false;
30 | }
31 |
32 | private void button1_Click(object sender, EventArgs e)
33 | {
34 | noop();
35 |
36 | cpu.start(boxCode.Text);
37 | updateView();
38 |
39 | boxCode.SelectAll();
40 | boxCode.SelectionColor = Color.Blue;
41 | }
42 |
43 | private void Form1_Load(object sender, EventArgs e)
44 | {
45 | registerView.AutoGenerateColumns = true;
46 | updateView();
47 | }
48 |
49 | public void updateView()
50 | {
51 | registerView.DataSource = cpu.regs.printRegisters();
52 | registerView.Refresh();
53 | }
54 |
55 | private void button2_Click(object sender, EventArgs e)
56 | {
57 | runTextChanged = false;
58 | cpu.regs.reset();
59 | updateView();
60 | runTextChanged = true;
61 | }
62 |
63 | int last = 0;
64 |
65 | private void button3_Click(object sender, EventArgs e)
66 | {
67 | runTextChanged = false;
68 | int indx2 = boxCode.Text.GetLine(last).IndexOf("#") > 0 ? boxCode.Text.GetLine(last).IndexOf("#") : boxCode.Text.GetLine(last).Length;
69 |
70 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(last), indx2);
71 | boxCode.SelectionColor = Color.Blue;
72 |
73 | int lst2 = boxCode.Text.GetLine(last).Length - indx2;
74 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(last) + indx2, lst2);
75 | boxCode.SelectionColor = Color.Green;
76 | last = cpu.regs.Reg_PC.get();
77 |
78 | noop();
79 |
80 | int indx = boxCode.Text.GetLine(last).IndexOf("#") > 0 ? boxCode.Text.GetLine(last).IndexOf("#") : boxCode.Text.GetLine(last).Length;
81 |
82 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(last), indx);
83 | boxCode.SelectionColor = Color.Red;
84 |
85 | int lst = boxCode.Text.GetLine(last).Length - indx;
86 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(last) + indx, lst);
87 | boxCode.SelectionColor = Color.Green;
88 |
89 | cpu.nextStep(boxCode.Text);
90 |
91 |
92 | updateView();
93 | runTextChanged = true;
94 | }
95 |
96 | bool didNoop = false;
97 | public void noop()
98 | {
99 | if (didNoop) return;
100 | didNoop = true;
101 | if (boxNop.Checked) while (boxCode.Text.Contains("\n\n")) boxCode.Text = boxCode.Text.Replace("\n\n", "\nNOP\n");
102 |
103 | for (int i = 0; i < boxCode.Lines.Count(); i++)
104 | {
105 | int indx = boxCode.Text.GetLine(i).IndexOf("#") > 0 ? boxCode.Text.GetLine(i).IndexOf("#") : boxCode.Text.GetLine(i).Length;
106 |
107 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(i), indx);
108 | boxCode.SelectionColor = Color.Black;
109 |
110 | int lst = boxCode.Text.GetLine(i).Length - indx;
111 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(i) + indx, lst);
112 | boxCode.SelectionColor = Color.Green;
113 | }
114 | }
115 |
116 | bool runTextChanged = true;
117 | private void boxCode_TextChanged(object sender, EventArgs e)
118 | {
119 | /*
120 | if (!runTextChanged) return;
121 | int xxx = boxCode.SelectionStart;
122 | for (int i = 0; i < boxCode.Lines.Count(); i++)
123 | {
124 | int indx = boxCode.Text.GetLine(i).IndexOf("#") > 0 ? boxCode.Text.GetLine(i).IndexOf("#") : boxCode.Text.GetLine(i).Length;
125 |
126 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(i), indx);
127 | boxCode.SelectionColor = Color.Black;
128 |
129 | int lst = boxCode.Text.GetLine(i).Length - indx;
130 | boxCode.Select(boxCode.GetFirstCharIndexFromLine(i) + indx, lst);
131 | boxCode.SelectionColor = Color.Green;
132 | }
133 | boxCode.Select(xxx, 0);
134 | * */
135 | }
136 | }
137 | }
138 |
139 | /*
140 | addi $s0, $0, 2 # Define $s0 como a soma de 2 + 0
141 | addi $s1, $s0, 3 # Define $s1 como soma de $s0 + 3
142 |
143 | jal repetir10 # Chama função repetir10 e define o endereço de retorno
144 |
145 | mult $s2, $s1 # Multiplica $s2 por $s1
146 |
147 | addi $v0, $0, 10 # Define o v0 e chama o syscall para terminar
148 | syscall # Executa saida
149 |
150 |
151 | repetir10: # Definição da função
152 | addi $s3, $0, 10 # $s3 = 0 + 10
153 | repeat:
154 | addi $s2, $s2, 1
155 | bne $s2, $s3, repeat # se $s2 != $s3 goto repeat
156 | jr ra # retorna o contador de programa para onde a função foi chamada
157 | */
--------------------------------------------------------------------------------
/mips/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/mips/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/mips/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace mips
2 | {
3 | partial class Form1
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.button1 = new System.Windows.Forms.Button();
32 | this.boxCode = new System.Windows.Forms.RichTextBox();
33 | this.registerView = new System.Windows.Forms.DataGridView();
34 | this.button2 = new System.Windows.Forms.Button();
35 | this.button3 = new System.Windows.Forms.Button();
36 | this.boxNop = new System.Windows.Forms.CheckBox();
37 | ((System.ComponentModel.ISupportInitialize)(this.registerView)).BeginInit();
38 | this.SuspendLayout();
39 | //
40 | // button1
41 | //
42 | this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
43 | this.button1.Location = new System.Drawing.Point(551, 527);
44 | this.button1.Name = "button1";
45 | this.button1.Size = new System.Drawing.Size(75, 23);
46 | this.button1.TabIndex = 0;
47 | this.button1.Text = "Start";
48 | this.button1.UseVisualStyleBackColor = true;
49 | this.button1.Click += new System.EventHandler(this.button1_Click);
50 | //
51 | // boxCode
52 | //
53 | this.boxCode.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
54 | | System.Windows.Forms.AnchorStyles.Left)
55 | | System.Windows.Forms.AnchorStyles.Right)));
56 | this.boxCode.Location = new System.Drawing.Point(12, 12);
57 | this.boxCode.Name = "boxCode";
58 | this.boxCode.Size = new System.Drawing.Size(368, 509);
59 | this.boxCode.TabIndex = 1;
60 | this.boxCode.Text = "";
61 | this.boxCode.TextChanged += new System.EventHandler(this.boxCode_TextChanged);
62 | //
63 | // registerView
64 | //
65 | this.registerView.AllowUserToAddRows = false;
66 | this.registerView.AllowUserToDeleteRows = false;
67 | this.registerView.AllowUserToResizeColumns = false;
68 | this.registerView.AllowUserToResizeRows = false;
69 | this.registerView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
70 | | System.Windows.Forms.AnchorStyles.Right)));
71 | this.registerView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
72 | this.registerView.Location = new System.Drawing.Point(386, 12);
73 | this.registerView.Name = "registerView";
74 | this.registerView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
75 | this.registerView.RowHeadersVisible = false;
76 | this.registerView.Size = new System.Drawing.Size(240, 509);
77 | this.registerView.TabIndex = 2;
78 | //
79 | // button2
80 | //
81 | this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
82 | this.button2.Location = new System.Drawing.Point(470, 527);
83 | this.button2.Name = "button2";
84 | this.button2.Size = new System.Drawing.Size(75, 23);
85 | this.button2.TabIndex = 3;
86 | this.button2.Text = "Reset";
87 | this.button2.UseVisualStyleBackColor = true;
88 | this.button2.Click += new System.EventHandler(this.button2_Click);
89 | //
90 | // button3
91 | //
92 | this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
93 | this.button3.Location = new System.Drawing.Point(389, 527);
94 | this.button3.Name = "button3";
95 | this.button3.Size = new System.Drawing.Size(75, 23);
96 | this.button3.TabIndex = 4;
97 | this.button3.Text = "Step";
98 | this.button3.UseVisualStyleBackColor = true;
99 | this.button3.Click += new System.EventHandler(this.button3_Click);
100 | //
101 | // boxNop
102 | //
103 | this.boxNop.AutoSize = true;
104 | this.boxNop.Checked = true;
105 | this.boxNop.CheckState = System.Windows.Forms.CheckState.Checked;
106 | this.boxNop.Location = new System.Drawing.Point(12, 527);
107 | this.boxNop.Name = "boxNop";
108 | this.boxNop.Size = new System.Drawing.Size(77, 17);
109 | this.boxNop.TabIndex = 5;
110 | this.boxNop.Text = "\" \" -> NOP";
111 | this.boxNop.UseVisualStyleBackColor = true;
112 | //
113 | // Form1
114 | //
115 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
116 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
117 | this.ClientSize = new System.Drawing.Size(638, 562);
118 | this.Controls.Add(this.boxNop);
119 | this.Controls.Add(this.button3);
120 | this.Controls.Add(this.button2);
121 | this.Controls.Add(this.registerView);
122 | this.Controls.Add(this.boxCode);
123 | this.Controls.Add(this.button1);
124 | this.Name = "Form1";
125 | this.Text = "Form1";
126 | this.Load += new System.EventHandler(this.Form1_Load);
127 | ((System.ComponentModel.ISupportInitialize)(this.registerView)).EndInit();
128 | this.ResumeLayout(false);
129 | this.PerformLayout();
130 |
131 | }
132 |
133 | #endregion
134 |
135 | private System.Windows.Forms.Button button1;
136 | private System.Windows.Forms.RichTextBox boxCode;
137 | private System.Windows.Forms.DataGridView registerView;
138 | private System.Windows.Forms.Button button2;
139 | private System.Windows.Forms.Button button3;
140 | private System.Windows.Forms.CheckBox boxNop;
141 | }
142 | }
143 |
144 |
--------------------------------------------------------------------------------
/mips/Cpu/mips.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows.Forms;
8 | using ExtensionMethods;
9 |
10 |
11 |
12 | namespace mips.Cpu
13 | {
14 |
15 |
16 |
17 | class mips
18 | {
19 | public registers regs = new registers();
20 |
21 | bool running = false;
22 | String instructions = "";
23 |
24 | public void start(string instructions)
25 | {
26 | running = true;
27 | regs.Reg_PC.set(0); // Definir contador de programa para o início
28 | this.instructions = instructions;
29 |
30 | while (running) //running será false quando acabar a execução
31 | {
32 | execInstruction(instructions.GetLine(regs.Reg_PC.get())); //Encontra a instrução e despacha para execução
33 | regs.Reg_PC.inc(); //Incrementa o contador de programa em 4 para próxima instrução
34 | }
35 | Finished(null,null); //Dispara o evento de termino
36 | }
37 |
38 | public void nextStep(string instructions)
39 | {
40 | running = true; // Se identificado que é a ultima instrução, será falso
41 |
42 | this.instructions = instructions;
43 |
44 | execInstruction(instructions.GetLine(regs.Reg_PC.get())); //Encontra a instrução e despacha para execução
45 | regs.Reg_PC.inc(); //Incrementa o contador de programa em 4 para próxima instrução
46 |
47 | if (!running)
48 | {
49 | regs.Reg_PC.set(0); //Zerar o contador de programa se terminado
50 | Finished(null,null);
51 | }
52 | }
53 |
54 | public EventHandler Finished = null;
55 |
56 | public void execInstruction(string line)
57 | {
58 | if(line.Contains('#')) // Separar comentarios no assembly
59 | line = line.Substring(0, line.IndexOf('#'));
60 |
61 | if (line.Length < 1) return; // Identificar linhas vazias
62 | if (line.Contains(':')) return; // Identificar labels para goto
63 |
64 | string[] splt = line.Split(' '); //Dividir a instrução para identificar registradores
65 |
66 | switch (splt[0].ToLower()) // Decodificar instrução
67 | {
68 | case "nop":
69 | break;
70 | case "noop":
71 | break;
72 |
73 | case "addi":
74 | setRegister(splt[1], getRegister(splt[2]) + Convert.ToInt32(splt[3]));
75 | break;
76 | case "add":
77 | setRegister(splt[1], getRegister(splt[2]) + getRegister(splt[3]));
78 | break;
79 |
80 | case "slt":
81 | if (getRegister(splt[2]) < getRegister(splt[3]))
82 | setRegister(splt[1], 1);
83 | else setRegister(splt[1], 0);
84 | break;
85 | case "slti":
86 | if (getRegister(splt[2]) < Convert.ToInt32(splt[3]))
87 | setRegister(splt[1], 1);
88 | else setRegister(splt[1], 0);
89 | break;
90 |
91 | case "sll":
92 | setRegister(splt[1], getRegister(splt[2]) << Convert.ToInt32(splt[3]));
93 | break;
94 | case "sllv":
95 | setRegister(splt[1], getRegister(splt[2]) << getRegister(splt[3]));
96 | break;
97 | case "srl":
98 | setRegister(splt[1], getRegister(splt[2]) >> Convert.ToInt32(splt[3]));
99 | break;
100 | case "srlv":
101 | setRegister(splt[1], getRegister(splt[2]) >> getRegister(splt[3]));
102 | break;
103 |
104 | case "sra":
105 | int temp = (int)((uint)getRegister(splt[2]) & (uint)2147483648);
106 | setRegister(splt[1], getRegister(splt[2]) >> Convert.ToInt32(splt[3]));
107 | break;
108 |
109 | case "lui":
110 | setRegister(splt[1], getRegister(splt[2]) << 16);
111 | break;
112 |
113 | case "mfhi":
114 | setRegister(splt[1], regs.Reg_HI.get());
115 | break;
116 | case "mflo":
117 | setRegister(splt[1], regs.Reg_LO.get());
118 | break;
119 |
120 | case "subi":
121 | setRegister(splt[1], getRegister(splt[2]) - Convert.ToInt32(splt[3]));
122 | break;
123 | case "sub":
124 | setRegister(splt[1], getRegister(splt[2]) - getRegister(splt[3]));
125 | break;
126 |
127 | case "div":
128 | regs.Reg_LO.set((int)(getRegister(splt[1]) / getRegister(splt[2])));
129 | regs.Reg_HI.set((int)(getRegister(splt[1]) % getRegister(splt[2])));
130 | break;
131 |
132 | case "mult":
133 | regs.Reg_LO.set((int)(getRegister(splt[1]) * getRegister(splt[2])));
134 |
135 | break;
136 |
137 | case "andi":
138 | setRegister(splt[1], getRegister(splt[2]) & Convert.ToInt32(splt[3]));
139 | break;
140 | case "and":
141 | setRegister(splt[1], getRegister(splt[2]) & getRegister(splt[3]));
142 | break;
143 |
144 | case "ori":
145 | setRegister(splt[1], getRegister(splt[2]) | Convert.ToInt32(splt[3]));
146 | break;
147 | case "or":
148 | setRegister(splt[1], getRegister(splt[2]) | getRegister(splt[3]));
149 | break;
150 |
151 | case "xori":
152 | setRegister(splt[1], getRegister(splt[2]) ^ Convert.ToInt32(splt[3]));
153 | break;
154 | case "xor":
155 | setRegister(splt[1], getRegister(splt[2]) ^ getRegister(splt[3]));
156 | break;
157 |
158 |
159 | case "beq":
160 | if (getRegister(splt[1]) == getRegister(splt[2]))
161 | {
162 | regs.Reg_PC.set(instructions.GetLine(splt[3]));
163 | }
164 | break;
165 |
166 | case "bgez":
167 | if (getRegister(splt[1]) >= 0)
168 | {
169 | regs.Reg_PC.set(instructions.GetLine(splt[2]));
170 | }
171 | break;
172 |
173 | case "bgezal":
174 | if (getRegister(splt[1]) >= 0)
175 | {
176 | regs.Reg_RA.set(regs.Reg_PC.get() * 4);
177 | regs.Reg_PC.set(instructions.GetLine(splt[2]));
178 | }
179 | break;
180 |
181 | case "bgtz":
182 | if (getRegister(splt[1]) > 0)
183 | {
184 | regs.Reg_PC.set(instructions.GetLine(splt[2]));
185 | }
186 | break;
187 |
188 | case "blez":
189 | if (getRegister(splt[1]) <= 0)
190 | {
191 | regs.Reg_PC.set(instructions.GetLine(splt[2]));
192 | }
193 | break;
194 |
195 | case "bltzal":
196 | if (getRegister(splt[1]) < 0)
197 | {
198 | regs.Reg_RA.set(regs.Reg_PC.get() * 4);
199 | regs.Reg_PC.set(instructions.GetLine(splt[2]));
200 | }
201 | break;
202 |
203 | case "bne":
204 | if (getRegister(splt[1]) != getRegister(splt[2]))
205 | {
206 | regs.Reg_PC.set(instructions.GetLine(splt[3]));
207 | }
208 | break;
209 |
210 | case "jal":
211 | regs.Reg_RA.set(regs.Reg_PC.get() * 4);
212 | int ln = instructions.GetLine(splt[1]);
213 | regs.Reg_PC.set(ln);
214 | break;
215 |
216 | case "j":
217 | regs.Reg_PC.set(instructions.GetLine(splt[1]));
218 | break;
219 |
220 | case "jr":
221 | regs.Reg_PC.set(regs.Reg_RA.get() /4);
222 | break;
223 |
224 | case "syscall":
225 | syscall();
226 | break;
227 | }
228 | }
229 |
230 | public void syscall()
231 | {
232 | switch (regs.Reg_v.get())
233 | {
234 | case 10:
235 | running = false;
236 | break;
237 | case 1:
238 | case 2:
239 | case 3:
240 | case 4:
241 | MessageBox.Show(regs.Reg_a.get().ToString());
242 | break;
243 | }
244 |
245 | }
246 |
247 | public void setRegister(string regName, int value)
248 | {
249 | char reg = regName[1];
250 | Func adct = x => Convert.ToInt32(regName[x].ToString()); //Função para pegar o nome
251 |
252 | string regnm = "";
253 |
254 | //Procurar se existe o registro no objeto CPU o registrador
255 | bool hasRegister = regs.GetType().GetFields().Count(p => p.Name.Contains(regs.Prefix + reg)) > 0;
256 | //Se não existe, adiciona o segundo caractere do nome do registrador
257 | regnm = hasRegister ? reg.ToString() : (regName[1].ToString() + regName[2].ToString()).ToUpper();
258 |
259 | //Seleciona o registrador por reflection
260 | var xei = regs.GetType().GetField(regs.Prefix + regnm).GetValue(regs) as Regs;
261 |
262 | //define o valor
263 | if (hasRegister)
264 | xei.set(value, adct(xei.defaultChar));
265 | else xei.set(value);
266 | }
267 |
268 | public int getRegister(string regName)
269 | {
270 |
271 | char reg = regName[1];
272 | Func adct = x => Convert.ToInt32(regName[x].ToString());//Função para pegar o nome
273 |
274 | string regnm = "";
275 |
276 | //Procurar se existe o registro no objeto CPU o registrador
277 | bool hasRegister = regs.GetType().GetFields().Count(p => p.Name.Contains(regs.Prefix + reg)) > 0;
278 | //Se não existe, adiciona o segundo caractere do nome do registrador
279 | regnm = hasRegister ? reg.ToString() : (regName[1].ToString() + regName[2].ToString()).ToUpper();
280 |
281 | //Seleciona o registrador por reflection
282 | var xei = regs.GetType().GetField(regs.Prefix + regnm).GetValue(regs) as Regs;
283 |
284 | //Get o valor
285 | int value = hasRegister ? xei.get(adct(xei.defaultChar)) : xei.get();
286 | return value;
287 |
288 | }
289 | }
290 |
291 | }
292 |
--------------------------------------------------------------------------------