944,158 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 1946
  • Assembly RSS
Nov 7th, 2009
0

Need help in factorial code

Expand Post »
; 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)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
surfer2009 is offline Offline
11 posts
since Oct 2009
Nov 7th, 2009
0
Re: Need help in factorial code
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; Nov 7th, 2009 at 5:50 pm.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: C and Assembly Mixed-Mode Hex comparison program
Next Thread in Assembly Forum Timeline: I need halp assembing my program [NASM + NASM - IDE]





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC