Module 3 · 25 मिनट पढ़ाई · मुफ़्त chapter
ALU, data-path और control unit
CPU में ALU, registers और control unit होते हैं। Single-bus data-path में ALU के आसपास registers Y और Z चाहिए, इसलिए ADD R1, R2 में छह steps लगते हैं। Hardwired control तेज़ और कठोर है, जबकि microprogrammed control, control words को control memory में रखता है और उसे बदलना आसान है।
शून्य से शुरू: reservation counter
Railway के reservation counter की तस्वीर सोचिए। यात्री खिड़की से एक form अंदर खिसकाता है, और clerk उसे पढ़कर समझता है कि क्या चाहिए। Clerk किराया निकालने के लिए calculator चलाता है, desk पर छोटी trays में notes रखता है, और सारे काग़ज़ एक ही साझा खिड़की से अंदर-बाहर करता है।
CPU भी ऐसे ही काम करता है। Request पढ़ने और हर अगला कदम तय करने वाला clerk control unit है, और calculator arithmetic logic unit (ALU) है। Trays registers हैं, यानी CPU के अंदर की छोटी और बहुत तेज़ storage, और जिस खिड़की से सब कुछ गुज़रता है, वह bus है।
Registers, ALU और buses के बीच data जिस रास्ते से चलता है, उसे data-path कहते हैं। Control unit इस रास्ते के gates को एक-एक clock step पर खोलता और बंद करता है, ताकि हर instruction पूरी हो सके। यह chapter दोनों हिस्से खोलकर दिखाता है: data को चलाने और हिसाब करने वाला data-path, और उसे निर्देश देने वाला control unit।
यह क्यों ज़रूरी है? Processor की रफ़्तार इस पर टिकी है कि हर instruction को कितने clock steps चाहिए और हर step कितना छोटा हो सकता है। ये दोनों बातें data-path और control unit तय करते हैं। इसीलिए GATE आपसे control steps गिनवाता है और control memory का size निकलवाता है।
Registers, flags और buses
कुछ registers programmer को दिखते हैं और कुछ पर्दे के पीछे काम करते हैं। Program counter (PC) अगली instruction का address रखता है, और instruction register (IR) उस instruction को रखता है जो अभी execute हो रही है। Memory address register (MAR) memory को भेजा जाने वाला address रखता है, और memory data register (MDR) वह word रखता है जो अभी पढ़ा गया है या लिखा जाने वाला है।
R0 से R31 जैसे general-purpose registers operands और results रखते हैं। Status register में ALU के set किए flags रहते हैं: result 0 हो तो zero (Z), negative हो तो sign (N), unsigned carry निकले तो carry (C), और signed overflow हो तो overflow (V)। "zero हो तो branch करो" जैसी branch instructions बस इन्हीं flags को जाँचती हैं।
CPU, memory और devices से system bus के ज़रिए बात करता है, जिसके तीन हिस्से हैं। Address bus एक ही दिशा में, CPU से बाहर की ओर चलती है, और lines से locations बता सकती है। Data bus दोनों दिशाओं में चलती है और उसकी चौड़ाई एक transfer में जाने वाले bits की संख्या है, जबकि control bus read, write, clock और interrupt के signals ले जाती है।
हल किया उदाहरण। एक processor में 32-bit address bus, 16-bit data bus और byte-addressable memory है। यह bytes, यानी 4 GB तक address कर सकता है। एक 32-bit word पढ़ने में दो bus transfers लगते हैं, क्योंकि हर transfer सिर्फ़ 16 bits ले जाता है।
यह क्यों ज़रूरी है? Bus की चौड़ाई तय करती है कि machine कितनी बड़ी memory इस्तेमाल कर सकती है और data कितनी तेज़ी से चल सकता है। Exam, address की चौड़ाई से memory का size पूछते हैं, या एक word के लिए कितने transfers लगेंगे, और दोनों जवाब इन्हीं परिभाषाओं से निकलते हैं।
Instruction cycle और micro-operations
हर instruction एक ही चक्र से गुज़रती है, जिसे instruction cycle कहते हैं। CPU instruction को fetch करता है, decode करता है, ज़रूरी operands लाता है, उसे execute करता है और result वापस लिखता है। अगला fetch शुरू करने से पहले वह देखता है कि कोई interrupt इंतज़ार तो नहीं कर रहा।
Fetch phase सभी instructions के लिए एक जैसा है और इसे register transfer notation में लिख सकते हैं, जहाँ तीर का मतलब है "इसमें यह भरा जाता है"।
Step में एक instruction की लंबाई जुड़ती है, जो 4-byte instructions और byte addresses वाली machine पर 4 होती है। PC को पहले ही बढ़ा देने से, मौजूदा instruction के execute होते समय वह अगली instruction की ओर इशारा कर रहा होता है।
ऐसा हर step एक micro-operation है, यानी वह सबसे छोटा काम जो hardware एक clock step में करता है। इसके चार प्रकार हैं: जैसा register transfer, जैसा arithmetic, AND, OR और XOR जैसे logic, और logical या arithmetic shift जैसे shifts। एक machine instruction बस micro-operations का एक छोटा क्रम है।
यह क्यों ज़रूरी है? जब आप किसी instruction को micro-operations में लिख लेते हैं, तो उसके clock steps गिन सकते हैं, देख सकते हैं कि वह कौन-से registers इस्तेमाल करती है, और उसके control signals design कर सकते हैं। GATE का हर data-path सवाल इसी आदत से शुरू होता है।
Single-bus data-path और उसके control steps
सबसे सस्ता data-path हर register और ALU को एक ही internal bus से जोड़ता है। हर register में एक "in" gate होता है, जो उसे bus से भरता है, और एक "out" gate होता है, जो उसका मान bus पर रखता है। एक clock step में सिर्फ़ एक register bus पर मान रख सकता है। इसलिए ALU को एक सहायक register Y चाहिए, जो एक operand रखे जब दूसरा bus से आए, और result पकड़ने के लिए register Z चाहिए।
4-byte instructions वाली machine पर ADD R1, R2 लीजिए, जिसका मतलब है। Control unit ऊपर के code block में दिए signals उठाता है, हर clock step की एक row है।
T1 में PC, MAR में जाता है, memory read शुरू होता है, और ALU, PC के मान में constant 4 जोड़कर Z में रखता है। T2 में नया मान PC में लौटता है और unit memory का इंतज़ार करता है (WMFC का मतलब है "wait for memory function complete")। T3 में instruction, MDR से IR में जाती है। T4 से T6 में R1, Y में copy होता है, उसमें R2 जुड़ता है, और Z वापस R1 में लिखा जाता है, इसलिए पूरी instruction में छह steps लगते हैं।
हल किया उदाहरण। 2 ns के clock पर, अगर memory T2 के अंदर जवाब दे दे, तो ADD R1, R2 में ns लगते हैं। ADD R1, [R2] जैसी instruction अपना दूसरा operand memory से पढ़ती है। उसे R2 को MAR में भेजने और word का इंतज़ार करने के लिए अतिरिक्त steps चाहिए, इसलिए उसमें 8 steps, यानी 16 ns लग सकते हैं।
यह क्यों ज़रूरी है? Single bus से hardware छोटा रहता है, जो सरल controllers के लिए ठीक है, लेकिन लगभग हर transfer को अपना अलग step लेना पड़ता है। GATE ऐसे क्रम देकर पूछता है कि instruction में कितने steps लगेंगे या कौन-सा signal छूट गया है।
Two-bus और three-bus data-paths
| Data-path | ADD R1, R2, R3 के execute steps | Hardware की लागत |
|---|---|---|
| Single bus | 3, Y और Z के साथ | सबसे कम: एक bus, हर register पर एक port |
| Two buses | 2, एक temporary register के साथ | मध्यम |
| Three buses | 1 | सबसे ज़्यादा: दो read ports और एक write port |
Single bus एक पतली सड़क जैसी है, इसलिए सीधा उपाय है ज़्यादा lanes बनाना। Two-bus data-path में एक bus registers से मान बाहर ले जाती है और दूसरी results वापस लाती है। इसलिए एक ही step में एक register से मान निकल सकता है और दूसरे register में result जा सकता है। Three-bus data-path और आगे जाता है, जिसमें buses A और B, ALU के दोनों inputs भरती हैं और bus C result वापस लाती है।
तीन buses के साथ के लिए सिर्फ़ एक execute step चाहिए: R2, bus A पर जाता है, R3, bus B पर, ALU जोड़ता है, और R1, bus C से भर जाता है। अब temporary registers Y और Z की ज़रूरत नहीं रहती। Fetch phase भी छोटा हो जाता है, क्योंकि PC को उसके अपने adder से बढ़ाया जा सकता है।
हल किया उदाहरण। एक program में 10⁶ register-to-register add instructions चलती हैं। 3 fetch steps और ऊपर के execute steps जोड़ें, तो single-bus machine को हर instruction में 6 steps चाहिए। Three-bus machine को लगभग 4 steps चाहिए, अगर उसका fetch अब भी 3 steps लेता है। 1 ns के clock पर कुल समय 6 ms और 4 ms है, यानी एक-तिहाई की बचत।
यह क्यों ज़रूरी है? हर आधुनिक processor multi-port register file और कई buses इस्तेमाल करता है, क्योंकि हर instruction के steps घटाना रफ़्तार बढ़ाने का सबसे सस्ता तरीका है। Steps और wiring के बीच का यह सौदा लिखित papers में तुलना का पसंदीदा सवाल है।
Hardwired और microprogrammed control
| Feature | Hardwired | Microprogrammed |
|---|---|---|
| Speed | तेज़, signals सीधे gates से आते हैं | धीमा, हर step में control memory पढ़नी पड़ती है |
| Instructions बदलना या जोड़ना | मुश्किल, फिर से design करना पड़ता है | आसान, microprogram फिर से लिखिए |
| किसके लिए ठीक | RISC, कम और सरल instructions | CISC, बहुत सी जटिल instructions |
| बड़े set के लिए design की मेहनत | ज़्यादा और ग़लती की संभावना वाली | व्यवस्थित |
Control unit को हर instruction के लिए सही step पर सही signals उठाने होते हैं। इसे बनाने के दो तरीके हैं। फ़र्क़ वैसा ही है जैसे एक clerk को हर प्रक्रिया ज़बानी याद हो, और दूसरा हर कदम नियमों की किताब में देखकर करे।
Hardwired control unit एक logic circuit है। Step counter T1, T2, T3 गिनता है, decoder, IR के opcode को एक चालू line में बदल देता है, और gates इन्हें flags के साथ मिलाकर हर control signal बनाते हैं। जैसे, signal Zin का logic expression हो सकता है।
Microprogrammed control unit हर step के signals का pattern एक word के रूप में रखता है, जिसे microinstruction कहते हैं। ये words एक छोटी और तेज़ control memory में रहते हैं। Control address register, जिसे micro-program counter भी कहते हैं, मौजूदा word की ओर इशारा करता है, और एक instruction के words का क्रम उसका microprogram है। तब किसी instruction को बदलने के लिए gates की wiring नहीं, बल्कि control memory के words बदलने पड़ते हैं।
यह क्यों ज़रूरी है? यह चुनाव RISC और CISC के बँटवारे के साथ चलता है, इसलिए exam अक्सर दोनों तुलनाएँ साथ पूछते हैं। इसी से यह भी समझ आता है कि कुछ processors की instruction वाली ग़लतियाँ microcode के update से ठीक क्यों हो सकीं।
Horizontal और vertical microcode: control-memory numericals
Microinstruction कितनी चौड़ी हो? Horizontal microcode में हर control signal को अपना अलग bit मिलता है, इसलिए 40 signals वाली machine में 40 signal bits होते हैं। एक step में signals का कोई भी मेल चल सकता है और कुछ भी decode नहीं करना पड़ता, लेकिन words चौड़े हो जाते हैं।
Vertical microcode में जो signals कभी साथ नहीं चलते, उन्हें एक field में रखकर encode कर दिया जाता है। ऐसे signals के समूह के field को bits चाहिए, जहाँ एक अतिरिक्त code का मतलब है "इनमें से कोई नहीं"। Words पतले हो जाते हैं, लेकिन हर field को एक decoder चाहिए, जिससे देरी बढ़ती है, और एक साथ कम signals चल पाते हैं।
हर word में sequencing के fields भी चाहिए। words की control memory के next-address field को bits चाहिए, और conditions में से चुनने वाले condition-select field को bits चाहिए।
हल किया उदाहरण। एक CPU में 40 control signals हैं, जो 7, 15, 10 और 8 signals के चार ऐसे समूहों में बँटते हैं जिनके signals आपस में साथ नहीं चलते। उसकी control memory में 512 microinstructions हैं। दोनों formats में next-address field को bits चाहिए।
Vertical fields की चौड़ाई , , और से आती है। यानी vertical coding आधी से ज़्यादा control memory बचा लेती है, और इसकी क़ीमत चार decoders हैं।
अगर इसी machine को 4 flags में से किसी पर या हमेशा branch करना हो, तो condition field को 5 हालात में से चुनना होगा। इसके लिए हर word में bits और चाहिए।
यह क्यों ज़रूरी है? Control memory का size निकालना GATE का नियमित numerical है, और इसमें बस दो जाल हैं: ceiling और "कोई नहीं" वाला code। असली designs दोनों तरीके मिलाते हैं। वे कुछ समूहों को encode करते हैं और ज़रूरी signals को अलग-अलग bits पर छोड़ देते हैं।
Descriptive lens: लिखित paper यह कैसे पूछते हैं
Engineering services, IT officer पदों और राज्य Assistant Programmer परीक्षाओं के लिखित paper इस topic को चार तरह से पूछते हैं:
- Single-bus data-path बनाकर समझाना और दी गई instruction का control sequence लिखना।
- Single-bus और multi-bus organisations की हर instruction के steps और hardware लागत के आधार पर तुलना करना।
- Hardwired और microprogrammed control units की, हर एक के block diagram के साथ, तुलना करना।
- Horizontal और vertical formats के लिए microinstruction की चौड़ाई और control memory का size निकालना।
अभ्यास सवाल (हमारे अपने, पिछले वर्षों के सवाल नहीं)।
- Single-bus data-path बनाइए और SUB R3, R4 के control steps लिखिए, registers Y और Z की भूमिका समझाते हुए। (10 अंक)
- Hardwired और microprogrammed control की पाँच बिंदुओं पर तुलना कीजिए, और बताइए कि RISC processor के लिए कौन-सा ठीक है और क्यों। (10 अंक)
- एक processor में 64 control signals हैं, जो 15, 31, 10 और 8 के ऐसे समूहों में हैं जिनके signals साथ नहीं चलते, और 1,024 microinstructions हैं। Horizontal और vertical formats में word की चौड़ाई और control memory का size निकालिए। (15 अंक)
सवाल 3 का answer plan।
- लिखिए कि horizontal coding में हर signal का एक bit है, इसलिए signal वाला हिस्सा 64 bits चौड़ा है।
- Next-address field को bits निकालिए, जो दोनों formats में चाहिए।
- Horizontal word को bits और memory को bits लिखिए।
- Vertical fields को , , और निकालिए, जिनका जोड़ हर समूह में "कोई नहीं" code मिलाकर 17 bits है।
- Vertical word को bits और memory को bits लिखिए।
- निष्कर्ष लिखिए कि vertical coding लगभग 63 प्रतिशत control memory बचाती है, लेकिन इसे चार decoders चाहिए और parallelism कम मिलता है।
Quick revision
- CPU में ALU, registers और control unit होते हैं, और flags Z, N, C और V, ALU के results दर्ज करते हैं।
- Address bus एक दिशा वाली है और lines से locations बताती है, जबकि data bus दोनों दिशाओं वाली है।
- Fetch में पहले होता है, फिर PC बढ़ने के साथ memory read, और फिर ।
- Micro-operations हैं register transfers, arithmetic, logic और shifts, और हर एक एक clock step में होता है।
- Single-bus data-path में ALU के आसपास Y और Z चाहिए, और ADD R1, R2 में छह steps लगते हैं।
- Three-bus data-path, को एक execute step में कर देता है।
- Hardwired control तेज़ और कठोर है, जबकि microprogrammed control धीमा और लचीला है।
- Horizontal microcode में हर signal का एक bit होता है, और vertical microcode में signals के हर समूह को bits मिलते हैं।
- Control memory का size, words की संख्या गुणा word की चौड़ाई है, जिसमें next-address और condition fields भी शामिल हैं।