diff --git a/SIMULATOR_FINAL.png b/SIMULATOR_FINAL.png new file mode 100644 index 0000000..55c35e7 Binary files /dev/null and b/SIMULATOR_FINAL.png differ diff --git a/Simulator.png b/Simulator.png new file mode 100644 index 0000000..3b40c63 Binary files /dev/null and b/Simulator.png differ diff --git a/Standard-White_2.png b/Standard-White_2.png new file mode 100644 index 0000000..4eb2b4f Binary files /dev/null and b/Standard-White_2.png differ diff --git a/Standard_2.png b/Standard_2.png new file mode 100644 index 0000000..27d8a41 Binary files /dev/null and b/Standard_2.png differ diff --git a/editor.js b/editor.js index 04abdbc..3d9d2cc 100644 --- a/editor.js +++ b/editor.js @@ -1,13 +1,15 @@ 'use strict' let editr = ace.edit('editor'); -let arrayOfStrings=[]; //<<<-------this will contain the code line by line +editr.setShowPrintMargin(false); +let arrayOfStrings=[]; //<<<-------this will contain the code line by line let memory = []; //this is the memory which is 4kB big for(let i=0;i<=4096;i++){ memory[i] = 0; } let linePointer = 0; -let Registers ={}; //this is all the registers in the risc-v +let Registers ={}; //this is all the registers in the risc-v initialiseRegisters(); +updateRegisters(); document.querySelector('.submitButton')?.addEventListener('click', function(){ @@ -16,30 +18,47 @@ function(){ memory =[]; let content1 = editor.session.getLine(0); let i = 0; - while(i < editor.session.getLength()){ + while(i < editor.session.getLength()){ //here we are getting the total lines present in the code and saving all the lines in a array of strings content1 = editor.session.getLine(i) i++; arrayOfStrings.push(content1); } for(let linePointer=0;linePointer j changed to linePointer - if(arrayOfStrings[linePointer]==="")continue - let currIndex =linePointer - console.log(linePointer); + if(arrayOfStrings[linePointer]==="")continue //this part of the code prevents the compiling the lines with no code in it + else if(IsLabel(arrayOfStrings[linePointer])){ //this part of the code checks if the line is label or not if it is a label then the compiler ignores it + continue; + } + let currIndex =linePointer //this currIndex variable keeps track of the line that we are compiling let regs=returnRegisters(arrayOfStrings[currIndex]); let instruction = returnFunction(arrayOfStrings[currIndex]); if(instruction === 'j'){ linePointer = rInstruction(instruction,returnLabel(arrayOfStrings[currIndex])); } + else if(IsBranch(instruction)){ + let temporaryPointer = rInstruction(instruction,regs[0],regs[1],regs[2]); + if(temporaryPointer === "labelNotFound"){ + console.log("labelNotFound"); + return; + } + if(temporaryPointer ===-1) continue; + else{ + linePointer = temporaryPointer; + continue; + } + } else{ rInstruction(instruction,regs[0],regs[1],regs[2]); } } console.log(Registers); - + updateRegisters(); } ) - - +document.querySelector('.resetButton').addEventListener('click',function(){ + initialiseRegisters(); + updateRegisters(); + location.reload(); +}) //<<--------------------------write testing code after this---------------------->> @@ -48,42 +67,55 @@ function(){ // <<-----------------------------------functions-------------------------------------->> +function updateRegisters(){ + let regss = Object.keys(Registers); + document.querySelector('.s1').textContent = 0; + for(let temp of regss){ + let temp1 = "."+temp; + document.querySelector(temp1).textContent = Registers[temp]; + } +} function initialiseRegisters(){ - Registers['zero'] = 0; - Registers['ra'] = 0; - Registers['sp'] = 0; - Registers['gp'] =0; - Registers['tp'] =0; - Registers['t0'] =0; - Registers['t1'] = 0; + + Registers['zero'] = 0; + Registers['ra'] = 0; + Registers['sp'] = 0; + Registers['gp'] =0; + Registers['tp'] =0; + Registers['t0'] =0; + Registers['t1'] = 0; Registers['t2'] =0; - Registers['s0'] =0; - Registers['fp'] =0; - Registers['s1'] =0; - for(let i=0;i<8;i++){ + Registers['s0'] =0; + Registers['s1'] =0; + for(let i=0;i<8;i++){ let temp1 = 'a'+i; Registers[temp1] = 0; } - for(let i=2;i<12;i++){ + for(let i=2;i<12;i++){ let temp1 = 's'+i; Registers[temp1] = 0; } for(let i=3;i<7;i++){ - let temp1 = 't'+3; + let temp1 = 't'+i; Registers[temp1] =0; } } function returnFunction(s){ let temp = ""; + let spaceCheck = false; for(let i=0;i length of arrayOfStrings or break; case "lw": break; @@ -173,8 +202,119 @@ function rInstruction(operation, register1=null,register2=null,register3=null){ return i; break; case "beq": + if(Registers[register1] === Registers[register2]){ + for(let i=0;i Registers[register2]){ + for(let i=0;i= Registers[register2]){ + for(let i=0;i RISC-V - + + + + + + + +
main: +#Input your code here
- - +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RegisterValueRegisterValue
x0 (zero) x16 (a6) -1
x1 (ra) -1x17 (a7) -1
x2 (sp)-1 x18 (s2)-1
x3 (gp) -1x19 (s3)-1
x4 (tp)-1 x20 (s4)-1
x5 (t0) -1x21 (s5)-1
x6 (t1) -1x22 (s6)-1
x7 (t2) -1x23 (s7)-1
x8 (s0) -1x24 (s8)-1
x9 (s1)-1x25 (s9) -1
x10 (a0) -1 x26 (s10)-1
x11 (a1) -1x27 (s11)-1
x12 (a2) -1x28 (t3) -1
x13 (a3) -1x29 (t4) -1
x14 (a4) -1x30 (t5) -1
x15 (a5) -1x31 (t6)-1
+ +