flat assembler
Message board for the users of flat assembler.

Index > Main > count more than capacity

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
on pics, operations are only on 8 bits.
then, to make easy loops (bad practice i know) i use the W register (equivalent to Accumulator) and then, i use a sort of dec instruction.

in X86 it gives this kind of code:
Code:
tempo0:
@@:
inc al
jne @b
ret
    


then, considering the risc architecture, it can be possible to do a sort of incremental addition that will add 1, 2, 3, 4, 5, 6, etc... and then, maybe it will reach the 0 value later than if i use a simple inc.
Code:
tempo1
mov al,0
mov ah,0
@@:
inc ah
add al,ah
jne @b
ret
    

how many times i will do the loop tempo1? it is some mystery for me. is there a math method to find a good way for more than 256 counts on byte?

0+1=1
1+2=3
3+3=6
6+4=10
10+5=15
15+6=21
21+7=28
36,45,55,66,78,91,105,120,136,153,171,180,
etc...
X+Y=0

i can find with a little code, simulating the computation very fast, but it is not a clean method to solve the problem...

the goal is to count something like 20000 times just with one main byte and one increment byte, and of course, only one jcc because in pic, jcc doesn't exist and needs 2 instructions. and there is only one acumulator, means it is not possible to work easy on many registers at a time.
Post 20 Feb 2011, 11:27
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17250
Location: In your JS exploiting you and your system
revolution
sum(1,2,...,n)=n(n+1)/2

You want to find the point(s) where n(n+1)/2 mod 256 = 0

First solution is at 511 & 512 and then every 512 from there.

511,512,1023,1024,1535,1536,...
Post 20 Feb 2011, 11:46
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
cool.
thanks.

in fact, there is a simpler way to do the job, it exists incf instruction (to increment f register, folowed by a btfss Z flag, it an be ok to work on multibyte temporisations.

i am just trying to have the hello world working with code compiled with fasm.. and it does nothing else than light the green led... even if is fore the red led ot switch on, it don't work... i am very sad because apparentlly, the macro i've writen yesterday don't give the good opcodes...
Post 20 Feb 2011, 12:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.