I'm trying to implement the following nor flip flop circuit logic in Go and having some difficulty with variable declarations:
My goal is to simulate the logic gates and circuitry as it would physically work. I've implemented a function for the nor gates [func nor()] and the flip flop itself [func norFlipFlop()]. The issue I'm facing is in declaring out0 and out1 since they depend on each other. As can be seen below out0 is defined as nor(a1, out1) and out1 is defined as nor(out0, a0). This obviously spits out a compilation error since out1 is not yet initialized and defined when out0 is defined. Is there a way to make this logic work while keeping it as close to the physical circuit logic as possible?
func nor(a int, b int) int {
if a + b == 0 {
return 1
} else {
return 0
}
}
func norFlipFlop(a1 int, a0 int) (int, int) {
out0 := nor(a1, out1)
out1 := nor(out0, a0)
return out1, out0
}
func main() {
out1, out0 := norFlipFlip(1, 1)
out := fmt.Sprint(out1, out0)
fmt.Println(out)
}