GATE 2003 Question | CAO PYQs
This lecture covers a GATE 2003 question on assembly language programming, explaining how a hypothetical processor's code uses flags, compare instructions, and rotate-right-through-carry operations. The instructor walks through the full code execution to show the program counts the number of 1-bits in register A. Two interlinked questions from the same code snippet are solved.
Summary
The lecture begins with an introduction to a GATE 2003 assembly language question involving a hypothetical processor with three 8-bit registers: A, B, and C. The instructor explains that this is the final lecture on assembly language code practice in the 'Nirbhav Series,' which focuses only on important topics in Computer Architecture rather than covering the full course.
Before diving into the code, the instructor takes a detour to explain processor flags. Flags are described as 1-bit memory cells implemented using flip-flops, collectively stored in a Status Register (also called the Flag Register or PSW — Program Status Word). The ALU produces two outputs: the actual result and the status of that result. Key flags discussed include the Zero Flag (set when result is zero), Sign Flag (set when result is negative), Carry Flag (set when a final carry is generated), Auxiliary Carry Flag (used in BCD arithmetic), and Parity Flag. The instructor clarifies that in the 8085 microprocessor, only 5 of the 8 bits in the status register are used as flags, with 3 bits left unused.
The CMP (Compare) instruction is then explained: it performs subtraction of the two operands internally through the ALU and sets flags accordingly. If the Zero Flag is set, the two operands are equal. If the Sign Flag is set, the source operand is greater than the destination.
The instructor then traces through the assembly code step by step. Register B is initialized to 0, register C to 8. The code enters a loop at label Z: it compares C with 0, and if equal (Zero Flag set), jumps to label X — ending the loop. Otherwise, it decrements C by 1 and performs a Rotate Right Through Carry on register A by 1 bit (RRC A, #1). If the Carry Flag is set after the rotation (meaning the LSB of A was 1), it jumps to label Y where B is incremented by 1, then unconditionally jumps back to Z. If Carry is not set, it jumps directly back to Z without incrementing B.
The instructor explains that RRC moves the least significant bit (LSB) of the register into the Carry Flag each iteration. Since C starts at 8 and decrements to 1 before the loop exits (running 8 times), all 8 bits of register A are individually examined through the Carry Flag. B is incremented only when a bit is 1. Therefore, after program execution, B contains the count of 1-bits in the initial value of register A — answering Question 1 (option B).
For Question 2, the instructor asks what instruction placed at label X would restore register A to its original value after execution. Since RRC operates on a 9-bit circular shift (8 bits of register A + 1 carry bit), 8 rotations (as performed by the loop) do NOT return to the original value — 9 rotations are needed. Therefore, placing one additional RRC A, #1 instruction at location X ensures the register A returns to its initial value. The answer is option A: RRC A, #1. The instructor explicitly warns against choosing NOP (no operation), which would be correct only for a plain 8-bit rotation without the carry bit.
Key Insights
- The instructor explains that the ALU produces two outputs — the actual computation result and the status of that result — and the status is stored in the Status Register (Flag Register/PSW), which is made up of flip-flops acting as 1-bit memory cells.
- The instructor clarifies that in the 8085 microprocessor, the 8-bit status register contains only 5 active flags (Carry, Parity, Auxiliary Carry, Zero, Sign) with 3 bits unused, warning students not to assume 8 flags just because the register is 8 bits wide.
- The instructor demonstrates that Rotate Right Through Carry (RRC) on an 8-bit register effectively operates as a 9-bit circular shift (8 register bits + 1 carry flag bit), meaning 9 rotations — not 8 — are needed to restore the original register value.
- The instructor reveals that the assembly program's core function is counting the number of 1-bits in register A: each RRC operation shifts the LSB into the Carry Flag, and register B is incremented only when the Carry Flag is 1, effectively counting all set bits over 8 loop iterations.
- The instructor draws a direct parallel between the assembly CMP instruction behavior (returning zero when two values are equal) and the C language `strcmp` function, which also returns 0 when two strings are equal, to help students remember the concept through cross-subject linking.
Topics
Transcript
[0:11] हेलो एवरीवन। आज के लेक्चर में बेटा हम लोग गेट 2003 का क्वेश्चन देखेंगे। इसमें दो क्वेश्चन थे। इंटरलिंक थे आपस में। ये हमारे पास एक कोड दिया हुआ था असेंबली लैंग्वेज का और इस पे दो क्वेश्चंस पूछे हुए थे। एक क्वेश्चन ये था हमारा और एक क्वेश्चन लेट मी शो यू। एक क्वेश्चन ये था। ठीक है? इन दोनों को करना है। तो अगर आपको याद आ रहा हो तो हम लोग असेंबली लैंग्वेज के क्वेश्चंस ही प्रैक्टिस कर रहे थे। पिछले लेक्चर में भी हमने कुछ क्वेश्चंस की प्रैक्टिस करी थी। तो आज का लेक्चर बेटा ये लास्ट लेक्चर होगा। असेंबली लैंग्वेज के कोड के जितने भी प्रैक्टिस करनी है हम कर चुके हैं। और फिर…
Full transcript available for MurmurCast members
Sign Up to AccessMore from GATE CSE LECTURES BY AMIT KHURANA
Update on Test Series 🥰😍🤩
Amit Sir announces the launch of a new GATE-oriented test series with approximately 2000 quality questions covering multiple subjects. Two tests (Programming and Data Structures Test 2, Digital Test 1) have been recently uploaded, and two tests are available for free to help students evaluate the platform before purchasing.
Problem of Calculator solved🥰😍🤩
Amit Sir announces the addition of a calculator feature to his GATE test series, addressing student feedback. He emphasizes the test series' affordability (₹99), quality of questions, and commitment to providing an authentic GATE exam experience with detailed solutions and analysis.
How to see soluttion after attempting test🤔🤔
The speaker explains that detailed solutions are provided for the test series and can be accessed through a 'solution analysis' button after submitting each test. Pricing information is shared, with the test series costing ₹399 for regular users and ₹377 for existing course pack holders, along with flexible payment options for those considering upgrading to the full 12-course pack.
Launch of Test Series🥰😍🤩
Amit Khurana announces the launch of a comprehensive GATE test series containing 53 tests with 2000+ questions across 12 subjects, offered at a launch price of ₹99 with special discounts for existing students. The test series features a GATE-identical interface, feedback-driven improvements, and covers all exam topics with proper question distribution and multiple difficulty levels.
Let's meet at 7 pm 🥰😍🤩
The speaker announces the launch of a test series video releasing at 7:00 pm, revealing that audience demand through emails and messages accelerated the timeline from next year to today. The speaker emphasizes taking a significant risk with this decision and requests audience blessings and support.