Added a div instruction and changed some of the debug outputs in a7out.

This commit is contained in:
Warren Toomey
2016-03-07 20:12:40 +10:00
parent 54947581cd
commit a7f040b8f5
+23 -7
View File
@@ -7,7 +7,7 @@
use strict; use strict;
use warnings; use warnings;
use Fcntl qw(:seek); use Fcntl qw(:seek);
#use DateTime; use DateTime;
use Data::Dumper; use Data::Dumper;
### Global variables ### ### Global variables ###
@@ -421,12 +421,12 @@ sub opr {
dprintf(" cla"); dprintf(" cla");
$AC = 0; $AC = 0;
} }
if ( $instruction & 004000 ) { # cli if ( $instruction & 004000 ) { # cll
dprintf(" cli"); dprintf(" cll");
$LINK = 0; $LINK = 0;
} }
if ( $instruction & 000002 ) { # cmi if ( $instruction & 000002 ) { # cml
dprintf(" cmi"); dprintf(" cml");
$LINK = ($LINK) ? 0 : LINKMASK; $LINK = ($LINK) ? 0 : LINKMASK;
} }
if ( $instruction & 000001 ) { # cma if ( $instruction & 000001 ) { # cma
@@ -489,7 +489,8 @@ sub eae {
if ( $instruction == 0653323 ) { # idiv: integer division if ( $instruction == 0653323 ) { # idiv: integer division
my $divisor= $Mem[ $PC+1 ]; my $divisor= $Mem[ $PC+1 ];
dprintf( "div AC %06o AC by %06o (decimal %d by %d)\n", $AC, $divisor, $AC, $divisor ); dprintf( "idiv AC %06o by %06o (decimal %d by %d)\n",
$AC, $divisor, $AC, $divisor );
# Prevent division by zero :-) # Prevent division by zero :-)
my $quotient = ($divisor) ? $AC / $divisor : 0; my $quotient = ($divisor) ? $AC / $divisor : 0;
my $remainder = ($divisor) ? $AC % $divisor : 0; my $remainder = ($divisor) ? $AC % $divisor : 0;
@@ -498,6 +499,21 @@ sub eae {
$PC+=2; $PC+=2;
return; return;
} }
if ( $instruction == 0640323 ) { # div: 36-bit unsigned integer division
my $divisor= $Mem[ $PC+1 ];
dprintf( "div MQ.AC %06o.%06o AC by %06o (decimal %d)\n",
$MQ, $AC, $divisor, $divisor );
# http://www.perlmonks.org/?node_id=718414 says that we won't
# lose accuracy before 2^53
my $dividend= ($MQ << 18) | $AC;
# Prevent division by zero :-)
my $quotient = ($divisor) ? $dividend / $divisor : 0;
my $remainder = ($divisor) ? $dividend % $divisor : 0;
$MQ= $quotient;
$AC= $remainder;
$PC+=2;
return;
}
if ( $maskedinstr == 0660500 ) { # lrss: long right shift, signed if ( $maskedinstr == 0660500 ) { # lrss: long right shift, signed
# We ignore the MQ as it's not # We ignore the MQ as it's not
# used by any user-mode programs # used by any user-mode programs
@@ -1093,7 +1109,7 @@ sub sys_time {
# Set MQ to the high 18 bits and AC to the low 18 bits # Set MQ to the high 18 bits and AC to the low 18 bits
$MQ = $sixtieths >> 18; $MQ = $sixtieths >> 18;
$AC = $sixtieths & 0777777; $AC = $sixtieths & 0777777;
dprintf( "time %06o %06o\n", $MQ, $AC ); dprintf( "time %06o %06o, %d sixtieths\n", $MQ, $AC, $sixtieths );
$PC += 1; $PC += 1;
return; return;
} }