Need help in factorial code

Reply

Join Date: Oct 2009
Posts: 7
Reputation: surfer2009 is an unknown quantity at this point 
Solved Threads: 0
surfer2009 surfer2009 is offline Offline
Newbie Poster

Need help in factorial code

 
0
  #1
16 Days Ago
; 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)
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 131
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 13
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster
 
0
  #2
16 Days Ago
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
Last edited by NotNull; 16 Days Ago at 5:50 pm.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC