Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Xeda112358

Pages: 1 ... 22 23 [24] 25 26 ... 317
346
ASM / Re: Should I learn ASM?
« on: March 13, 2017, 11:25:06 pm »
But the multiplication isn't convoluted! It's exactly how most of us are taught in grade school, except instead of multiplying digits 0~9, it's just multiplying by 0 or 1 which is super trivial. Like:

         01110101
        x10101101
        ---------
         01110101
        000000000
       0111010100
      01110101000
     000000000000
    0111010100000
   00000000000000
  011101010000000

Or removing the multiplies by zero:

         01110101
        x10101101
        ---------
         01110101
       0111010100
      01110101000
    0111010100000
  011101010000000




So suppose bit 3 is set. Then you basically add your top number, shifted left three times. As an example, suppose you wanted to multiply C*E (ignoring the top 8 bits):
Code: [Select]
;C is our "top" number.
;E is our "bottom" number.
;A will be our "accumulator"

    ld a,0

    rrc e    ;this rotates register 'e' right, putting the bottom bit as "carry" [out of the register].
    jr nc,checkbit1   ;nc == not carry. If "carry" out was zero, skip this step.
    add a,c    ;if carry out was 1, then add to our accumulator.
checkbit1:
    sla c    ;finally, shift our "top number" to the left in case we need to add this to the accumulator, too. Then [REPEAT] 7 more times.
    rrc e
    jr nc,checkbit2
    add a,c
checkbit2:
    sla c
    rrc e
    jr nc,checkbit3
    add a,c
checkbit3:
    sla c
    rrc e
    jr nc,checkbit4
    add a,c
checkbit4:
    sla c
    rrc e
    jr nc,checkbit5
    add a,c
checkbit5:
    sla c
    rrc e
    jr nc,checkbit6
    add a,c
checkbit6:
    sla c
    rrc e
    jr nc,checkbit7
    add a,c
checkbit7:
    sla c
    rrc e
    jr nc,all_done
    add a,c
all_done:
    ret
If you can see how that relates to the school book algorithm, then just know that the following does practically the same thing:
Code: [Select]
;C is our "top" number.
;E is our "bottom" number.
;A will be our "accumulator"

    xor a    ;mad hax to set A to zero. Faster, smaller.
    ld b,8
loop:
    rrc e    ;this rotates register 'e' right, putting the bottom bit as "carry" [out of the register].
    jr nc,no_add   ;nc == not carry. If "carry" out was zero, skip this step.
    add a,c    ;if carry out was 1, then add to our accumulator.
no_add:
    sla c    ;finally, shift our "top number" to the left in case we need to add this to the accumulator, too.
    djnz loop  ;aaand repeat, decrementing register B until zero (this is a specialized instruction on the Z80)
    ret

But please don't use that in a real program :P It's terribly inefficient. If you understand how the register pairing works, you can come up with a much better AND more convoluted algorithm:
Spoiler For "Step-by-Step How to derive the 'best' 8-bit Multiplication Algorithm":
Let's start by rearranging the above code. The way we do 'schoolbook' multiplication starts at the least significant digit, but we can just as easily start from the most significant digit. So let's do an example in base 10:

    377
   x613
   ----
=1*3*377+10*1*377+100*6*377
=1(3*377+10(1*377+10(6*377)))

If we want to convert that last line to pseudo-code:
Code: [Select]
0->acc
10*acc+6*377->acc
10*acc+1*377->acc
10*acc+3*377->acc
So if we wanted something like that in assembly:
Code: [Select]
H*E -> A
;H is the "bottom" number that we will no be checking the top digit down to the bottom digit.
;E is the 'Top" number.
;A is the accumulator
;basic algo, after initializing A to zero.
;    multiply A by 2.
;    shift H left by 1
;    if this results in a bit carried out (so a 1 carried out), then add E ('top' number) to A (the accumulator)
;    repeat 7 more times for all bits in H.
    xor a
    ld b,8
loop:
    add a,a
    sla h        ;shifts H left by 1, bringing in a 0 for the low bit. mathematically the same as H*2 -> H
    jr nc,skip_add
    add a,e
skip_add:
    djnz loop
    ret
That's faster, but not optimal! To get the optimal way, lets stray from optimality a little to make 'L' our accumulator. Since we can't directly add another register to L, we'll have to juggle with register A making it slower:
Code: [Select]
    ld l,0
    ld b,8
loop:
    sla l
    sla h
    jr nc,skip_add
    ld a,l \ add a,e \  ld l,a
skip_add:
    djnz loop
    ret
But since we know that 'sla l' will spit out a zero-bit for the first 8 iterations (all of them), we can do 'sla l \ rl h' which is the same size and speed. However, this is the same as just doing doing "add hl,hl" ! This is where you'll have to learn how register pairs work :P
Code: [Select]
    ld l,0
    ld b,8
loop:
    add hl,hl
    jr nc,skip_add
    ld a,l \ add a,e \  ld l,a
skip_add:
    djnz loop
    ret
But wait, there is more! We don't have an "add l,e" instruction, but we do have an "add hl,de" instruction. If we make D==0, then we can change 'ld a,l \ add a,e \  ld l,a' to 'add hl,de'. The problem is, if the lower byte of HL, (so L) overflows, then the upper byte H, our 'bottom' number. We can't have it changing our input value halfway through the algorithm! Thankfully, the changes never propagate into those upper bits. This requires some tedious work to prove, but if you are cool with taking that at face value, then our last piece of the puzzle gives us:
Code: [Select]
    ld d,0
    ld l,d    ;since D=0 already, this sets L to 0, as we want. It's smaller and faster than ld l,0.
    ld b,8
loop:
    add hl,hl
    jr nc,skip_add
    add hl,de
skip_add:
    djnz loop
    ret
Even better, this actually givers us the full 16-bit result instead of just the lower 8 bits :)

347
General Calculator Help / Re: Ti84+SE misbehaving
« on: January 25, 2017, 10:08:12 am »
Which OS version? 2.53MP is known to be fairly buggy, 2.55MP is pretty stable in my experience, but I have gotten it to randomly crash before.

348
The Axe Parser Project / Re: Need Help With Collision
« on: January 18, 2017, 02:53:22 pm »
Have you tried swapping X and Y ? I haven't really dissected the code so this is a shot in the dark, but it's an issue I've frequently encountered.

349
TI-BASIC / Re: Fastest way to render random points and lines?
« on: January 15, 2017, 09:27:27 am »
Of course assembly would be way faster, but have you tried the standard built in Pxl-On(, Pxl-Off(, Pxl-Change(, Pt-On(, Pt-Off(, Pt-Change(, Line(, and Circle( commands? Also, if you include an extra argument for Circle( of {i it will perform faster (i being the imaginary i).

If you haven't tried Axe yet, I urge you to try that if you want much faster graphics. Just be warned that Axe works a lot closer to assembly, so you can't just press [ON] to break out of infinite loops. For example, if you do While 1:End, you will need to pull a battery and get a RAM clear.

Edit: Also, if you want a pixel based circle (instead of TIs point-based), I think KermM wrote an entirely TI-BASIC routine that performs faster than TIs.

350
News / Re: Reuben Quest: Lost Between Times
« on: January 09, 2017, 09:03:48 pm »
This is.....odd.
Which calculator?
Did you have an item selected? Which one? Was it a bottle? What was inside the bottle?
TI-84+SE OS 2.55MP (shush, I use it for the extra built in functions :P )
I tried it at various points in the game including with water selected. It also crashes when I go to use magic, then press down. And occasionally if I die and hit [2nd] too quickly, it glitches to an odd map area and when I move it causes it to crash.

351
News / Re: Reuben Quest: Lost Between Times
« on: January 01, 2017, 09:22:20 am »
I haven't played an awful lot, but it's fun so far!
I have one major bug to report, though: Whenever I press the down arrow when I'm charged for an attack, I get an error (Err:Link I believe) and it causes my calc to freeze and I have to pull a battery.

352
News / Re: Reuben Quest: Lost Between Times
« on: December 19, 2016, 09:39:32 am »
Holy canoli, +1 for that, for sure! It looks sooo good! Gonna start playing when I boot up my pi to send to my calc!

I wonder if this will make it into next year's POTY then? I sure hope so XD

354
TI-BASIC / Re: Help overcoming Symbolic bug
« on: November 12, 2016, 07:07:13 am »
That's really clever! Is this bug only an issue when Batlib is installed? I'm worried that it might be a bug with Batlib or Batlib+Symbolic.

355
TI-BASIC / Re: Help overcoming Symbolic bug
« on: November 07, 2016, 03:00:27 pm »
I'm not sure why that could even be an issue. I don't have symbolic or access to link software, so  could you try this and see if it works :
Code: [Select]
If 1=1:Then
    "X*X^2→Str1
    "2*3→Str2
    ClrHome
    Disp real(13,Str1)
    real(13,"X
    Disp real(13,Str2)
End
Also, for Batlib commands, of you have an argument of 0 before a string, you can omit it. For example:
Code: [Select]

If 1=1:Then
    "X*X^2→Str1
    "2*3→Str2
   
    ClrHome
    Disp real(13,dim(11,"DStr1",length(Str1
    Disp real(13,dim(11,"DStr2",length(Str2
End
As well, if the last few arguments are zero, you can omit them, too.

356
Math and Science / Re: Quadratic and Faster Convergence for Division
« on: October 26, 2016, 11:23:42 am »
Oh, it's a common programming technique for performing ##\frac{x}{2^{n}(2^{k}\pm1)}##.

357
TI-BASIC / Re: Convert decimal to fraction as a string (TI-84)
« on: October 26, 2016, 11:19:58 am »
I'm glad to hear it! Every so often, I take time to look at my code and try to come up with better ways of doing things. who knows, maybe in a few years there will be a Batlib 2 :P

358
TI Z80 / Re: ICE - an interpreter/compiler of CE-BASIC
« on: October 24, 2016, 08:06:27 pm »
Holy, crud, wow!

359
TI-BASIC / Re: Convert decimal to fraction as a string (TI-84)
« on: October 24, 2016, 08:02:41 pm »
Well, I mean if your code is only working with rational numbers (a/b, with a,b integers and b>0), you can manually keep track of the numerators and denominators. For example, take two numbers, 3/7 and 15/11, and represent them as {3,7->L1:{15,11->L2.

Addition:
{L1(1)L2(2)+L1(2)L2(1),L1(2)L2(2):Ans/gcd(abs(Ans(1)),abs(Ans(2
Subtraction:
{L1(1)L2(2)-L1(2)L2(1),L1(2)L2(2):Ans/gcd(abs(Ans(1)),abs(Ans(2
Multiplication:
{L1(1)L2(1),L1(2)L2(2):Ans/gcd(abs(Ans(1)),abs(Ans(2
Division:
{L1(1)L2(2),L1(2)L2(1):Ans/gcd(abs(Ans(1)),abs(Ans(2


360
TI-BASIC / Re: Routh-Hurwitz Matlab to TI-Nspire
« on: October 24, 2016, 05:59:53 pm »
For reference, the code linked:
Spoiler For "code":
Code: [Select]
function [] = rhc( r )
%The Routh-Hurwitz stability criterion is a necessary (and frequently
%sufficient) method to establish the stability of a single-input,
%single-output (SISO), linear time invariant (LTI) control system.
%More generally, given a polynomial, some calculations using only the
%coefficients of that polynomial can lead us to the conclusion that it
%is not stable.
%in this program you must give your system coefficents and the
%Routh-Hurwitz table would be shown


m=length(r);
n=round(m/2);
q=1;
k=0;
for p = 1:length(r)
    if rem(p,2)==0
        c_even(k)=r(p);
    else
        c_odd(q)=r(p);

        k=k+1;
        q=q+1;
    end
end
a=zeros(m,n);

if m/2 ~= round(m/2)
    c_even(n)=0;
end
a(1,:)=c_odd;
a(2,:)=c_even;
if a(2,1)==0
    a(2,1)=0.01;
end
for i=3:m
    for j=1:n-1
        x=a(i-1,1);
        if x==0
            x=0.01;
        end

        a(i,j)=((a(i-1,1)*a(i-2,j+1))-(a(i-2,1)*a(i-1,j+1)))/x;

    end
    if a(i,:)==0
        order=(m-i+1);
        c=0;
        d=1;
        for j=1:n-1
            a(i,j)=(order-c)*(a(i-1,d));
            d=d+1;
            c=c+2;
        end
    end
    if a(i,1)==0
        a(i,1)=0.01;
    end
end
Right_poles=0;
for i=1:m-1
    if sign(a(i,1))*sign(a(i+1,1))==-1
        Right_poles=Right_poles+1;
    end
end
fprintf('\n Routh-Hurwitz Table:\n')
a
fprintf('\n Number Of Right Poles =%2.0f\n',Right_poles)


   
    fprintf('\n Given Polynomials Coefficents Roots :\n')
 ROOTS=roots(r)

end

I'm not very familiar with matlab, so I hope this works. Here is the first part:
Spoiler For "first part":
Code: [Select]
length(r)->m
augment(r,{0})->r
int(.5+r/2)->n
newMatrix(m,n)->a
for k,1,n
r[k*2-1]->a[1,k]
r[k*2]->a[2,k]
EndFor
m->order
For i,3,m
For j,1,n-1
a[i-1,1]->c
limit((x*a[i-2,j+1]-a[i-2,1]*a[i-1,j+1])/x,x,c)->a[i,j]
EndFor
Here is the next line, which I don't know how to translate:
Code: [Select]
if a(i,:)==0And the next chunk, translated:
Spoiler For "next part":
Code: [Select]
for j,1,n-1
(order-2*j)*a[i-1,j]->a[i,j]
EndFor
order-1->order
EndIf
EndFor
0->Right_poles
for i,1,m-1
If sign(a[i,1])*sign(a[i+1,1])=-1:Then
Right_poles+1->Right_poles
EndIf
EndFor
And this last bit I don't know how to translate:
Spoiler For "???":
Code: [Select]
fprintf('\n Routh-Hurwitz Table:\n')
a
fprintf('\n Number Of Right Poles =%2.0f\n',Right_poles)


   
    fprintf('\n Given Polynomials Coefficents Roots :\n')
 ROOTS=roots(r)

end

Pages: 1 ... 22 23 [24] 25 26 ... 317