a5: Dokumentation verbessert

This commit is contained in:
Johannes Theiner 2019-01-03 11:24:51 +01:00
parent ac56259ce8
commit 2aa5b91430
4 changed files with 39 additions and 26 deletions

View File

@ -7,14 +7,9 @@ flagtest.o: flagtest.c
# ASM-Modul assemblieren
addsub.o: addsub.asm
nasm -f elf -o addsub.o addsub.asm
nasm -f elf -o addsub.o addsub.asm # assemblieren
# Projekt aufraemen
clean:
@echo 'Ausgabedateien loeschen'
rm -f flagtest *.o *~

View File

@ -8,15 +8,14 @@ addsub:
mov ebp, esp
push ebx
push ecx
push edx
mov eax, 0
mov bx, word [ebp+16] ;Operation
mov ax, word [ebp+8] ;op1
mov bx, word [ebp+16] ;what
cmp bx, 0x2b
cmp bx, 0x2b;hex code for + symbol
jne substract
add ax, word [ebp+12] ;op2
@ -26,21 +25,18 @@ substract: sub ax, word [ebp+12] ;op2
return:
pushfd;Flagregister auf Stack pushen
pushfd;push flags to stack
pop edx;Flagregister in edx schreiben
pop edx;write flags to edx
mov ebx, [ebp+20]
mov ebx, [ebp+20];write flag pointer address to ebx
mov [ebx], edx
mov [ebx], edx;write flags to pointer address
pop edx
pop ecx
pop ebx
mov esp, ebp
pop ebp
ret
section .data
ret

View File

@ -2,11 +2,10 @@
#include <stdlib.h>
/**
*
* @param op1 ebp+8
* @param op2 ebp+12
* @param what ebp+16
* @param flags ebp+24
* @param flags ebp+20
* @return
*/
extern int addsub(int op1, int op2, char what, unsigned int *flags);
@ -26,24 +25,44 @@ int main(int argc, char **argv) {
int op2 = atoi(argv[3]);
char what = *argv[2];
//we need the operators both as signed and unsigned
signed short sop1 = (short) op1;
signed short sop2 = (short) op2;
unsigned short uop1 = (unsigned short) op1;
unsigned short uop2 = (unsigned short) op2;
unsigned int *flags = malloc(sizeof(unsigned int));
int result = addsub(op1, op2, what, flags);
//we also need the result as signed and unsigned
short signedRes = (short) result;
unsigned short unsignedRes = (unsigned short) result;
printf("Flags:\n");
printf("O D I T S Z A P C\n");
/*
* 0: Overflow flag
* 1: Direction flag
* 2: Interrupt enable flag
* 3: Trap flag
* 4: Signed flag
* 5: Zero flag
* 6: reserved
* 7: Auxiliary flag
* 8: reserved
* 9: Parity flag
* 10: reserved
* 11: Carry flag
*/
int flagArray[12];
//flags are saved as a decimal value, so we need to convert to binary
for(int i = 0; i < 12; ++i) {
flagArray[i] = *flags % 2;
*flags = *flags / 2;
@ -57,21 +76,24 @@ int main(int argc, char **argv) {
printf("Ergebnis und Operanden Signed:\n");
printf("%d %c %d = %d\t", sop1, what, sop2, signedRes);
if(flagArray[11] != 0)
printf("Ergebnis ist falsch!");
else
if(flagArray[0] == 0)
printf("Ergebnis ist richtig!");
else
printf("Ergebnis ist falsch!");
printf("\n\n");
printf("Ergebnis und Operanden Unsigned:\n");
printf("%u %c %u = %u\t", uop1, what, uop2, unsignedRes);
if(flagArray[0] != 0)
printf("Ergebnis ist falsch!");
else
if(flagArray[11] == 0)
printf("Ergebnis ist richtig!");
else
printf("Ergebnis ist falsch!");
printf("\n\n");

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
make
./flagtest 32769 + 2
./flagtest 32769 - 2
./flagtest 32769 - 2