Saturday, March 24, 2012

Factorial of a given number with macro using 8086

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

2 comments:

  1. 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

    ReplyDelete
    Replies
    1. Hi
      What 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.

      Delete

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...