Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Need help in mathematical algorithm (S.O.S!!!)

webboywebboy Member Posts: 4
I'm an absolute beginner in Assembly programming.
First I have to write n! (n factorial) in Assembly (probably on a recursive way), then I have to write the summary of the first n positive integers: n*(n+1)/2.

Please, tell me how to write mathematical programs in Assembly.

How should I begin to write such programs, which methods are to be needed?


  • emu8086emu8086 Member Posts: 125
    Here is the program that calculates the factorial,
    it requires '' header file, you can get it
    from emu8086 pack:

    The following code should be compatible with MASM/TASM as well
    (some tiny modifications maybe required), see this article
    for more info:

    ; This sample gets the number
    ; from the user, and calculates
    ; factorial for it.
    ; Supported input from 0 to 8
    ; inclusive!


    include ''

    ORG 100h


    ; get first number:

    DB 13, 10, 'Enter the number: ', 0

    CALL scan_num

    ; factorial of 0 = 1:
    MOV AX, 1
    CMP CX, 0
    JE print_result

    ; move the number to BX:
    ; CX will be a counter:

    MOV BX, CX

    MOV AX, 1
    MOV BX, 1

    MUL BX
    CMP DX, 0
    JNE overflow
    INC BX
    LOOP calc


    ; print result in AX:
    DB 13, 10, 'Factorial: ', 0

    JMP exit

    DB 13, 10, 'The result is too big!', 13, 10, 'Use values from 0 to 8.', 0
    JMP start



    ; here we define the functions
    ; from

    ; SCAN_NUM reads a
    ; number from the user and stores
    ; it in CX register.


    ; PRINT_NUM prints a signed
    ; number in AX.
    ; PRINT_NUM_UNS prints an unsigned
    ; number in AX (required by
    ; PRINT_NUM):


    ; PTHIS prints NULL terminated
    ; string defined just after
    ; the CALL PTHIS instruction:


    Hope this helps.

    Let me know if any trouble...

  • webboywebboy Member Posts: 4
    I have the following problem:

    EMU8086 can't be downloaded ordinarly. At the end of the download, the setup can't run.

    I need EMU8086 because of, please tell me which site I can download it from.

    Or if you have the version, which is functioning, you can send it to me by E-Mail.

    My E-mail address is: [email protected]
  • emu8086emu8086 Member Posts: 125
    you can try downloading emu8086 from Simtel Servers
    all around the world:

  • webboywebboy Member Posts: 4
    Thanks for all the informations. I have downloaded it successfully.

  • Shawn CarterShawn Carter Member Posts: 0

    ____ // // free video tutorials and ebooks about // Scratch, Swift, Ruby, Python, MATLAB, Objective-C, PL/SQL, Go, JavaScript, Java, PHP, Perl, Visual Basic .NET, C++, C#, Visual Basic, R, Delphi, C, Assembly Fortran, COBOL, Rust, Hack, D, Apex, Scala, LabVIEW, Awk, Lua, Transact-SQL, ABAP, Lisp, Julia, Dart, Ada, Scheme, Crystal, FoxPro, Alice, Kotlin, Bash, VBScript, ML, Logo, F#, Erlang, SAS, Prolog, Clojure // _________

Sign In or Register to comment.