Consider the following fragment of assembly code array dw 7
Consider the following fragment of assembly code: array dw 7, 6, 5, 4 count dw 4 ... xor ax, ax stc mov cx, count mov si, offset array;offset converts PTR to NUMBER label1: adc ax, word ptr [si];si will point to 1st element of \"array\" add si, 2 loop labell label2: What will be the value in AX when control reaches label2? What is the purpose of the line: xor ax, ax Write an efficient and functionally equivalent code segment for the line: loop label1
Solution
Ans(a):The loop starting at lable1 will be executed 4 times as cx is initialised as 4 by putting count in it.As loop executes each time ,value of AX will be:
AX = AX + Array[SI] + CF
AX = 0 + 7 + 1 = 8
AX = 8 + 6 + 0 = 14
AX = 14 + 5 + 0 = 19
AX = 19 + 4 + 0 = 23 or 17h
after execution of loop value of AX will be 23 or 17h.
Ans(b)
ax here is a register and applying xor operation over it ,will set it to 0.
Ans (c)
loop label1
DEC CX
CMP CX, 0
JNZ label1
CX will be set to count and we will decrement CX with each time execution of loop and will compare its value with 0 inside the loop.If it is 0 loop will exit.
