What's new

Java Two's complement, need help

Status
Not open for further replies.

fireclouu

Honorary Poster
Joined
Jun 1, 2014
Posts
438
Solutions
1
Reaction
152
Points
196
Hello! May marunong po ba dito mag-perform ng two complement? Bali gumagawa po kasi ako ng intel 8080 emulation, pwede niyo po icheck sa git ko clouu-27 (pakitanggal na lang dash :) ), sa CpuEmulation.java, sa CMP method, eto partial:
Java:
private void CMP(int var) {

        // Need to perform two-complement to achieve such result        // a + (two comp. immediate)

        // complement — defined also as "another set" e.g. another set of binary 1 is binary 0!

        // similar to a - immediate

        // int twoComp = ((~opbyte & 0xff) + 1);

        int res = A.value - var;

       

        Z.flag = (res == 0) ? (byte) 1 : 0;

        S.flag = ((res & 0x80) == 0x80) ? (byte) 1 : 0;

        P.flag = parityFlag(res);  // ensuring only checks for 8-bit variable

        CY.flag = (res > 0xff ) ? 1 : (byte) 0;

        AC.flag = (res > 0x9) ? (byte) 1 : 0;

    }

workaround implementation po yung A.value - var;

kaya po need ng twos comp eh para makuha yung flags, (carry, zero, etc), tumingin na po ako sa internet kaso di ko talaga gets 'yung two's comp, ang alam ko lang "addition to subtract" raw, di ako makaadvance hehe. Thanks!
 
Status
Not open for further replies.
Back
Top