Closed philbudne closed 4 years ago
I tried to compile this file using as
from the image:
o20: 020
o21: 021
o22: 022
o23: 023
o24: 024
o25: 025
o26: 026
o27: 027
o28: 028
o29: 029
o30: 030
0;0;0;0;0
no20: -020
no21: -021
no22: -022
no23: -023
no24: -024
no25: -025
no26: -026
no27: -027
no28: -028
no29: -029
no30: -030
0;0;0;0;0
as expected it the a.out
looks like this:
@ od a.out
000000: 000020 000021 000022 000023 000024 000025 000026 000027
000010: 000030 000031 000030 000000 000000 000000 000000 000000
000020: 777760 777757 777756 777755 777754 777753 777752 777751
000030: 777750 777747 777750 000000 000000 000000 000000 000000
@
When experimenting I came up with this change that makes as7
behave
similar to as
. Moreover my change looks show some similarities to the one
you propose
diff --git a/tools/as7 b/tools/as7
--- a/tools/as7
+++ b/tools/as7
@@ -445,6 +445,15 @@ sub parse_line {
} # while
}
+sub as_oct {
+ my $oct = shift;
+ my $value = 0;
+ for my $c (split //, $oct) {
+ $value = $value * 8 + $c;
+ }
+ return $value;
+}
+
# Blame Phil for this bit too...
# Parse an expression off $line and return a PDP-7 word
# as a series of whitespace separated "syllables"
@@ -514,7 +523,7 @@ sub parse_expression {
my $value = $1;
printf "\tfound constant: $value\n" if ($debug);
if ( $value =~ m{^0} ) {
- $syllable = oct($value);
+ $syllable = as_oct($value);
}
else {
$syllable = $value + 0;
Compiling my test code above using as7
with your commit appears to
produce the same output as as
on target so it looks safe to merge.
Alternative to changing "bad" octal constants in source files, such as one in st7.s: https://github.com/DoctorWkt/pdp7-unix/pull/224