public static WordField LoadFromRegister(FieldSpec fieldSpec, Register register) { int fieldSpecByteCount = fieldSpec.ByteCount; if (fieldSpecByteCount > register.ByteCountWithPadding) { throw new ArgumentOutOfRangeException(nameof(fieldSpec), fieldSpec, "bytecount too large for this register"); } var field = new WordField(fieldSpec, fieldSpecByteCount); int fromRegisterStartIndex = register.ByteCountWithPadding - fieldSpecByteCount; fieldSpecByteCount--; while (fieldSpecByteCount >= 0) { field[fieldSpecByteCount] = register.GetByteWithPadding(fromRegisterStartIndex + fieldSpecByteCount); fieldSpecByteCount--; } if (fieldSpec.IncludesSign) { field.Sign = register.Sign; } return(field); }
public static WordField LoadFromFullWord(FieldSpec fieldSpec, IFullWord word) { int fieldSpecByteCount = fieldSpec.ByteCount; var field = new WordField(fieldSpec, fieldSpecByteCount); int lowBoundByteIndex = fieldSpec.LowBoundByteIndex; for (int i = 0; i < fieldSpecByteCount; i++) { field[i] = word[lowBoundByteIndex + i]; } if (fieldSpec.IncludesSign) { field.Sign = word.Sign; } return(field); }
WordField(FieldSpec fieldSpec, int byteCount) : base(byteCount) { mFieldSpec = fieldSpec; }