Commit 3e1e76a9 authored by George Hotz's avatar George Hotz

add tests passing

parent 971a7bde
...@@ -3,6 +3,7 @@ pragma solidity ^0.7.3; ...@@ -3,6 +3,7 @@ pragma solidity ^0.7.3;
// https://inst.eecs.berkeley.edu/~cs61c/resources/MIPS_Green_Sheet.pdf // https://inst.eecs.berkeley.edu/~cs61c/resources/MIPS_Green_Sheet.pdf
// https://uweb.engr.arizona.edu/~ece369/Resources/spim/MIPSReference.pdf // https://uweb.engr.arizona.edu/~ece369/Resources/spim/MIPSReference.pdf
// https://en.wikibooks.org/wiki/MIPS_Assembly/Instruction_Formats
// This is a separate contract from the challenge contract // This is a separate contract from the challenge contract
// Anyone can use it to validate a MIPS state transition // Anyone can use it to validate a MIPS state transition
...@@ -117,6 +118,8 @@ contract MIPS { ...@@ -117,6 +118,8 @@ contract MIPS {
// TODO: replace with table // TODO: replace with table
if (opcode == 8) { opcode = 0; func = 0x20; } // addi if (opcode == 8) { opcode = 0; func = 0x20; } // addi
else if (opcode == 9) { opcode = 0; func = 0x21; } // addiu else if (opcode == 9) { opcode = 0; func = 0x21; } // addiu
else if (opcode == 0xa) { opcode = 0; func = 0x2a; } // slti
else if (opcode == 0xb) { opcode = 0; func = 0x2B; } // sltiu
else if (opcode == 0xc) { opcode = 0; func = 0x24; } // andi else if (opcode == 0xc) { opcode = 0; func = 0x24; } // andi
else if (opcode == 0xd) { opcode = 0; func = 0x25; } // ori else if (opcode == 0xd) { opcode = 0; func = 0x25; } // ori
else if (opcode == 0xe) { opcode = 0; func = 0x26; } // xori else if (opcode == 0xe) { opcode = 0; func = 0x26; } // xori
...@@ -133,7 +136,7 @@ contract MIPS { ...@@ -133,7 +136,7 @@ contract MIPS {
return rs-rt; // sub or subu return rs-rt; // sub or subu
} else if (func == 0x2a) { } else if (func == 0x2a) {
return int32(rs)<int32(rt) ? 1 : 0; // slt return int32(rs)<int32(rt) ? 1 : 0; // slt
} else if (func == 0x26) { } else if (func == 0x2B) {
return rs<rt ? 1 : 0; // sltu return rs<rt ? 1 : 0; // sltu
// Shift and ShiftV // Shift and ShiftV
} else if (func == 0x00) { return rt << shamt; // sll } else if (func == 0x00) { return rt << shamt; // sll
......
...@@ -213,13 +213,16 @@ func main() { ...@@ -213,13 +213,16 @@ func main() {
// 19.100079097s for 1_000_000 new steps // 19.100079097s for 1_000_000 new steps
//steps := 1000000 //steps := 1000000
//debug = true //debug = true
files, err := ioutil.ReadDir("test/bin") files, err := ioutil.ReadDir("test/bin")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
for _, f := range files { for _, f := range files {
runTest("test/bin/"+f.Name(), 20, interpreter, bytecode) runTest("test/bin/"+f.Name(), 100, interpreter, bytecode)
} }
/*debug = true
runTest("test/bin/add.bin", 20, interpreter, bytecode)*/
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment