pell equation matrix solution for paper

A forum for HLA users and Randall Hyde's (original) Art of Assembly Language Book
fffefd
Posts: 25
Joined: Wed Jan 18, 2023 1:54 pm

hla for (a,b,c)*4, 1989 forged nes vice stick happiness, paper space, x -1

Post by fffefd »

/*

t=a+b+b+c
|a b|
|b c|

m(r+)^n=
|a b|a an b|
|b c| |
| r+|an an^2 bn|
| n|b bn c|

m(l-)^n=
|a b|a bn b|
|b c|bn cn^2 cn|
| l-|b |
| n|cn c|

m(r-)^n=
|b c|b bn c|
|a b|an an^2 bn|
| r-| |
| n|a an b|

m(l+)^n=
|b c|b cn c|
|a b| |
| l+|bn cn^2 cn|
| n|a bn b|

i=
|1 0|
|0 1|

l^n=
|1 0|
|n 1|

r^n=
|1 n|
|0 1|

l=
|1 0|1 0|
|0 1|1 1|
| l| |
| 1| |

r=
|1 0|1 1|
|0 1|0 1|
| r| |
| 1| |

|1 0|1 x 0|
|0 -n| |
| r+|x x^2 0x|
| x|0 0x -n|
x^2-n>0,x-1

m=
|a b|
|b c|

lmr=m(r+)
lllmrrr
l^n(m)r^n=m(r+)^n

rml=m(l-)
rrrmlll
r^n(m)l^n=m(l-)^n

rmr=m(r-)
rrrmrrr
r^n(m)r^n=m(r-)^n

lml=m(l+)
lllmlll
l^n(m)l^n=m(l+)^n

rl
rrrlll
(r^n)(l^n)=
|n^2 1 n|
|n 1|

lr
lllrrr
(l^n)(r^n)=
|1 n|
|n n^2 1|

rl=ril=i(l-)
lr=lir=i(r+)
(r^n)(l^n)=r^n(i)l^n=i(l-)^n
(l^n)(r^n)=l^n(i)r^n=i(r+)^n

rr=rir=i(r-)
ll=lil=i(l+)
(r^n)(r^n)=r^n(i)r^n=i(r-)^n
(l^n)(l^n)=l^n(i)l^n=i(l+)^n

*/
program pellMatrixNegative;

#includeonce( "stdlib.hhf" )
#includeonce( "hide/hidelib.hhf" )
?@nodisplay := true;
?@noalignstack := true;
?@noframe:=true;

const
_0:dword:=$1000;

static
byte 'a','_',' ',' ';a_:dword:=1;
byte 'b','_',' ',' ';b_:dword:=0;
byte 'c','_',' ',' ';c_:dword:=0;//-1000;
dword 0,0;
byte 'a',' ',' ',' ';a:dword;
byte 'b',' ',' ',' ';b:dword;
byte 'c',' ',' ',' ';c:dword;
dword 0,0;
byte 'a','0',' ',' ';a0:dword;
byte 'b','0',' ',' ';b0:dword;
byte 'c','0',' ',' ';c0:dword;
dword 0,0;

storage
aa:dword[$1000];

begin pellMatrixNegative;
byte $0f,$1f,%00_110_101,'1',' ',' ',' ';
mov(1,esi);

byte $0f,$1f,%00_110_101,'l','o','o','p';
forever
//breakif n^2
byte $0f,$1f,%00_000_101,'b','r','e','a';
for(xor(ecx,ecx);ecx<=esi;inc(ecx))do
mov(ecx,eax);
mul(eax);
if(eax=esi)then
jmp _oddSquare;
elseif(eax>esi)then
break;
endif;
endfor;

//set c_
byte $0f,$1f,%00_110_101,'c','_',' ',' ';
mov(esi,eax);
neg(eax);
mov(eax,c_);

byte $0f,$1f,%00_111_101,'z','e','r','o';
xor(edi,edi);

byte $0f,$1f,%00_000_101,'a','b','c',' ';
mov(mov(a_,eax),a);
mov(mov(b_,eax),b);
mov(mov(c_,eax),c);

/*initiate ebp*/
byte $0f,$1f,%00_101_101,'i','n','i','t';
xor(ebp,ebp);
add(a,add(b,add(b,add(c,ebp))));

byte $0f,$1f,%00_111_101,'l','o','o','p';
forever
//m(r+)^n
byte $0f,$1f,%00_000_101,'m','r','+','n';
for(mov($1,ecx);(type int32 ebp)<0;inc(ecx))do
//c
byte $0f,$1f,%00_000_101,'c',' ',' ',' ';
mov(c,ebp);
//bn
byte $0f,$1f,%00_000_101,'b','n',' ',' ';
mov(ecx,eax);
intmul(b,eax);
add(eax,ebp);
add(eax,ebp);
//an^2
byte $0f,$1f,%00_000_101,'a','n','^','2';
mov(ecx,eax);
mul(eax);
intmul(a,eax);
add(eax,ebp);

endfor;

byte $0f,$1f,%10_001_111,'a','a',' ',' ';
sub(2,ecx);
mov(ecx,aa[edi*4]);
inc(edi);
//an^2 bn bn c
byte $0f,$1f,%00_000_101,'a','b','b','c';
mov(c,ebp);
mov(ecx,eax);
intmul(b,eax);
add(eax,ebp);
add(eax,ebp);
mov(ecx,eax);
mul(eax);
intmul(a,eax);
add(eax,ebp);
mov(ebp,c);
//an b
byte $0f,$1f,%00_000_101,'a','n','b',' ';
mov(ecx,eax);
intmul(a,eax);
add(b,eax);
mov(eax,b);
//a
byte $0f,$1f,%00_000_101,'a',' ',' ',' ';
/*
//display a,b,c
stdout.put((type int32 a),' ',(type int32 b),' ',(type int32 c),nl);
*/
//store a0,b0,c0
byte $0f,$1f,%00_000_101,'a','0','b','0';
if(edi=1)then
mov(mov(a,eax),a0);
mov(mov(b,eax),b0);
mov(mov(c,eax),c0);
endif;
//compare a0,b0,c0 to stop loop
byte $0f,$1f,%00_000_101,'s','t','o','p';
if(edi>1)then
mov(a,eax);
if(eax=a0)then
mov(b,eax);
if(eax=b0)then
mov(c,eax);
if(eax=c0)then
mov(edi,edx);
/*
//display edx
stdout.put(edx,' ');
*/
jmp _endloop;
endif;
endif;
endif;
endif;
/*initiate ebp*/
byte $0f,$1f,%00_101_101,'i','n','i','t';
xor(ebp,ebp);
add(a,add(b,add(b,add(c,ebp))));

//m(l-)^n
byte $0f,$1f,%00_000_101,'m','l','-','n';
for(mov($1,ecx);(type int32 ebp)>0;inc(ecx))do
//a
byte $0f,$1f,%00_000_101,'a',' ',' ',' ';
mov(a,ebp);
//bn
byte $0f,$1f,%00_000_101,'b','n',' ',' ';
mov(ecx,eax);
intmul(b,eax);
add(eax,ebp);
add(eax,ebp);
//cn^2
byte $0f,$1f,%00_000_101,'c','n','^','2';
mov(ecx,eax);
mul(eax);
intmul(c,eax);
add(eax,ebp);

endfor;

byte $0f,$1f,%10_001_111,'a','a',' ',' ';
sub(2,ecx);
mov(ecx,aa[edi*4]);
inc(edi);
//cn^2 bn bn a
byte $0f,$1f,%00_000_101,'c','b','b','a';
mov(a,ebp);
mov(ecx,eax);
intmul(b,eax);
add(eax,ebp);
add(eax,ebp);
mov(ecx,eax);
mul(eax);
intmul(c,eax);
add(eax,ebp);
mov(ebp,a);
//cn b
byte $0f,$1f,%00_000_101,'c','n','b',' ';
mov(ecx,eax);
intmul(c,eax);
add(b,eax);
mov(eax,b);
//c
byte $0f,$1f,%00_000_101,'c',' ',' ',' ';
/*
//display a,b,c
stdout.put((type int32 a),' ',(type int32 b),' ',(type int32 c),nl);
*/
/*initiate ebp*/
byte $0f,$1f,%00_101_101,'i','n','i','t';
xor(ebp,ebp);
add(c,add(b,add(b,add(a,ebp))));

endfor;
_endloop:
byte $0f,$1f,%00_000_101,'e','n','d','l';

/*
//display aa
xor(edi,edi);
forever
stdout.put((type int32 aa[edi*4]),' ');
inc(edi);
if(aa[edi*4]=0)then
break;
endif;
endfor;
stdout.newln();
*/

//identify abc*4, edx from stop
byte $0f,$1f,%00_000_101,'a','b','c','4';
mov(edx,eax);
dec(eax);
mov(aa[eax*4],eax);
/*
//display eax
stdout.put(eax,' ');
*/
mov(edx,ebx);
shr(1,ebx);
mov(aa[ebx*4],ebx);
/*
//display ebx
stdout.put(ebx,' ');
*/
if(eax!=ebx)then
//jmp _notAbc4Form;
byte $8d,%00_000_101;dword &_notAbc4Form;
byte $ff,%11_100_000;
endif;

//display abc*4, edx from stop
for(xor(edi,edi);edi<edx;inc(edi))do
stdout.put((type int32 aa[edi*4]),' ');
endfor;
stdout.newln();

_notAbc4Form:
byte $0f,$1f,%00_000_101,'n','o','t','a';

//clear aa
byte $0f,$1f,%00_000_101,'a','a','c','l';
xor(edi,edi);
forever
mov(0,aa[edi*4]);
inc(edi);
if(aa[edi*4]!=0)then
continue;
else
break;
endif;
endfor;

_oddSquare:
byte $0f,$1f,%00_000_101,'o','d','d','s';
inc(esi);
breakif(esi=_0);

endfor;

end pellMatrixNegative;
Attachments
pellMatrixNegative.7z
(6.17 KiB) Downloaded 248 times
Post Reply