stripped everything down - starting from scratch. reading obj file works

This commit is contained in:
vik 2024-12-31 21:39:26 -06:00
parent df6caea574
commit 0f9980425c
3 changed files with 18 additions and 59 deletions

BIN
helloworld Normal file

Binary file not shown.

View File

@ -1,63 +1,22 @@
const PC_START: u16 = 0x3000;
#[allow(dead_code)]
enum Registers {
R0 = 0,
R1,
R2,
R3,
R4,
R5,
R6,
R7,
PC,
COND,
COUNT
}
#[allow(dead_code)]
enum Opcodes {
// https://www.cs.utexas.edu/~fussell/courses/cs310h/lectures/Lecture_10-310h.pdf
ADD = 0, // add
AND, // and
NOT, // not (bitwise)
LD, // load (pc relative)
LDI, // load indirect
LDR, // load base + offset
LEA, // load immediate
ST, // store pc relative
STR, // store base + offset
STI, // store indirect
BR, // branch
JSR, // jump register
JMP, // jump
RTI, // return from interrupt (unused)
TRAP, // trap
}
#[allow(dead_code)]
enum ConditionFlags {
POS = 1 << 0,
ZERO = 1 << 1,
NEG = 1 << 2,
}
mod mem;
use std::env;
use std::fs;
use std::io;
use std::io::Read;
fn main() {
let _memory:[u16; 1 << 16] = [0; 1 << 16];
let mut registers:[u16; Registers::COUNT as usize] = [0; Registers::COUNT as usize];
registers[Registers::COND as usize] = ConditionFlags::ZERO as u16;
registers[Registers::PC as usize] = PC_START;
// set running state
let mut running:bool = true;
while running {
let index: u16 = registers[Registers::PC as usize];
let mut instr:u16 = _memory[index as usize];
registers[Registers::PC as usize] += 1;
match instr >> 12 {
op if op == Opcodes::ADD as u16 => todo!(),
_ => todo!(),
}
let args: Vec<String> = env::args().collect();
let path = args.get(1).expect("enter a file please!");
let file = fs::File::open(path).expect("couldnt open file");
let mut reader = io::BufReader::new(file);
let mut values = Vec::new();
let mut buffer:[u8;2] = [0;2];
while reader.read_exact(&mut buffer).is_ok() {
let instruction = u16::from_be_bytes(buffer);
values.push(instruction);
}
println!("data: {:?}\n", values);
for data in values{
println!("hex data: {:#06X}", data);
}
}

0
src/mem.rs Normal file
View File