3 ms·
One common interview question I've run across is to write the code for a simple four-function calculator, the kind that you can find for a dollar or two in near
by userbinator 9y ago
One common interview question I've run across is to write the code for a simple four-function calculator, the kind that you can find for a dollar or two in nearly any convenience store, right next to the pencils and erasers.
Coincidentally, I've previously posted here a detailed model/explanation of how those work: https://news.ycombinator.com/item?id=9456444 https://news.ycombinator.com/item?id=9456444
They're usually based on a 4-bit mask-ROM microcontroller running at several kHz. Very "simple" in relative terms to most computers today, and in hindsight I could probably write the code for one quite quickly, but I bet the 99% of programmers who haven't ever really given a thought to how they work in detail would struggle to come up with an accurate description in an interview.
Also worth reading: https://news.ycombinator.com/item?id=6302364 https://news.ycombinator.com/item?id=6302364
- psyc 9y agoI’m about to do a 4-bit 4 op calculator with only logic gates, for a project. Not that I could do it in an interview!
- lgas 9y agoOut of curiosity, in the description you linked you say it's a two-register model but then you mention R, O and I but only refer to O as a register. You refer to both R and I as accumulators. I assume at least one of them is also a register, but that would suggest it's a three-register model, no?
- userbinator 9y agoI meant two actual registers/accumulators (R and I) which store numbers, and O which only stores the operation being performed.
- lgas 9y agoGotcha, thanks.