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?
ax = FFF6 h and cx = 0 h
This problem asks us to determine the final values of the ax and cx registers after executing a given assembly language program fragment. Let's break down the program line by line and trace the execution.
The program fragment is as follows:
mov ax, 0h mov cx, 0A h doloop: dec ax loop doloop
Here's what each instruction does:
Let's trace the values of ax and cx through each iteration of the loop.
Initial state:
ax = 0h
cx = 0A h (which is 10 in decimal)
The loop doloop instruction will cause the code between the doloop label and the loop instruction (which is just dec ax) to execute cx times. Since cx starts at 10, the loop body will execute 10 times.
Let's see how the register values change during the loop iterations:
| Iteration | dec ax Action | ax Value Before dec ax | ax Value After dec ax | loop doloop Action | cx Value Before loop | cx Value After loop | Jump? (cx != 0) |
|---|---|---|---|---|---|---|---|
| 1 | Decrement ax by 1 | 0000h | FFFFh ($0-1$ in 16-bit is FFFFh) | Decrement cx, check if zero | 0Ah (10) | 09h (9) | Yes |
| 2 | Decrement ax by 1 | FFFFh | FFFEh | Decrement cx, check if zero | 09h (9) | 08h (8) | Yes |
| 3 | Decrement ax by 1 | FFFEh | FFFDh | Decrement cx, check if zero | 08h (8) | 07h (7) | Yes |
| 4 | Decrement ax by 1 | FFFDh | FFC h | Decrement cx, check if zero | 07h (7) | 06h (6) | Yes |
| 5 | Decrement ax by 1 | FFC h | FFFBh | Decrement cx, check if zero | 06h (6) | 05h (5) | Yes |
| 6 | Decrement ax by 1 | FFFBh | FFFAh | Decrement cx, check if zero | 05h (5) | 04h (4) | Yes |
| 7 | Decrement ax by 1 | FFFAh | FFF9h | Decrement cx, check if zero | 04h (4) | 03h (3) | Yes |
| 8 | Decrement ax by 1 | FFF9h | FFF8h | Decrement cx, check if zero | 03h (3) | 02h (2) | Yes |
| 9 | Decrement ax by 1 | FFF8h | FFF7h | Decrement cx, check if zero | 02h (2) | 01h (1) | Yes |
| 10 | Decrement ax by 1 | FFF7h | FFF6h | Decrement cx, check if zero | 01h (1) | 00h (0) | No (loop terminates) |
Alternatively, since ax starts at 0 and is decremented 10 times, the final value can be calculated as $0 - 10$. In 16-bit two's complement representation, $0 - 10$ is equal to FFF6h.
The loop terminates when cx becomes 0. The loop instruction decrements cx from 1 down to 0, and then the loop finishes.
After the loop completes, the value of ax is FFF6h, and the value of cx is 0h.
By tracing the execution of the assembly code fragment, we found that the ax register is decremented 10 times, starting from 0, resulting in FFF6h. The cx register is used as a loop counter and is decremented from 0A h (10) down to 0, at which point the loop terminates.
| Concept | Description |
|---|---|
| Registers (AX, CX) | Small storage locations within the CPU used to hold data or addresses temporarily. AX is a general-purpose register often used for arithmetic operations. CX is often used as a counter for loops. |
| mov Instruction | Moves data from a source operand to a destination operand. Example: mov destination, source. |
| dec Instruction | Decrements the value of the operand by 1. Example: dec register. |
| loop Instruction | Decrements the CX register by 1 and jumps to a specified label if CX is not zero. |
| Hexadecimal (h) | A base-16 number system often used in assembly language. 0A h is 10 in decimal. |
| Two's Complement | A method used to represent signed numbers in binary. Decrementing 0 can result in the maximum value for the data size when using two's complement (e.g., 0000h - 1 = FFFFh for 16-bit). $0 - 10$ in 16-bit two's complement is FFF6h. |
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:
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:
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 :
This instruction is of what type?
ADD R1, A, B
The following language uses mnemonic OP codes