Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 44 additions & 208 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@uiw/react-codemirror": "^4.19.9",
"aos": "^2.3.4",
"axios": "^1.4.0",
"codemirror": "^5.65.18",
"framer-motion": "^10.3.1",
"gsap": "^3.11.5",
"prop-types": "^15.8.1",
Expand Down
1 change: 1 addition & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function App() {
</img>

<Routes>
<Route exact path='/profile' element={<Profile />}/>
<Route exact path="/" element={<Hero/>}/>
<Route exact path="/ide" element={<Ide currentUser={currentUser}/>}/>
<Route exact path="/archi" element={<Arch/>}/>
Expand Down
Binary file added src/Emulator.zip
Binary file not shown.
51 changes: 9 additions & 42 deletions src/Emulator/ALU.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class Alu{

subBinary(size){
//get the two's complement of the content of the RUAL2:
console.log("RUAL2 Value befor anything "+this.Rual2.value);

//than the one's complement of the result :
let i=this.Rual2.value.length-1;
Expand All @@ -136,19 +135,14 @@ class Alu{
i--;
}
this.Rual2.setvalue(b);
console.log("Ones complement of RUAL2 "+this.Rual2.value);

//first we add (RAL2)+1
//first we add (RAL2)+1
let x=1;
let res1=parseInt(this.Rual2.getvalue(),2);
res1=res1+x;
this.Rual2.setvalue(fullzero(size,res1.toString(2)));
b=this.Rual2.getvalue()//very important on overflow detection
console.log("Tows complement of RUAL2 "+this.Rual2.value);
//then the simple binary addition between RUAL1 and RUAL2:
this.addBinary(size)
console.log("The result of subsrtaction "+ this.Acc.getvalue());

this.addBinary(size)
//overflow detection:
if (this.Rual1.getvalue()[0]!=b[0]) {
if (b[0]==this.Acc.getvalue()[0]) {
Expand All @@ -165,9 +159,7 @@ class Alu{


binaryMultiply(size) {
let binaryString1=(this.Rual1.getvalue()).substring(0,size);
console.log("string1 :"+binaryString1);

let binaryString1=(this.Rual1.getvalue()).substring(0,size);
//two's complement of the abs part of a
if(this.Rual1.getvalue()[0]=='1'){
let i=size;
Expand All @@ -186,9 +178,7 @@ class Alu{
}
}
let binaryString2=this.Rual2.getvalue().substring(0,size);//verifier
console.log("string2 :"+binaryString2);

//two's complement of the abs part of b
//two's complement of the abs part of b
if(this.Rual2.getvalue()[0]=='1'){
let i=size;
let find1=false
Expand All @@ -207,18 +197,13 @@ class Alu{
}

let int1 = parseInt(binaryString1, 2)
console.log(int1)
let int2 = parseInt(binaryString2, 2)
console.log(int2)
let res= (int1 * int2).toString(2);
console.log(res);
if(res.length>=16 ){res=fullzero(32,res)}
else{ res=fullzero(16,res)}
if (this.Rual1.getvalue()[0]==this.Rual2.getvalue()[0]) {
console.log("positive result")

}else{
console.log("negative result");
let find1=false
for (let i = res.length; i >=0; i--) {
if(find1==true){
Expand All @@ -234,7 +219,6 @@ class Alu{
}
}

console.log(res);
if(res.length>16){
let resacc=res.substring(16,32);
this.Acc.setvalue(resacc);
Expand All @@ -261,9 +245,7 @@ class Alu{

DivBinary(size){

let binaryString1=(this.Rual1.getvalue()).substring(1,size);
console.log("string1 :"+binaryString1);

let binaryString1=(this.Rual1.getvalue()).substring(1,size);
//two's complement of the abs part of a
if(this.Rual1.getvalue()[0]=='1'){
let i=size;
Expand All @@ -282,8 +264,6 @@ class Alu{
}
}
let binaryString2=this.Rual2.getvalue().substring(1,size);
console.log("string2 :"+binaryString2);

//two's complement of the abs part of b
if(this.Rual2.getvalue()[0]=='1'){
let i=size;
Expand All @@ -303,21 +283,15 @@ class Alu{
}

let int1 = parseInt(binaryString1, 2)
console.log(int1)
let int2 = parseInt(binaryString2, 2)
console.log(int2)
let q= (Math.floor(int1 / int2)).toString(2);
console.log("le quotient en valeur absolue :"+q);
let r=(int1 % int2).toString(2)
q=fullzero(size,q);
console.log("quotient before two's complement "+q);
r=fullzero(size,r);
//positive or negativ quotient
if (this.Rual1.getvalue()[0]==this.Rual2.getvalue()[0]) {
console.log("positive quotient ")


}else{
console.log("negative quotient");
let find1=false
for (let i =q.length; i >=0; i--) {
if(find1==true){
Expand All @@ -337,9 +311,7 @@ class Alu{
//positive or negative reste

if(this.Rual1.getvalue()[0]=='0') {
console.log("positive reste ")
}else{
console.log("negative rete");
}else{
let find1=false
for (let i =r.length; i >=0; i--) {
if(find1==true){
Expand All @@ -361,13 +333,8 @@ class Alu{
//this.Flags[2]=carry.toString();//carry
let figure="1"
this.Flags[3] = ((this.Acc.value.match(new RegExp(figure, "g")) || []).length %2).toString();//parity
this.Flags[4]=this.Acc.getvalue()[size-1];//p/imp

console.log("le quotient :" +q);

console.log("le reste en valeur absolue: "+r);

this.Acc.setvalue(q);
this.Flags[4]=this.Acc.getvalue()[size-1];//p/imp
this.Acc.setvalue(q);

return r;

Expand Down
64 changes: 56 additions & 8 deletions src/Emulator/IO_Unit.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
import { generalPurposeRegister } from "./Register.js";

class IOUnit {
constructor(buffer) {
this.buffer = buffer;
constructor() {
// Buffer with 50 slots, initially empty
this.buffer = new Array(50).fill(null).map(() => ({ value: null, filled: false }));

this.ioController = {
status: "idle",
transferInProgress: false,
};
}
getBuffer() {
return this.buffer;

// Write data into the buffer
writeToBuffer(index, value) {
if (index < 0 || index >= this.buffer.length) {
console.error(`Invalid index: ${index}. Must be between 0 and ${this.buffer.length - 1}`);
return;
}

this.buffer[index].value = value;
this.buffer[index].filled = true;

console.log(`Value "${value}" written to buffer slot ${index}`);
}
setBuffer(buffer) {
this.buffer = buffer;

// Read data while ignoring truly empty slots
readFromBuffer() {
const bufferString = this.buffer
.filter(slot => slot.filled) // Keep only filled slots
.map(slot => slot.value) // Extract values
.join("");

console.log(`Buffer content (excluding empty columns): "${bufferString}"`);
return bufferString;
}
write() {
console.log(this.buffer);
convertCharToASCII(index) {
if (index >= 0 && index < this.buffer.length) {
const asciiValue = this.buffer[index].toString().charCodeAt(0) || 0;
console.log(`Character at index ${index}: ${this.buffer[index]}, ASCII: ${asciiValue}`);
return asciiValue;
} else {
console.error("Index out of bounds");
return null;
}
}
writeASCIIToBuffer(asciiValue, index) {
if (index >= 0 && index < this.buffer.length) {
this.buffer[index] = String.fromCharCode(asciiValue);
console.log(`Stored character '${this.buffer[index]}' at index ${index} from ASCII ${asciiValue}`);
} else {
console.error("Index out of bounds");
}
}
emptyBuffer() {
this.buffer.forEach(slot => {
slot.value = 0; // Reset value to 0
slot.filled = false; // Mark as empty
});

}
}
export default IOUnit;
Loading