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):
;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:
;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 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:
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:
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
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:
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
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.
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 ) 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.
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.
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:
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.
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
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.
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
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:
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