]>
iEval git - clump.git/blob - asm.pm
269b8d1d49d62963131325ce32f42e95e1e0f3ca
17 use Device
::SerialPort
;
19 my $port = Device
::SerialPort
->new($ARGV[0] // '/dev/ttyUSB1') or die "$!";
21 #$port->baudrate(4000000);
22 $port->parity('none');
25 $port->handshake('none');
26 $port->read_const_time(2000);
28 $port->write_settings or die "$!";
32 use Time
::HiRes qw
/sleep/;
35 #sysopen $port, '/dev/ttyUSB1', O_SYNC | O_RDWR or die "$!";
38 use parent qw
/Exporter/;
39 our @EXPORT = qw
/loada loadb store write_verilog alu_select_a alu_select_b alu_select_f alu_zero flag_zero flag_news alu_xor alu_xnor alu_or alu_of_function aluc_add alus_add aluc_addAF alus_addAF alu2 alu3 add addC loadi storei ledm ledi route/;
40 our @EXPORT_OK = qw
/loada loadb store write_verilog alu_select_a alu_select_b alu_select_f alu_zero flag_zero flag_news alu_xor alu_xnor alu_or alu_of_function aluc_add alus_add aluc_addAF alus_addAF alu2 alu3 add addC loadi storei ledm ledi route/;
42 use File
::Slurp
::Tiny
'write_file';
50 my $binary = pack 'vCC', @cmd{qw/I mem_addr op/}; # we ignore CS for now
51 my $length = length $binary;
52 my $wrote = syswrite $port, $binary, $length;
54 # say "Wrote $wrote of $length bytes";
55 if ($cmd{op} == OP_READ) {
57 my $count_in = sysread $port, $string_in, 2;
58 my @memory = unpack 'v*', $string_in;
77 my $binary = pack 'vCC', @cmd{qw
/I mem_addr op/}; # we ignore CS for now
78 my $hex = reverse unpack 'h*', $binary;
79 say "$rom_cnt: data <= 32'h$hex;";
86 { I
=> 0, mem_addr
=> 0, op
=> OP_NOP
, CS
=> 0 }
90 my ($addr, $flagr, $bsel, $aluc) = @_;
96 { I
=> $I, mem_addr
=> $addr, op
=> OP_LOADA
, CS
=> 0 }
100 my ($addr, $cond, $inv, $alus) = @_;
106 { I
=> $I, mem_addr
=> $addr, op
=> OP_LOADB
, CS
=> 0 }
111 # send_ { I => 0, mem_addr => $addr, op => OP_READ, CS => 1 }
115 my ($addr, $flagw, $edge_, $cube) = @_;
121 { I
=> $I, mem_addr
=> $addr, op
=> OP_STORE
, CS
=> 0 }
127 { I
=> $I, mem_addr
=> $addr, op
=> OP_LOADI
, CS
=> 0 }
131 my ($addr, $dest_addr) = @_;
134 { I
=> $I, mem_addr
=> $addr, op
=> OP_ROUTE
, CS
=> 0 }
140 { I
=> $I, mem_addr
=> $addr, op
=> OP_STOREI
, CS
=> 0 }
144 my ($addr, $mode, $offset_leds) = @_;
145 my $I = $offset_leds;
148 { I
=> $I, mem_addr
=> $addr, op
=> OP_LED
, CS
=> 0 }
152 my ($addr, $offset) = @_;
153 led
$addr, 1, $offset;
164 sub flag_news
{ 8 + $_[0] }
190 sub alu_of_function
(&) {
194 local $a = ($i & 4) >> 2;
195 local $b = ($i & 2) >> 1;
197 $alu += ($fun->() ?
1 : 0) << $i;
202 sub aluc_add
{ alu_of_function
{ ($a + $b + $_) & 2 } }
203 sub alus_add
{ alu_of_function
{ ($a + $b + $_) & 1 } }
205 sub aluc_addAF
{ alu_of_function
{ ($a + $_) & 2 } }
206 sub alus_addAF
{ alu_of_function
{ ($a + $_) & 1 } }
208 sub alu_or
{ alu_of_function
{ $a | $b | $_ } }
211 my ($aluc, $alus, $addrA, $addrB, $flagr, $flagw, $cond, $inv) = @_;
212 loada
$addrA, $flagr, 0, $aluc;
213 loadb
$addrB, $cond, $inv, $alus;
214 store
$addrA, $flagw, 0, 0;
218 my ($aluc, $alus, $addrA, $addrB, $addrC, $flagr, $flagw) = @_;
219 loada
$addrA, $flagr, 0, $aluc;
220 loadb
$addrB, 0, 1, $alus;
221 store
$addrC, $flagw, 0, 0;
225 my ($addrA, $addrB, $addrC, $flag_carry) = @_;
226 alu3 aluc_add
, alus_add
, $addrA, $addrB, $addrC, flag_zero
, $flag_carry;
230 my ($addrA, $addrB, $addrC, $flag_carry) = @_;
231 alu3 aluc_add
, alus_add
, $addrA, $addrB, $addrC, $flag_carry, $flag_carry;
234 # news_gen face partea de mijloc
235 # news_[mf][mf] face primul alu3, apeleaza news_gen, apoi face ultimul alu3
237 my ($nX, $nY, $dest) = @_;
252 if ($nX || $nY) { # not the last go
253 alu3 alu_select_f
, alu_select_a
, 0, 0, 0, flag_news
($direction), flag_zero
254 } elsif (exists $dest{address
}) {
255 alu3 alu_select_f
, alu_select_f
, 0, 0, $dest{address
}, flag_news
($direction), flag_zero
256 } elsif (exists $dest{flag
}) {
257 alu3 alu_select_f
, alu_select_a
, 0, 0, 0, flag_news
($direction), $dest{flag
}
259 die "No destination address nor flag given to [news_generic]\n"
265 my ($addrIN, $addrOUT, $nX, $nY) = @_;
266 alu3 alu_select_a
, alu_select_a
, $addrIN, 0, $addrIN, flag_zero
, flag_zero
;
267 news_generic
$nX, $nY, {address
=> $addrOUT};
271 my ($addrIN, $flagOUT, $nX, $nY) = @_;
272 alu3 alu_select_a
, alu_select_a
, $addrIN, 0, $addrIN, flag_zero
, flag_zero
;
273 news_generic
$nX, $nY, {flag
=> $flagOUT};
277 my ($flagIN, $addrOUT, $nX, $nY) = @_;
278 alu3 alu_select_f
, alu_select_a
, 0, 0, 0, $flagIN, flag_zero
;
279 news_generic
$nX, $nY, {address
=> $addrOUT};
283 my ($flagIN, $flagOUT, $nX, $nY) = @_;
284 alu3 alu_select_f
, alu_select_a
, 0, 0, 0, $flagIN, flag_zero
;
285 news_generic
$nX, $nY, {flag
=> $flagOUT};
This page took 0.065781 seconds and 3 git commands to generate.