flat assembler
Message board for the users of flat assembler.

 Index > Main > count more than capacity
Author
edfed

Joined: 20 Feb 2006
Posts: 4280
Location: Now
edfed 20 Feb 2011, 11:27
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
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.
20 Feb 2011, 11:27
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18940
Location: In your JS exploiting you and your system
revolution 20 Feb 2011, 11:46
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,...
20 Feb 2011, 11:46
edfed

Joined: 20 Feb 2006
Posts: 4280
Location: Now
edfed 20 Feb 2011, 12:02
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...
20 Feb 2011, 12:02
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum