@Test public void testSubtract() { Assert.assertEquals(10, space.subtract(addr(1, 32), addr(1, 22))); Assert.assertEquals(-16, space.subtract(addr(5, 0), addr(5, 16))); Assert.assertEquals(0, space.subtract(addr(3, 12), addr(3, 12))); Assert.assertEquals(0, space.subtract(addr(2, 0), addr(0, 32))); Assert.assertEquals(16, space.subtract(addr(1, 0), addr(0, 0))); Assert.assertEquals(-16, space.subtract(addr(0, 0), addr(1, 0))); SegmentedAddressSpace sp2 = new SegmentedAddressSpace("SpaceTwo", 2); SegmentedAddress addr2 = new SegmentedAddress(sp2, 0, 0); try { space.subtract(addr(0, 0), addr2); Assert.fail("Subtract should have failed!"); } catch (IllegalArgumentException e) { } Assert.assertEquals(addr(4, 2), space.subtract(addr(4, 5), 3)); Assert.assertEquals(addr(0, 0x2f), space.subtract(addr(3, 0), 1)); Assert.assertEquals(addr(13, 9), space.subtract(addr(13, 5), -4)); try { Assert.assertEquals(addr(0, 0), space.subtract(addr(0, 0), 0x100000)); Assert.fail(); } catch (AddressOutOfBoundsException e) { } try { Assert.assertEquals(addr(0, 2), space.subtractNoWrap(addr(0, 5), 3)); Assert.assertEquals(addr(3, 9), space.subtractNoWrap(addr(3, 5), -4)); } catch (AddressOverflowException e) { Assert.fail(e.getMessage()); } try { space.subtractNoWrap(addr(0, 5), 0x10000); Assert.fail("Should not have gotten a value!"); } catch (AddressOverflowException e) { } }
@Override public Address subtract(Address addr, long displacement) { if (displacement < 0) { return add(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } long off = addr.getOffset() - displacement; if (off >= 0) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address subtract(Address addr, long displacement) { if (displacement < 0) { return add(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } long off = addr.getOffset() - displacement; if (off >= 0) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address subtract(Address addr, long displacement) { if (displacement < 0) { return add(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } long off = addr.getOffset() - displacement; if (off >= 0) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } SegmentedAddressSpace(String name, int unique); }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address subtract(Address addr, long displacement) { if (displacement < 0) { return add(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } long off = addr.getOffset() - displacement; if (off >= 0) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } SegmentedAddressSpace(String name, int unique); @Override Address getAddress(String addrString); @Override Address getAddress(String addrString, boolean caseSensitive); @Override Address subtract(Address addr, long displacement); @Override Address add(Address addr, long displacement); @Override SegmentedAddress getAddress(long byteOffset); @Override SegmentedAddress getAddressInThisSpaceOnly(long byteOffset); SegmentedAddress getAddress(int segment, int segmentOffset); @Override SegmentedAddressSpace getPhysicalSpace(); @Override int getPointerSize(); }
SegmentedAddressSpace extends GenericAddressSpace { @Override public Address subtract(Address addr, long displacement) { if (displacement < 0) { return add(addr, -displacement); } testAddressSpace(addr); if (displacement > spaceSize) { throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } long off = addr.getOffset() - displacement; if (off >= 0) { SegmentedAddress saddr = (SegmentedAddress) addr; return new SegmentedAddress(this, off).normalize(saddr.getSegment()); } throw new AddressOutOfBoundsException( "Address Overflow in subtract: " + addr + " + " + displacement); } SegmentedAddressSpace(String name, int unique); @Override Address getAddress(String addrString); @Override Address getAddress(String addrString, boolean caseSensitive); @Override Address subtract(Address addr, long displacement); @Override Address add(Address addr, long displacement); @Override SegmentedAddress getAddress(long byteOffset); @Override SegmentedAddress getAddressInThisSpaceOnly(long byteOffset); SegmentedAddress getAddress(int segment, int segmentOffset); @Override SegmentedAddressSpace getPhysicalSpace(); @Override int getPointerSize();  }