diff --git a/.gitignore b/.gitignore index 20fba2b..4606bfb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea bin cmake-build-debug +CMakeFiles diff --git a/src/c/a5/addsub.asm b/src/c/a5/addsub.asm index 43cc8bc..f6a6ee3 100644 --- a/src/c/a5/addsub.asm +++ b/src/c/a5/addsub.asm @@ -9,6 +9,7 @@ addsub: push ebx push ecx + push edx mov eax, 0 @@ -29,13 +30,23 @@ return: 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 + ;FIXME: Hier wird an die falsche Stelle oder so geschrieben + mov ebx, [ebp+24] + mov [ebx], edx + + ;mov [ebp+24], edx;Flagregister aus edx in flags ptr aus C kopieren + ;mov word[ebp+24], 32 + + pop edx pop ecx pop ebx mov esp, ebp pop ebp - ret \ No newline at end of file + ret + +section .data + +temp dw 0 \ No newline at end of file diff --git a/src/c/a5/flagtest.c b/src/c/a5/flagtest.c index d7aefa0..1abb63b 100644 --- a/src/c/a5/flagtest.c +++ b/src/c/a5/flagtest.c @@ -6,12 +6,11 @@ * @param op1 ebp+8 * @param op2 ebp+12 * @param what ebp+16 - * @param flags ebp+16 + * @param flags ebp+24 * @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"); @@ -27,7 +26,9 @@ int main(int argc, char **argv) { int op2 = atoi(argv[3]); char what = *argv[2]; - unsigned int *flags = malloc(32); + unsigned int *flags = malloc(sizeof(unsigned int)); + //TODO: DEBUG Statement, remove later + *flags = 42; int result = addsub(op1, op2, what, flags); @@ -36,12 +37,14 @@ int main(int argc, char **argv) { 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("%u\n\n", *flags); printf("%p\n", flags); printf("Ergebnis und Operanden Signed:\n"); diff --git a/src/c/a5/run.sh b/src/c/a5/run.sh new file mode 100755 index 0000000..f4a2b1e --- /dev/null +++ b/src/c/a5/run.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +make +./flagtest 32769 + 2 +./flagtest 32769 - 2