add addi print test
This commit is contained in:
parent
756410e5b4
commit
3b17ffcaa6
@ -1,3 +1,5 @@
|
|||||||
|
#[allow(non_snake_case)] // supprimer le warning snake case (quand les noms de variables ont des majuscules)
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Instruction {
|
pub struct Instruction {
|
||||||
pub value : u64,
|
pub value : u64,
|
||||||
|
|
||||||
@ -26,6 +28,7 @@ pub struct Instruction {
|
|||||||
pub imm21_1_signed : i32,
|
pub imm21_1_signed : i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(non_snake_case)]
|
||||||
pub fn decode(val : u64) -> Instruction {
|
pub fn decode(val : u64) -> Instruction {
|
||||||
|
|
||||||
let value = val;
|
let value = val;
|
||||||
|
21
src/print.rs
21
src/print.rs
@ -260,16 +260,16 @@ pub fn print(ins: Instruction, pc: i32) -> String { //TODO pc should be u64
|
|||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod Test {
|
mod test {
|
||||||
use crate::{print, decode};
|
use crate::{print, decode};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test1() {
|
fn test_op() {
|
||||||
let sub = decode::decode(0b01000001000010001000111000110011);
|
let sub = decode::decode(0b0100000_10000_10001_000_11100_0110011);
|
||||||
let add = decode::decode(0b00000001000010001000111000110011);
|
let add = decode::decode(0b0000000_10000_10001_000_11100_0110011);
|
||||||
let xor = decode::decode(0b00000001000010001100111000110011);
|
let xor = decode::decode(0b0000000_10000_10001_100_11100_0110011);
|
||||||
let slr = decode::decode(0b00000001000010001101111000110011);
|
let slr = decode::decode(0b0000000_10000_10001_101_11100_0110011);
|
||||||
let sra = decode::decode(0b01000001000010001101111000110011);
|
let sra = decode::decode(0b0100000_10000_10001_101_11100_0110011);
|
||||||
|
|
||||||
assert_eq!("sub r28, r17, r16", print::print(sub, 0));
|
assert_eq!("sub r28, r17, r16", print::print(sub, 0));
|
||||||
assert_eq!("xor r28, r17, r16", print::print(xor, 0));
|
assert_eq!("xor r28, r17, r16", print::print(xor, 0));
|
||||||
@ -278,4 +278,11 @@ mod Test {
|
|||||||
assert_eq!("add r28, r17, r16", print::print(add, 0));
|
assert_eq!("add r28, r17, r16", print::print(add, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_opi() {
|
||||||
|
let addi = decode::decode(0b0000000000_10001_000_11100_0010011);
|
||||||
|
assert_eq!("addi x28, x17, 0", print::print(addi, 0));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user