FACTORIAL MACRO
XOR CX,CX
XOR AX,AX
INC AX
MOV CL,NUMBER
CMP CL,0
JE GO
REPEAT: MUL CX
LOOP REPEAT
GO: MOV FACT,AX
ENDM
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
ORG 2000H
NUMBER DB 08H
FACT DW 0
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
FACTORIAL
MOV AH,4CH
INT 21H
CODE ENDS
END START
XOR CX,CX
XOR AX,AX
INC AX
MOV CL,NUMBER
CMP CL,0
JE GO
REPEAT: MUL CX
LOOP REPEAT
GO: MOV FACT,AX
ENDM
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
ORG 2000H
NUMBER DB 08H
FACT DW 0
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
FACTORIAL
MOV AH,4CH
INT 21H
CODE ENDS
END START
In the factorial macro in the loop repeat i think there must be dec of cx is it correct or not and please explain there must be repeat loop or not
ReplyDeleteHi
DeleteWhat you expected is correct when you are using some other registers as counter. But here we are using cx. Consider one thing cx is called as counter. means the default behavior is counting. when ever the loop is being executed the value stored in cx will decrement automatically.
so in the loop repeat no need to use dec cx.
Hope you understood.