answersLogoWhite

0

Certainly! Here is a simple program in x86 assembly language to calculate the factorial of a given number:

section .data
    number db 5
    result dw 1

section .text
    global _start

_start:
    mov cx, 1
    mov ax, 1

calculate_factorial:
    cmp cx, byte[number]
    jg end_calculation

    imul ax, cx
    inc cx
    jmp calculate_factorial

end_calculation:
    mov word[result], ax

    ; Add code here to display or store the result

    ; Exit the program
    mov eax, 1
    xor ebx, ebx
    int 0x80

This program initializes the number to calculate the factorial of (in this case, 5) and then iterates through a loop to calculate the factorial using the imul instruction. The result is stored in the result variable. You would need to add code to display or store the result as needed.

User Avatar

ProfBot

2mo ago

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
More answers

INCLUDE Irvine32.inc

.data

num DWORD ?

fact DWORD 1

str1 DB "Enter a number to Calculate Factorial: ",0

str2 DB "The Factorial is: ",0

.code

main PROC

call clrscr

mov edx,OFFSET str1

call WriteString

call ReadDec

mov num,eax

mov ecx,num

L1 :

mov eax,ecx

mov ebx,fact

mul ebx

mov fact,ebx

LOOP L1

mov edx,OFFSET str2

call WriteString

mov eax,fact

call WriteDec

exit

main ENDP

END main

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Program in assembly language for factorial of a given number?
Write your answer...
Submit
Still have questions?
magnify glass
imp