diff --git a/CPUKit_ASBUILT/PLD/ALU/ALU.PLD b/CPUKit_ASBUILT/PLD/ALU/ALU.PLD index 3a7fcc6..72145b5 100644 --- a/CPUKit_ASBUILT/PLD/ALU/ALU.PLD +++ b/CPUKit_ASBUILT/PLD/ALU/ALU.PLD @@ -48,9 +48,14 @@ FIELD aluop = [FUNC0..2]; /* Invert the B input bits for SUB functions */ [B0..15] = aluop:['d'0,'d'2,'d'3,'d'4,'d'5,'d'6,'d'7]&[BBUS0..15] # aluop:['d'1]&!([BBUS0..15]); -/* Setup Carry-in for addition or subtraction, and if the with carry flag is active. */ +/* Setup Carry-in for addition or subtraction, and if the with carry flag is active. + For addition, the carry bit equals 1 to indicates a carry from the previous op. + For subtraction, the carry bit equals 0 to indicate a borrow from the previous op. + This is the opposite of X86 and 68K, but the same as ARM,6502. + + */ C0 = (aluop:['d'2] & CFOut & (!ALU_WC) ) // inst=ADD: if WC==0 Cin=CF else Cin=0 - # (aluop:['d'1] & ( (!CFOut) # ALU_WC)); // inst=SUB: if WC==0 Cin=!CF else Cin=1 + # (aluop:['d'1] & ( (CFOut) # ALU_WC)); // inst=SUB: if WC==0 Cin=CF else Cin=1 P0 = A0 $ B0; G0 = A0 & B0; diff --git a/asm/pygen.py b/asm/pygen.py new file mode 100644 index 0000000..75149de --- /dev/null +++ b/asm/pygen.py @@ -0,0 +1,69 @@ +maxq=maxn=maxr=maxk=maxl=maxt=0 + +def calcPi(limit): # Generator function + """ + Prints out the digits of PI + until it reaches the given limit + """ + + q, r, t, k, n, l = 1, 0, 1, 1, 3, 3 + + + decimal = limit + counter = 0 + + while counter != decimal + 1: + if 4 * q + r - t < n * t: + # yield digit + yield n + # insert period after first digit + if counter == 0: + yield '.' + # end + if decimal == counter: + print('') + break + counter += 1 + nr = 10 * (r - n * t) + n = ((10 * (3 * q + r)) // t) - 10 * n + q *= 10 + r = nr + maxn=max(n,maxn) + maxq=max(q,maxq) + maxr=max(r,maxr) + + else: + nr = (2 * q + r) * l + nn = (q * (7 * k) + 2 + (r * l)) // (t * l) + q *= k + t *= l + l += 2 + k += 1 + n = nn + r = nr + maxn=max(n,maxn) + maxq=max(q,maxq) + maxr=max(r,maxr) + maxt=max(t,maxt) + maxl=max(l,maxl) + maxk=max(k,maxk) + + + + +# Calls CalcPi with the given limit +pi_digits = calcPi(int(input("Enter the number of decimals to calculate to: "))) + +i = 0 + +# Prints the output of calcPi generator function +# Inserts a newline after every 40th number +for d in pi_digits: + print(d, end='') + i += 1 + if i == 40: + print("") + i = 0 + + +print("n:",maxn,"q:",maxq)