[][src]Struct pir_8_emu::isa::GeneralPurposeRegister

pub struct GeneralPurposeRegister { /* fields omitted */ }

There are eight 8-bit General Purpose registers, each has an internal address for use within the CPU, instructions like MOVE and LOAD can use these addresses.

All the registers will start with an initial value of 0.

There are eight 8-bit General Purpose registers, each has an internal address for use within the CPU, instructions like MOVE and LOAD can use these addresses. The first five registers have some special functionality, as described, the last three have no special functionality. The last four registers can also be used with the stack.

AddressLetterDescription
000FFlag register (can also be used to get a zero value)
001SOutput of the ALU - ALU operations will overwrite any value stored
010XInput to ALU (Only input for unary operations)
011YSecond input for ALU
100APort number for PORT instruction
101B
110C
111D

Flag register

The flag register can be be read and written to as a general purpose register, though keep in mind that ALU and Compare instructions can effect the value of the flags.

Not all of the bits have a specified role (yet), though the CLRF operation will still clear them.

A value of 1 denotes the flag as 'set', whilst a value of 0 denotes the flag is 'unset'.

Below is a description of what each bit in the flag register denotes.

BitLetterDescription
0ZZero flag
1CCarry flag
2PParity (even number of set bits)
3EEquals flag
4GGreater than
5
6
7

Methods

impl GeneralPurposeRegister[src]

pub fn new(address: u8, letter: char) -> Option<GeneralPurposeRegister>[src]

Create a new, empty register named as specified.

Examples

let x = GeneralPurposeRegister::new(0b010, 'X').unwrap();
assert_eq!(*x, 0);
assert_eq!(x.address(), 0b010);
assert_eq!(x.letter(), 'X');

assert_eq!(GeneralPurposeRegister::new(0b1000, 'Q'), None);

pub fn address(self) -> u8[src]

The address for this register

Limited to 3 bits' width

pub fn letter(self) -> char[src]

The letter/mnemonic for this register

E.g. "X"

pub fn relabel(&mut self, to_letter: char) -> Result<(), ()>[src]

Change this register's letter to the specified one

Will return Err(()) if the letter isn't ASCII

impl GeneralPurposeRegister[src]

pub fn defaults() -> GeneralPurposeRegisterBank[src]

Get the default 8 GP registers specified in the ISA

pub fn from_letters(s: &str) -> Result<GeneralPurposeRegisterBank, i8>[src]

Create a GP register bank from letters contained within the specified string

The string must be 8-ASCII-characters-long.

If it's shorter, Err(-1) is returned, if it's longer, Err(8) is returned, if character for register at address AAA is non-ASCII, Err(AAA) is returned,

Examples

assert_eq!(GeneralPurposeRegister::from_letters("FSXYABCD"), Ok(GeneralPurposeRegister::defaults()));

Trait Implementations

impl Clone for GeneralPurposeRegister[src]

impl Copy for GeneralPurposeRegister[src]

impl Debug for GeneralPurposeRegister[src]

impl Deref for GeneralPurposeRegister[src]

type Target = u8

The resulting type after dereferencing.

impl DerefMut for GeneralPurposeRegister[src]

impl Display for GeneralPurposeRegister[src]

impl Eq for GeneralPurposeRegister[src]

impl Hash for GeneralPurposeRegister[src]

impl Ord for GeneralPurposeRegister[src]

impl PartialEq<GeneralPurposeRegister> for GeneralPurposeRegister[src]

impl PartialOrd<GeneralPurposeRegister> for GeneralPurposeRegister[src]

impl ReadWritable for GeneralPurposeRegister[src]

impl StructuralEq for GeneralPurposeRegister[src]

impl StructuralPartialEq for GeneralPurposeRegister[src]

Auto Trait Implementations

impl RefUnwindSafe for GeneralPurposeRegister

impl !Send for GeneralPurposeRegister

impl !Sync for GeneralPurposeRegister

impl Unpin for GeneralPurposeRegister

impl UnwindSafe for GeneralPurposeRegister

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.