Last active
April 23, 2021 07:07
-
-
Save mmagm/0674dd13260b16befa69d5b854f59474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
int main(void) { | |
int8_t ms[] = { | |
0x50, | |
0x50, | |
0x50, | |
0x50, | |
0xD0, | |
0xD0, | |
0xD0, | |
0xD0 | |
}; | |
int8_t ns[] = { | |
0x10, | |
0x50, | |
0x90, | |
0xD0, | |
0x10, | |
0x50, | |
0x90, | |
0xD0 | |
}; | |
int result = 0; | |
bool overflow = 0; | |
bool carry = 0; | |
bool m7 = 0; | |
bool n7 = 0; | |
bool c6 = 0; | |
bool c7 = 0; | |
bool s7 = 0; | |
for (int i = 0; i < 8; i++) { | |
result = (ms[i] + ns[i]) & 0xFF; | |
overflow = (ms[i] ^ result) & (ns[i] ^ result) & 0x80; | |
m7 = ms[i] & 0x80; | |
n7 = ns[i] & 0x80; | |
c6 = (ms[i] & 0x40) & (ns[i] & 0x40); | |
c7 = (m7 & n7) | (c6 & (m7 | n7)); | |
s7 = result & 0x80; | |
printf("%5d %5d %5d | %5d %5d %5d | ", m7, n7, c6, c7, s7, overflow); | |
printf("%5hhu + %5hhu = %5hhu | ", ms[i], ns[i], result); | |
printf("%5hhd + %5hhd = %5hhd | ", ms[i], ns[i], result); | |
printf("%5hhx + %5hhx = %5hhx \n", ms[i], ns[i], result); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment