a5: jetzt fehlen nur noch die Flags

This commit is contained in:
Johannes Theiner 2018-12-30 14:09:53 +01:00
parent f4d7832b48
commit 841c5961e0
2 changed files with 51 additions and 11 deletions

View File

@ -7,7 +7,8 @@ addsub:
push ebp push ebp
mov ebp, esp mov ebp, esp
push bx push ebx
push ecx
mov eax, 0 mov eax, 0
@ -23,11 +24,18 @@ addsub:
substract: sub ax, word [ebp+12] ;op2 substract: sub ax, word [ebp+12] ;op2
return: 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 mov esp, ebp
pop ebp pop ebp
ret ret
section .data
operation dw 2

View File

@ -1,6 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.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); extern int addsub(int op1, int op2, char what, unsigned int *flags);
@ -9,18 +17,42 @@ int main(int argc, char **argv) {
printf("Wrong number of arguments\n"); printf("Wrong number of arguments\n");
return -1; return -1;
} }
if (*argv[2] != '+' && *argv[2] != '-') {
printf("Only the operators +/- are supported\n");
return -1;
}
int op1 = atoi(argv[1]); int op1 = atoi(argv[1]);
int op2 = atoi(argv[3]); int op2 = atoi(argv[3]);
char what = *argv[2]; char what = *argv[2];
unsigned int * flags = NULL; unsigned int *flags = malloc(32);
int result = addsub(op1, op2, what, flags); int result = addsub(op1, op2, what, flags);
short signedRes = (short) result;
unsigned short unsignedRes = (unsigned short) result;
printf("%d\n", result); printf("Flags:\n");
printf("%u\n", result); 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; return 0;
} }