Last change
on this file since 357 was 2, checked in by Rick van der Zwet, 15 years ago |
Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)
|
-
Property svn:executable
set to
*
|
File size:
1.7 KB
|
Line | |
---|
1 | /* Author : Rick van der Zwet
|
---|
2 | * S-number : 0433373
|
---|
3 | * Version : $Id: alu.c 364 2007-12-03 07:23:37Z rick $
|
---|
4 | * Copyright : FreeBSD Licence
|
---|
5 | * Description : ALU unit
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <stdlib.h>
|
---|
9 | #include <stdio.h>
|
---|
10 | #include <sysexits.h>
|
---|
11 | #include "alu.h"
|
---|
12 |
|
---|
13 | word
|
---|
14 | alu_sra(const word in1, const word in2)
|
---|
15 | {
|
---|
16 | word out = 0;
|
---|
17 | out = in1 >> in2;
|
---|
18 | /* Find out wether high order bit was set */
|
---|
19 | if (in1 >> (BITSIZE(out) - 1) == 0x1) {
|
---|
20 | /* Set bit in2 till high-order to 1 */
|
---|
21 | int i = BITSIZE(out) - in2;
|
---|
22 | for (; i < BITSIZE(out); i++)
|
---|
23 | out = out | (1 << i);
|
---|
24 | }
|
---|
25 | return (out);
|
---|
26 | }
|
---|
27 |
|
---|
28 | word
|
---|
29 | alu(word in1, word in2, alu_control_t action)
|
---|
30 | {
|
---|
31 | word out = 0;
|
---|
32 | switch (action) {
|
---|
33 | case ADD:
|
---|
34 | out = in1 + in2;
|
---|
35 | break;
|
---|
36 | case AND:
|
---|
37 | out = in1 & in2;
|
---|
38 | break;
|
---|
39 | case NOR:
|
---|
40 | out = ~(in1 | in2);
|
---|
41 | break;
|
---|
42 | case OR:
|
---|
43 | out = in1 | in2;
|
---|
44 | break;
|
---|
45 | case PassS1:
|
---|
46 | out = in1;
|
---|
47 | break;
|
---|
48 | case PassS2:
|
---|
49 | out = in2;
|
---|
50 | break;
|
---|
51 | case SLL:
|
---|
52 | out = in1 << in2;
|
---|
53 | break;
|
---|
54 | case SRA:
|
---|
55 | out = alu_sra(in1, in2);
|
---|
56 | break;
|
---|
57 | case SRL:
|
---|
58 | out = in1 >> in2;
|
---|
59 | break;
|
---|
60 | case SUB:
|
---|
61 | out = in1 - in2;
|
---|
62 | break;
|
---|
63 | case XOR:
|
---|
64 | out = in1 ^ in2;
|
---|
65 | break;
|
---|
66 | default:
|
---|
67 | fprintf(stderr,"Requested alu-action not implemented\n");
|
---|
68 | exit(EX_SOFTWARE);
|
---|
69 | break;
|
---|
70 | };
|
---|
71 |
|
---|
72 | /* Set signals */
|
---|
73 | if (out < 0) {
|
---|
74 | zero = FALSE;
|
---|
75 | negative = TRUE;
|
---|
76 | } else if (out == 0) {
|
---|
77 | zero = TRUE;
|
---|
78 | negative = FALSE;
|
---|
79 | } else {
|
---|
80 | zero = FALSE;
|
---|
81 | negative = FALSE;
|
---|
82 | }
|
---|
83 |
|
---|
84 | return(out);
|
---|
85 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.