a5: jetzt fehlen nur noch die Flags
This commit is contained in:
parent
f4d7832b48
commit
841c5961e0
|
@ -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
|
|
@ -1,26 +1,58 @@
|
|||
#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) {
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue