☕ Java Two's complement, need help

Status
Not open for further replies.

fireclouu

Fanatic
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.

Similar threads

About this Thread

  • 1
    Replies
  • 430
    Views
  • 1
    Participants
Last reply from:
fireclouu

Trending Topics

Online now

Members online
1,051
Guests online
9,345
Total visitors
10,396

Forum statistics

Threads
2,354,240
Posts
29,382,837
Members
1,079,383
Latest member
PHC_CallMe
Back
Top