int X = 0;
int Y = 1;
while(X <= 10 ){
if(X%2 == 0)
Y = Y * X;
else
Y++;
X++;
}
cout << "Y is: " << Y;
This is what I have for my Easy68k code.
ORG $1000
START: ; first instruction of program
MOVE.W #0,D1 ;PUT 0 IN D1 (X)
MOVE.W #1,D2 ;PUT 1 IN D2 (Y)
LOOP CLR.W D3 ;Find the remainder
MOVE.W D1,D3
DIVU #2,D3
SWAP D3
CMP #0,D3 ;Compare remainder with 0
BEQ EQUAL ;If equal, then go to equal
ADD.W #1,D2 ;Y++
ADD.W #1,D1 ;X++
CMP #11,D1 ;Compare D1 with 11
BEQ DONE ;If D1 equals 11, break loop.
BRA LOOP
EQUAL MULU.W D1,D2 ;Multiply D1 and D2 and store it in D2
ADD.W #1,D1 ;X++
CMP #11,D1 ;Compare D1 with 11
BEQ DONE ;If D1 equals 11, break loop.
BRA LOOP
DONE LEA MESSAGE,A1
MOVE.W #14,D0
TRAP #15
MOVE.W D2,D1
MOVE.W #3,D0
TRAP #15
SIMHALT ; halt simulator
MESSAGE DC.W 'Y is: ',0
END START ; last line of source
I'm not exactly sure what is incorrect about my code but I have a feeling it is an issue at the beginning of the loop section. I have followed along with the code but I still cannot figure out where it is going wrong. When I run it, it outputs Y is: 10. D1 and D2 are also both A or 10. Any help is appreciated.