; this code gereates maximum factorial of 8 decimal
; since, A is a 16-bit register and can hold max value of ;65535 dec (255h).
;

MOV A,#8d ; value for the factorial (1-8max)
MOV B,A ; B=A
MOV C,#1d ; C=1
here: ; LOOP
SUB B,C ; B-1
MUL AB ; AxB
CMP B,C ;if B=1
JNE here ;jump back

END

this code not work .please help me in thi and this also not work for lager values.(i have to take factorial of numbers 1 to 12)

But I know, you are a coder.
Your code does work ;)

MOV A,#8d ; value for the factorial (1-8max)
MOV B,A ; B=A
MOV C,#1d ; C=1
here: ; LOOP
SUB B,C ; B-1
MUL AB ; AxB
CMP B,C ;if B=1
JNE here ;jump back
== Magically becomes
MOV AX, 8 ; value for the factorial (1-8max)
MOV BX, AX ; BX=AX
MOV CX, 1 ; C=1
here: ; LOOP
SUB BX, CX ; BX--
MUL BX ; AX x BX
CMP BX, CX ;if B=1
JNE here ;jump back

A is not an ordinary name for one of the 16-bit regs,
depends on your anti-assembler.
I prefer Intel SyNtAx.
These register names just become values in the instruction.
For instance MOV AX, 103h ;ax - is indicated by opcode.
and MOV AX, [103h] -> 8B060301 in this case AX is indicated
by REG field of the modR/M.
This pertains to 16-bit 8086 instruction format.

In some assemblers END directive is used to indicate
the entry point of the program, for .COMs it will always
be 100h (under DOS).

For 16-bits maximum unsigned value
is 65,535 = 2^16-1 = FFFFh.

[[[ AbbbLLLGgLzAx
anti mind control ...
ioOi iOioI oIoIIoi

Edited 7 Years Ago by NotNull: n/a

This article has been dead for over six months. Start a new discussion instead.