part2 (3382B)
1--- Part Two --- 2 3For some reason, the sea port's computer system still can't communicate with your ferry's docking 4program. It must be using [1m[37mversion 2[0m of the decoder chip! 5 6A version 2 decoder chip doesn't modify the values being written at all. Instead, it acts as a 7memory address decoder. Immediately before a value is written to memory, each bit in the bitmask 8modifies the corresponding bit of the destination [1m[37mmemory address[0m in the following way: 9 10 11 - If the bitmask bit is 0, the corresponding memory address bit is [1m[37munchanged[0m. 12 - If the bitmask bit is 1, the corresponding memory address bit is [1m[37moverwritten with 1[0m. 13 - If the bitmask bit is X, the corresponding memory address bit is [1m[37mfloating[0m. 14 15 16A [1m[37mfloating[0m bit is not connected to anything and instead fluctuates unpredictably. In 17practice, this means the floating bits will take on [1m[37mall possible values[0m, potentially 18causing many memory addresses to be written all at once! 19 20For example, consider the following program: 21 22mask = 000000000000000000000000000000X1001X 23mem[42] = 100 24mask = 00000000000000000000000000000000X0XX 25mem[26] = 1 26 27When this program goes to write to memory address 42, it first applies the bitmask: 28 29address: 000000000000000000000000000000101010 (decimal 42) 30mask: 000000000000000000000000000000X1001X 31result: 000000000000000000000000000000[1m[37mX1[0m10[1m[37m1X[0m 32 33After applying the mask, four bits are overwritten, three of which are different, and two of which 34are [1m[37mfloating[0m. Floating bits take on every possible combination of values; with two 35floating bits, four actual memory addresses are written: 36 37000000000000000000000000000000[1m[37m0[0m1101[1m[37m0[0m (decimal 26) 38000000000000000000000000000000[1m[37m0[0m1101[1m[37m1[0m (decimal 27) 39000000000000000000000000000000[1m[37m1[0m1101[1m[37m0[0m (decimal 58) 40000000000000000000000000000000[1m[37m1[0m1101[1m[37m1[0m (decimal 59) 41 42Next, the program is about to write to memory address 26 with a different bitmask: 43 44address: 000000000000000000000000000000011010 (decimal 26) 45mask: 00000000000000000000000000000000X0XX 46result: 00000000000000000000000000000001[1m[37mX[0m0[1m[37mXX[0m 47 48This results in an address with three floating bits, causing writes to [1m[37meight[0m memory 49addresses: 50 5100000000000000000000000000000001[1m[37m0[0m0[1m[37m00[0m (decimal 16) 5200000000000000000000000000000001[1m[37m0[0m0[1m[37m01[0m (decimal 17) 5300000000000000000000000000000001[1m[37m0[0m0[1m[37m10[0m (decimal 18) 5400000000000000000000000000000001[1m[37m0[0m0[1m[37m11[0m (decimal 19) 5500000000000000000000000000000001[1m[37m1[0m0[1m[37m00[0m (decimal 24) 5600000000000000000000000000000001[1m[37m1[0m0[1m[37m01[0m (decimal 25) 5700000000000000000000000000000001[1m[37m1[0m0[1m[37m10[0m (decimal 26) 5800000000000000000000000000000001[1m[37m1[0m0[1m[37m11[0m (decimal 27) 59 60The entire 36-bit address space still begins initialized to the value 0 at every address, and you 61still need the sum of all values left in memory at the end of the program. In this example, the sum 62is [1m[37m208[0m. 63 64Execute the initialization program using an emulator for a version 2 decoder chip. [1m[37mWhat is 65the sum of all values left in memory after it completes?[0m 66 67