aboutsummaryrefslogtreecommitdiff
path: root/src/isa/mod.rs
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2015-12-20 14:59:22 -0500
committerDavid Li <li.davidm96@gmail.com>2015-12-20 14:59:22 -0500
commit80c073a5c4a992598ecaf36c58d2294f6aa766d0 (patch)
tree416a845f3055e38005545f9c87b2b6445c878cf9 /src/isa/mod.rs
parent8ca42acf1a92ac0d811bbeecf8aed25a8c2d5a30 (diff)
Implement JAL, JALR
Diffstat (limited to 'src/isa/mod.rs')
-rw-r--r--src/isa/mod.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/isa/mod.rs b/src/isa/mod.rs
index 0e3261b..c8aa290 100644
--- a/src/isa/mod.rs
+++ b/src/isa/mod.rs
@@ -127,9 +127,18 @@ impl Instruction {
}
pub fn s_imm(&self) -> i32 {
- let word = self.word as i32;
- let low = (word >> 7) & 0x1F;
- let high = (word >> 25) & 0x7F;
+ let low = (self.word >> 7) & 0x1F;
+ let high = ((self.word as i32) >> 25) & 0x7F;
(high << 7) | low
}
+
+ pub fn uj_imm(&self) -> i32 {
+ // Want zero-extension
+ let low1 = (self.word >> 21) & 0x3FF;
+ let low11 = (self.word >> 19) & 0x1;
+ let low12 = (self.word >> 12) & 0xFF;
+ // Want sign-extension
+ let low20 = ((self.word as i32) >> 30) & 0x1;
+ (low20 << 20) | (low12 << 12) | (low11 << 11) | (low1 << 1)
+ }
}