Writing in assembly language Motorola 68hc11, was able to get this to work for numbers up to 6 factorial. I need it to work for N<=9 factorial, and for N=9 and higher, it must correctly calculate the lowest two bytes. It must match the C pseudocode, which I've written and therefore can be changed 1-to-1. The pseudocode must use two nested loops and can only use if/while/do-until loops, no for loops. You also cannot use the MUL instruction, must add together as in pseudocode. The only thing that can't be changed are these parts:
* start of data section
ORG $B000
N FCB 8
ORG $B010
NFAC RMB 2
* define any other variables that you might need here
ORG $C000
* start of your program
Lab3.asm
* Name: Jake McConkey
* ID: JBMDCZ
* Date: 2/28/24
* Lab3
* Program description: 10
* Pseudocode: 11
* #include <stdio.h>
* int main() 14
* unsigned int N=8;
* unsigned int factorial = 1;
* unsigned int i=i;
* unsigned int factAdd=0;
* if(N==) 20
* printf("0=1
");
* while(i<=N)
* factAdd=factorial;
* unsigned int j=1;
* while(j<i)
* factorial=factorial+factAdd;
* i++
* printf("N!: %d
",factorial);
*************************************************
* start of data section
ORG $B030
N FCB 6
ORG $B010
NFAC RMB 2
FADD RMB 1
* define any other variables that you might need here
ORG $C0050
* start of your program
CLR FADD
LDAA #1
CLR NFAC
STAA NFAC+1
WHILE:
LDAA
CMPA
BHI ENDWHILE
LDAB NFAC+1
STAB FADD
FCB #1
LDAA #1
STAA WHILE2
LDX 3
CPX I
BHS ENDWHILE2
LDAB FADD
LDX NFAC
ABX
STX NFAC
INC
BRA WHILE2
ENDWHILE2
INC
BRA WHILE
ENDWHILE
STOP