June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
69
Task/Four-bit-adder/Ring/four-bit-adder.ring
Normal file
69
Task/Four-bit-adder/Ring/four-bit-adder.ring
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
###---------------------------
|
||||
# Program: 4 Bit Adder - Ring
|
||||
# Author: Bert Mariani
|
||||
# Date: 2018-02-28
|
||||
#
|
||||
# Bit Adder: Input A B Cin
|
||||
# Output S Cout
|
||||
#
|
||||
# A ^ B => axb XOR gate
|
||||
# axb ^ C => Sout XOR gate
|
||||
# axb & C => d AND gate
|
||||
#
|
||||
# A & B => anb AND gate
|
||||
# anb | d => Cout OR gate
|
||||
#
|
||||
# Call Adder for number of bit in input fields
|
||||
###-------------------------------------------
|
||||
### 4 Bits
|
||||
|
||||
Cout = "0"
|
||||
OutputS = "0000"
|
||||
InputA = "0101"
|
||||
InputB = "1101"
|
||||
|
||||
See "InputA:.. "+ InputA +nl
|
||||
See "InputB:.. "+ InputB +nl
|
||||
BitsAdd(InputA, InputB)
|
||||
See "Sum...: "+ Cout +" "+ OutputS +nl+nl
|
||||
|
||||
###-------------------------------------------
|
||||
### 32 Bits
|
||||
|
||||
Cout = "0"
|
||||
OutputS = "00000000000000000000000000000000"
|
||||
InputA = "01010101010101010101010101010101"
|
||||
InputB = "11011101110111011101110111011101"
|
||||
|
||||
See "InputA:.. "+ InputA +nl
|
||||
See "InputB:.. "+ InputB +nl
|
||||
BitsAdd(InputA, InputB)
|
||||
See "Sum...: "+ Cout +" "+ OutputS +nl+nl
|
||||
|
||||
###-------------------------------
|
||||
|
||||
Func BitsAdd(InputA, InputB)
|
||||
nbrBits = len(InputA)
|
||||
|
||||
for i = nbrBits to 1 step -1
|
||||
A = InputA[i]
|
||||
B = InputB[i]
|
||||
C = Cout
|
||||
|
||||
S = Adder(A,B,C)
|
||||
OutputS[i] = "" + S
|
||||
next
|
||||
return
|
||||
|
||||
###------------------------
|
||||
Func Adder(A,B,C)
|
||||
|
||||
axb = A ^ B
|
||||
Sout = axb ^ C
|
||||
d = axb & C
|
||||
|
||||
anb = A & B
|
||||
Cout = anb | d ### Cout is global
|
||||
|
||||
return(Sout)
|
||||
###------------------------
|
||||
Loading…
Add table
Add a link
Reference in a new issue