From 8b5feeed96b3110967f88420d058c6e916a67f60 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Thu, 19 Dec 2024 23:12:39 +0100 Subject: assembler: Implement and add tests for operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/object.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/xixanta/src/object.rs') diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs index 8f177a1..2708647 100644 --- a/lib/xixanta/src/object.rs +++ b/lib/xixanta/src/object.rs @@ -32,6 +32,12 @@ pub struct Bundle { /// Whether the bytes on `bytes` contain the final value or not. This is /// used for internal purposes only. pub resolved: bool, + + /// Whether we have to consider the bundle to contain a negative number. + /// This comes from the fact that we just have a bunch of signednessless + /// bytes, but using the negative unary operator will give us a hint on how + /// to interpret it when needed. + pub negative: bool, } impl Bundle { @@ -52,6 +58,35 @@ impl Bundle { cycles: 0, affected_on_page: false, resolved: true, + negative: false, + } + } + + /// Returns the `bytes` field from the bundle as interpreted as bytes from a + /// regular integer. + pub fn value(&self) -> isize { + if self.negative { + isize::from_le_bytes([ + self.bytes[0], + self.bytes[1], + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + ]) + } else { + isize::from_le_bytes([ + self.bytes[0], + self.bytes[1], + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ]) } } } -- cgit v1.2.3