From 841c5961e089d3fcc065d9b64576579d6b26fc00 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sun, 30 Dec 2018 14:09:53 +0100 Subject: [PATCH] a5: jetzt fehlen nur noch die Flags --- src/c/a5/addsub.asm | 22 +++++++++++++++------- src/c/a5/flagtest.c | 40 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/c/a5/addsub.asm b/src/c/a5/addsub.asm index ee81f70..43cc8bc 100644 --- a/src/c/a5/addsub.asm +++ b/src/c/a5/addsub.asm @@ -7,7 +7,8 @@ addsub: push ebp mov ebp, esp - push bx + push ebx + push ecx mov eax, 0 @@ -23,11 +24,18 @@ addsub: substract: sub ax, word [ebp+12] ;op2 return: - pop bx + + pushfd;Flagregister auf Stack pushen + + pop edx;Flagregister in edx schreiben + + ;TODO: Hier wird an die falsche Stelle oder so geschrieben + mov [ebp+20], edx;Flagregister aus edx in flags ptr aus C kopieren + + + pop ecx + pop ebx + mov esp, ebp pop ebp - ret - -section .data - -operation dw 2 \ No newline at end of file + ret \ No newline at end of file diff --git a/src/c/a5/flagtest.c b/src/c/a5/flagtest.c index ec206ec..d7aefa0 100644 --- a/src/c/a5/flagtest.c +++ b/src/c/a5/flagtest.c @@ -1,26 +1,58 @@ #include #include +/** + * + * @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) { + 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 = NULL; + unsigned int *flags = malloc(32); int result = addsub(op1, op2, what, flags); + short signedRes = (short) result; + unsigned short unsignedRes = (unsigned short) result; - printf("%d\n", result); - printf("%u\n", 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; } \ No newline at end of file