Computer instructions kaise follow karta hai
Program state, sequence, decisions, repetition aur language-level aur machine instruction ka difference samjhein.
Is chapter mein9 sections
Program information ke saath kaam karta hai aur waqt ke saath use badalta hai. Program follow karne ke liye poochhein: abhi kya pata hai, agla step kya hai, aur kya badlega? C ki punctuation seekhne se pehle bhi hum yeh practice kar sakte hain.
1. State relevant information ka snapshot hai
Library desk par counter imagine karein. Shuru mein zero hai; ek book return hone par one ho jata hai. Count system ki state ka hissa hai: abhi ki situation describe karne wali information. Real program ki state badi hoti hai; abhi sirf count follow karenge.
Kuch operations result calculate karte hain. Doosre stored information badalte ya outside world se interact karte hain. C objects mein changes aur output jaise kuch interactions ko side effect kehti hai. “Side” ka matlab unimportant nahi; count update karna hi step ka main purpose ho sakta hai.
2. Order meaning badal sakta hai
Yeh ordinary-language instructions hain, C nahi: count zero se shuru karo; one badhao; current value yaad rakho; phir one badhao. Final count two hai, remembered value one. Earlier value yaad rakhna har later change se permanent connection automatically nahi banata.
| Is step ke baad | Count | Remembered value |
|---|---|---|
| Start | 0 | Abhi supplied nahi |
| Ek baar badhao | 1 | Abhi supplied nahi |
| Count yaad rakho | 1 | 1 |
| Dobara badhao | 2 | 1 |
Trace selected steps aur unke baad ki state ka record hai. Isse reasoning check hoti hai. Har row logical step dikhati hai; zaroori nahi ki woh ek processor instruction ho. Compiler C ka required behavior preserve karke work combine kar sakta hai.
3. Condition ek path choose karti hai
Maan lijiye desk par maximum five returned books aa sakti hain. Ek aur lene se pehle test karein ki count five se kam hai ya nahi. Yeh test condition hai. Program jis information ko examine karta hai, usse condition next action choose karti hai.
Boundary important hai. “Five se kam” aur “maximum five” alag tests hain. Count five par pehla false aur doosra true hai. Kai errors arithmetic failure nahi, boundary ke disagreement hote hain. Symbols likhne se pehle rule define karna yeh difference notice karne mein help karta hai.
4. Loop progress kaise karti hai
Loop work repeat karta hai. Rule ho sakta hai: jab tak book available hai aur desk par room hai, book lo aur count badhao. Chaar parts follow karein: starting count, test, ek repetition ka work aur woh change jo loop ko rokega.
True continuation test ko kuch badalta hi nahi toh loop finish na ho sakta hai. Kuch systems application active rehne tak intentionally event loop run karte hain; har long-running repetition mistake nahi. Sawaal hai ki behavior specification se match karta hai aur resources aur external events correctly handle hote hain ya nahi.
5. Source instruction aur machine instruction alag hain
Source languages functions, conditions aur objects jaise concepts deti hain. CPU apne machine-level instruction set ki instructions execute karta hai, baaki system components ke support ke saath. Source statement, assembly-language line aur machine instruction ke beech universal one-to-one mapping nahi. Kuch source constructs bahut instructions banate hain; kuch optimization ke baad koi work nahi.
Common fetch–decode–execute model mein processor instruction information leta, interpret karta aur operation perform karta hai. Modern implementations internal work overlap aur reorganize kar sakti hain. Yeh introduction hai, timing diagram ya har processor ke ek instruction complete karke hi doosra dekhne ki guarantee nahi.
Aur gehra samjhein: C abstract machine
C execution samajhne ka model deti hai. Implementation machine work differently organise kar sakti hai, agar required observable behavior preserve ho. Yeh freedom language rules ke andar hai. Operation ka undefined behavior ho toh convincing trace use valid nahi banata.
6. Trace ko sahi jagah use karein
Small state table counters, conditions, loops aur value copying mein useful hai. Jo known hai woh likhein; jo establish nahi hua use unknown mark karein. Unknown entry ko convenience ke liye zero na banayein. Aage padhenge C kab zero initialization deti hai aur kab nahi.
Count four se shuru hai. Rule “count five se kam ho tab accept karo” hai, aur har acceptance one add karti hai. Test false hone se pehle kitni books accept hongi?
Explanation padhein
Ek. First successful test acceptance allow karta hai, jisse count five hota hai. Next test false hota hai. Boundary tak pahunchane wali acceptance undo nahi hoti.
Primary references aur aage ki reading
- WG14 N1570 — public C11 committee draft: Sections 5.1.2.3, 6.5, and 6.8 is C17-baseline explanation ke core rules deti hain. Yeh public draft hai, final ISO publication nahi.
Aage badhne se pehle
- State program ki current situation describe karne wali information hai.
- Trace selected steps aur state par unke effects record karta hai.
- Finish hone wale loop ko exit tak pahunchne ka reason chahiye.
In ideas ko alag rakhein
- Source step / Machine instruction
- Source-level step kai machine instructions mein map ho sakta hai ya language rules ke under optimise away ho sakta hai.
Four se five hokar rukne wale counter ko explain karne ke liye kya record karenge?
Optional: bolkar samjhein ya note rakhein. Tayyar hon toh aage badh sakte hain.Apni understanding check karein
Optional hai. Answers save ya send nahi hote; chapter kabhi lock nahi hota.
Har choice ki explanation padhein
- Haan, line breaks processor operations define karte hain.
Source layout one-to-one instruction count establish nahi karta.
- Haan, har comment ke liye ek machine instruction required hai.
Comments runtime instructions nahi hain.
- Nahi. Translation aur optimization alag arrangement bana sakti hain.
✓ Sahi reasoning. Particular machine-level trace assume karne se pehle language semantics se reason karein.
General
Agla idea padhne ke liye tayyar?
Mark this chapter as read whenever you feel ready.