All Exams Test series for 1 year @ ₹349 only
Question

Consider the following assembly program fragment:

stc

mov al, 11010110b

mov cl, 2

rcl al, 3

rol al, 4

shr al, cl

mul cl

The contents of the destination register ax (in hexadecimal) and the status of Carry Flag (CF) after the execution of above instructions, are:

The correct answer is

ax = 003CH; CF = 0

Assembly Program Analysis: Determining ax and CF

Let's analyze the provided assembly program fragment instruction by instruction to determine the final state of the ax register and the Carry Flag (CF).

Analyzing the Assembly Instructions

The program fragment performs several operations on the al register, which is the lower byte of the ax register, and manipulates the Carry Flag (CF) before performing a multiplication.

  • stc: This instruction sets the Carry Flag (CF) to \(1\).
  • mov al, 11010110b: This instruction loads the immediate binary value \(11010110_2\) into the al register. In hexadecimal, \(11010110_2\) is \(D6H\). So, al becomes \(D6H\). Assuming the upper byte ah is initially \(0\), the ax register is \(00D6H\).
  • mov cl, 2: This instruction loads the immediate value \(2\) into the cl register. This value will be used as a count in subsequent shift or rotate operations.

rcl al, 3

The rcl al, 3 instruction rotates the bits of the al register to the left by \(3\) positions, including the Carry Flag (CF). The bit shifted out of the most significant bit (Bit \(7\)) goes into CF, and the original value of CF goes into the least significant bit (Bit \(0\)).

  • Initial: al = \(11010110_2\), CF = \(1\).
  • Rotation 1: Bit \(7\) (\(1\)) moves to CF. CF (\(1\)) moves to Bit \(0\). al becomes \(10101101_2\), CF becomes \(1\).
  • Rotation 2: Bit \(7\) (\(1\)) moves to CF. CF (\(1\)) moves to Bit \(0\). al becomes \(01011011_2\), CF becomes \(1\).
  • Rotation 3: Bit \(7\) (\(0\)) moves to CF. CF (\(1\)) moves to Bit \(0\). al becomes \(10110111_2\), CF becomes \(0\).

After rcl al, 3, al is \(10110111_2\) (\(B7H\)) and CF is \(0\).

rol al, 4

The rol al, 4 instruction rotates the bits of the al register to the left by \(4\) positions. The bits shifted out of the most significant bit (Bit \(7\)) wrap around and enter the least significant bit (Bit \(0\)). CF is affected by the last bit rotated out of Bit 7 (which becomes the new bit 0), but its state is not included in the rotation itself like with RCL/RCR. The Intel manual states CF gets the last bit rotated out of bit 7 for ROL. Let's check the state of AL bit 7 during rotation.

  • Initial: al = \(10110111_2\). CF = \(0\) (from previous instruction).
  • Rotation 1: Bit \(7\) (\(1\)) moves to Bit \(0\). al becomes \(01101111_2\). CF is \(1\) (bit 7 of initial value).
  • Rotation 2: Bit \(7\) (\(0\)) moves to Bit \(0\). al becomes \(11011110_2\). CF is \(0\) (bit 7 of previous step).
  • Rotation 3: Bit \(7\) (\(1\)) moves to Bit \(0\). al becomes \(10111101_2\). CF is \(1\) (bit 7 of previous step).
  • Rotation 4: Bit \(7\) (\(1\)) moves to Bit \(0\). al becomes \(01111011_2\). CF is \(1\) (bit 7 of previous step).

After rol al, 4, al is \(01111011_2\) (\(7BH\)) and CF is \(1\). Note: Some sources say ROL/ROR only affect OF, and CF is undefined or gets bit 0/7 respectively. However, common instruction set documentation indicates CF gets the last bit rotated *from* bit 7 (ROL) or *from* bit 0 (ROR). Following this, CF is \(1\).

shr al, cl

The shr al, cl instruction shifts the bits of the al register to the right logically by the count in cl (\(2\)). Zeroes are shifted into the most significant bit (Bit \(7\)), and the bits shifted out of the least significant bit (Bit \(0\)) are lost, with the last bit shifted out going into the Carry Flag (CF).

  • Initial: al = \(01111011_2\), cl = \(2\). CF = \(1\) (from previous instruction).
  • Shift 1 (by 1): Bit \(0\) (\(1\)) is shifted out. al becomes \(00111101_2\). The bit shifted out (\(1\)) would go to CF if shifting by 1.
  • Shift 2 (by 1): Bit \(0\) (\(1\), which was original Bit \(1\)) is shifted out. al becomes \(00011110_2\). The last bit shifted out (\(1\)) goes into CF.

After shr al, cl, al is \(00011110_2\) (\(1EH\)) and CF is \(1\).

mul cl

The mul cl instruction performs an unsigned multiplication of the al register by the cl register. Since the operands are \(8\)-bit registers, the result is a \(16\)-bit value stored in the ax register (ah:al).

  • al = \(1EH\) (\(30\) decimal)
  • cl = \(2\) (\(2\) decimal)
  • Product = \(30 \times 2 = 60\) decimal.
  • In hexadecimal, \(60\) decimal is \(3CH\).

The \(16\)-bit product is \(003CH\). This value is loaded into the ax register. So, ah becomes \(00H\) and al becomes \(3CH\). The mul instruction clears both the Carry Flag (CF) and the Overflow Flag (OF) if the high byte of the product (ah in this case) is zero; otherwise, it sets both flags.

Since the high byte of the product \(003CH\) is \(00H\), CF is cleared to \(0\).

After mul cl, ax is \(003CH\) and CF is \(0\).

Final State of ax and CF

After executing all the instructions, the contents of the ax register are \(003CH\) and the state of the Carry Flag (CF) is \(0\).

Matching with Options

Comparing our final state (\(ax = 003CH\), \(CF = 0\)) with the given options:

  • Option 1: ax = 003CH; CF = 0 (Matches)
  • Option 2: ax = 001EH; CF = 0 (ax is incorrect)
  • Option 3: ax = 007BH; CF = 1 (ax and CF are incorrect)
  • Option 4: ax = 00B7H; CF = 1 (ax and CF are incorrect)

Revision Table: Register and Flag Status

Instruction AL (Binary) AL (Hex) AX (Hex) CF
Initial State (Assume AX=0) Undefined Undefined 0000H Undefined
stc Undefined Undefined 0000H 1
mov al, 11010110b 11010110 D6H 00D6H 1
mov cl, 2 11010110 D6H 00D6H 1
rcl al, 3 10110111 B7H 00B7H 0
rol al, 4 01111011 7BH 007BH 1
shr al, cl (2) 00011110 1EH 001EH 1
mul cl 00111100 3CH 003CH 0

Additional Information: Assembly Instructions and Flags

  • stc (Set Carry Flag): This instruction explicitly sets the Carry Flag (CF) to 1. It does not affect any other flags or registers.
  • mov (Move): This instruction copies data from a source operand to a destination operand. It is a data transfer instruction and does not affect any flags.
  • rcl (Rotate Through Carry Left): This instruction rotates the bits of the destination operand left through the Carry Flag. The CF is treated as an extension of the destination operand. CF and OF are affected.
  • rol (Rotate Left): This instruction rotates the bits of the destination operand left. The bit rotated out of the most significant bit enters the least significant bit. CF gets the last bit rotated out of the MSB. OF is affected if rotating by 1.
  • shr (Shift Right Logical): This instruction shifts the bits of the destination operand right. Zeroes are introduced from the left. The last bit shifted out of the LSB goes into CF. OF is affected if the original MSB changes.
  • mul (Unsigned Multiply): This instruction performs an unsigned multiplication. For an 8-bit source like cl, it multiplies al by the source and stores the 16-bit result in ax (ah:al). CF and OF are set if the upper half of the product (ah) is non-zero, otherwise they are cleared. SF, ZF, AF, PF are undefined.
Was this answer helpful?

Important Questions from Machine Instructions and Addressing Modes

  1. Arrange the following types of machine in descending order of complexity.

    (A) SISD

    (B) MIMD

    (C) SIMD

    Choose the correct answer from the options given below:

  2. Consider the following program fragment in assembly language:

    mov ax, 0h

    mov cx, 0A h

    doloop:

    dec ax

    loop doloop

    What is the value of ax and cx registers after the completion of the doloop?

  3. A micro-instruction format has micro-ops field which is divided into three subfields F1, F2, F3 each having seven distinct micro-operations, condition field CD for four status bits, branch field BR having four options used in conjunction with address field ADF. The address space is of 128 memory locations. The size of micro-instruction is :  

  4. This instruction is of what type?

    ADD R1, A, B

  5. The following language uses mnemonic OP codes

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App