diff options
Diffstat (limited to 'sem4')
-rw-r--r-- | sem4/embedded/emb_m2/myfloat_red.h | 69 | ||||
-rw-r--r-- | sem4/embedded/emb_m4/jrnl/regs.h | 146 |
2 files changed, 105 insertions, 110 deletions
diff --git a/sem4/embedded/emb_m2/myfloat_red.h b/sem4/embedded/emb_m2/myfloat_red.h index b553233..142d0bc 100644 --- a/sem4/embedded/emb_m2/myfloat_red.h +++ b/sem4/embedded/emb_m2/myfloat_red.h @@ -4,54 +4,51 @@ */ //low precision floating pt type -typedef struct myfloat -{ - signed char mantissa; - signed char exponent; +typedef struct myfloat { + signed char mantissa; + signed char exponent; } myfloat_type; - //convert from double to low precision type void doub2mydouble(double arg, myfloat_type *res) { - int exponent; - double temp; - exponent = ceil(log(abs(arg))/log(2)); //base 2 logarithm - temp=arg*pow(2,7-exponent); - res->mantissa = (signed char)temp; - res->exponent = exponent-7; + int exponent; + double temp; + exponent = ceil(log(abs(arg)) / log(2)); //base 2 logarithm + temp = arg * pow(2, 7 - exponent); + res->mantissa = (signed char)temp; + res->exponent = exponent - 7; } //convert from low precision type to double double myfloat2double(myfloat_type *arg1) { - double res = (double)(arg1->mantissa) * pow(2,arg1->exponent); - return res; + double res = (double)(arg1->mantissa) * pow(2, arg1->exponent); + return res; } //multiply to low precision types -void mult_float(myfloat_type *arg1,myfloat_type *arg2,myfloat_type *result) +void mult_float(myfloat_type *arg1, myfloat_type *arg2, myfloat_type *result) { - int temp; - unsigned char sign; - - sign=0x80 & ((unsigned char)arg1-> mantissa ^ (unsigned char)arg2-> mantissa); //find sign of result - - char i=0; - temp = (int)(arg1-> mantissa) * (int)(arg2-> mantissa); - - temp = temp & 0x7f00; //take away sign from product - - while(abs(temp)>128) - { - i++; - temp=temp>>1; - } - - result->mantissa = (unsigned char) temp; - - result->mantissa = result->mantissa | sign; //add recorded sign - - result->exponent = arg1->exponent + arg2->exponent + i; - + int temp; + unsigned char sign; + + sign = 0x80 & ((unsigned char)arg1->mantissa ^ + (unsigned char)arg2->mantissa); //find sign of result + + char i = 0; + temp = (int)(arg1->mantissa) * (int)(arg2->mantissa); + + temp = temp & 0x7f00; //take away sign from product + + while (abs(temp) > 128) { + i++; + temp = temp >> 1; + } + + result->mantissa = (unsigned char)temp; + + result->mantissa = result->mantissa | sign; //add recorded sign + + result->exponent = arg1->exponent + arg2->exponent + i; } diff --git a/sem4/embedded/emb_m4/jrnl/regs.h b/sem4/embedded/emb_m4/jrnl/regs.h index 3f6ae03..cd475f5 100644 --- a/sem4/embedded/emb_m4/jrnl/regs.h +++ b/sem4/embedded/emb_m4/jrnl/regs.h @@ -2,80 +2,78 @@ #define REGS_H // Taken from Jens -#define PUSHREGS() __asm__ volatile ( \ - "push r1 \n" \ - "push r0 \n" \ - "in r0, __SREG__ \n" \ - "cli \n" \ - "push r0 \n" \ - "cli \n" \ - "push r2 \n" \ - "push r3 \n" \ - "push r4 \n" \ - "push r5 \n" \ - "push r6 \n" \ - "push r7 \n" \ - "push r8 \n" \ - "push r9 \n" \ - "push r10 \n" \ - "push r11 \n" \ - "push r12 \n" \ - "push r13 \n" \ - "push r14 \n" \ - "push r15 \n" \ - "push r16 \n" \ - "push r17 \n" \ - "push r18 \n" \ - "push r19 \n" \ - "push r20 \n" \ - "push r21 \n" \ - "push r22 \n" \ - "push r23 \n" \ - "push r24 \n" \ - "push r25 \n" \ - "push r26 \n" \ - "push r27 \n" \ - "push r28 \n" \ - "push r29 \n" \ - "push r30 \n" \ - "push r31 \n" \ - ) +#define PUSHREGS() \ + __asm__ volatile("push r1 \n" \ + "push r0 \n" \ + "in r0, __SREG__ \n" \ + "cli \n" \ + "push r0 \n" \ + "cli \n" \ + "push r2 \n" \ + "push r3 \n" \ + "push r4 \n" \ + "push r5 \n" \ + "push r6 \n" \ + "push r7 \n" \ + "push r8 \n" \ + "push r9 \n" \ + "push r10 \n" \ + "push r11 \n" \ + "push r12 \n" \ + "push r13 \n" \ + "push r14 \n" \ + "push r15 \n" \ + "push r16 \n" \ + "push r17 \n" \ + "push r18 \n" \ + "push r19 \n" \ + "push r20 \n" \ + "push r21 \n" \ + "push r22 \n" \ + "push r23 \n" \ + "push r24 \n" \ + "push r25 \n" \ + "push r26 \n" \ + "push r27 \n" \ + "push r28 \n" \ + "push r29 \n" \ + "push r30 \n" \ + "push r31 \n") -#define POPREGS() __asm__ volatile ( \ - "pop r31 \n" \ - "pop r30 \n" \ - "pop r29 \n" \ - "pop r28 \n" \ - "pop r27 \n" \ - "pop r26 \n" \ - "pop r25 \n" \ - "pop r24 \n" \ - "pop r23 \n" \ - "pop r22 \n" \ - "pop r21 \n" \ - "pop r20 \n" \ - "pop r19 \n" \ - "pop r18 \n" \ - "pop r17 \n" \ - "pop r16 \n" \ - "pop r15 \n" \ - "pop r14 \n" \ - "pop r13 \n" \ - "pop r12 \n" \ - "pop r11 \n" \ - "pop r10 \n" \ - "pop r9 \n" \ - "pop r8 \n" \ - "pop r7 \n" \ - "pop r6 \n" \ - "pop r5 \n" \ - "pop r4 \n" \ - "pop r3 \n" \ - "pop r2 \n" \ - "pop r0 \n" \ - "out __SREG__, r0 \n" \ - "pop r0 \n" \ - "pop r1 \n" \ - ) +#define POPREGS() \ + __asm__ volatile("pop r31 \n" \ + "pop r30 \n" \ + "pop r29 \n" \ + "pop r28 \n" \ + "pop r27 \n" \ + "pop r26 \n" \ + "pop r25 \n" \ + "pop r24 \n" \ + "pop r23 \n" \ + "pop r22 \n" \ + "pop r21 \n" \ + "pop r20 \n" \ + "pop r19 \n" \ + "pop r18 \n" \ + "pop r17 \n" \ + "pop r16 \n" \ + "pop r15 \n" \ + "pop r14 \n" \ + "pop r13 \n" \ + "pop r12 \n" \ + "pop r11 \n" \ + "pop r10 \n" \ + "pop r9 \n" \ + "pop r8 \n" \ + "pop r7 \n" \ + "pop r6 \n" \ + "pop r5 \n" \ + "pop r4 \n" \ + "pop r3 \n" \ + "pop r2 \n" \ + "pop r0 \n" \ + "out __SREG__, r0 \n" \ + "pop r0 \n" \ + "pop r1 \n") #endif |