58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
/**
|
|
*
|
|
* @param op1 ebp+8
|
|
* @param op2 ebp+12
|
|
* @param what ebp+16
|
|
* @param flags ebp+16
|
|
* @return
|
|
*/
|
|
extern int addsub(int op1, int op2, char what, unsigned int *flags);
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc != 4) {
|
|
printf("Wrong number of arguments\n");
|
|
return -1;
|
|
}
|
|
if (*argv[2] != '+' && *argv[2] != '-') {
|
|
printf("Only the operators +/- are supported\n");
|
|
return -1;
|
|
}
|
|
|
|
|
|
int op1 = atoi(argv[1]);
|
|
int op2 = atoi(argv[3]);
|
|
char what = *argv[2];
|
|
|
|
unsigned int *flags = malloc(32);
|
|
|
|
int result = addsub(op1, op2, what, flags);
|
|
|
|
short signedRes = (short) result;
|
|
unsigned short unsignedRes = (unsigned short) result;
|
|
|
|
printf("Flags:\n");
|
|
printf("O D I T S Z A P C\n");
|
|
/*
|
|
* TODO: Interpretation wenn Fehler im ASM behoben
|
|
* https://stackoverflow.com/a/9361069
|
|
*/
|
|
|
|
printf("%d\n\n", *flags);
|
|
printf("%p\n", flags);
|
|
|
|
printf("Ergebnis und Operanden Signed:\n");
|
|
printf("%d %c %d = %d", op1, what, op2, signedRes);
|
|
|
|
printf("\n\n");
|
|
|
|
printf("Ergebnis und Operanden Unsigned:\n");
|
|
printf("%d %c %d = %u", op1, what, op2, unsignedRes);
|
|
|
|
printf("\n\n");
|
|
|
|
return 0;
|
|
} |