Let's remember what a transponder code is used for in the first place.
When transmitting a non-discrete code, such as 1200, ATC has no way1 of telling you apart from other aircraft transmitting the same code. On the ATC radar, you will simply show up as something like "1200/A030" where 1200 is the code transmitted and A030 (3000FT) is you mode C altitude.
To provide you with radar service, ATC has to be able to identify you on the radar, which means that they have to be able to distinctly associate your flight with a specific track on the radar. They do this using transponder codes2. An assigned (discrete) transponder code will be unique for a flight within a given area. Say you are instructed to squawk 2174, you will now show up on the screen as "2174/A030", and because ATC knows that you, and no one else in the area, is squawking 2174, they know that they are you looking at you.
Your question is, how does ATC keep track of the assigned transponder codes? Today this is mostly an automated process. A central flight data processing system (or the US equivalent - sorry for my European terminology) contains a database of all active flightplans as well as their assigned transponder codes. When a discrete transponder code is received by the ATM system, it will automatically query this database, asking for any flightplan information associated with this specific transponder code. It will then show the received information on the radar screen. Essentially, the transponder code is a database key, allowing the system to look up information about your flight and show it to the controller.
Now you are no longer shown on the radar with just your transponder code and mode C altitude, because the system has a lot more information about you. You might be shown as something like "N12345/A030/C172" (callsign/altitude/aircraft type). The exact label varies greatly from system to system - the point here being that the system is now able to show specific information from your flightplan rather than just generic information submitted by your transponder.
So how does a controller know if you have been assigned a transponder code or not? If you have, you will be shown on their radar screen as a full label, with callsign etc. If not, your callsign is no where to be found on the radar, and they will have to guess that you are probably one of the (potentially many) 1200-tracks on the screen.
1: They can in fact identify you by other means, such as requesting your exact position and heading, but identification with the help of transponder is a lot simpler.
2: Normal 4-digit transponder codes are slowly being replaced by mode-S transponders, which transmit a unique 24-bit aircraft identifier at all times to the radar system. But that's probably best left for another question.