Post Created date
Remainder
Here's some reasonably straightforward assembly code for calculating the Modulo of an arbitrary long number(up to 256 bytes in this case) by an 8bit number. This is written for...
Wednesday, 12 July 2006 - 08:21
Two's complement signed byte division
What chip are you using? Is it one that supports MULSU? If so, you can use it to multiply (end - start) * step. And!.. You can use MULSU to divide by 7: Multiply by round(256/7...
Tuesday, 4 July 2006 - 19:58
General C: Determine MSB position in 32 Bit variable
Sebastian, I've modified your code so it uses the standard C calling convention by avoiding the use of R16 as a return value. The nifty thing is that it has the exact same cycle...
Tuesday, 6 June 2006 - 21:42
General C: Determine MSB position in 32 Bit variable
For function return values, WinAVR's GCC promotes 8bit types to 16 bit types. So the calling function would expect the upper 8bits to be zeroed. I can't explain advantage of that...
Friday, 2 June 2006 - 21:35
General C: Determine MSB position in 32 Bit variable
glitch wrote: ; input r16/17/18/19 ; output r20 get_msb_brute: ldi r20, 32 ; 1 sbrc r19,7 ; 1/2 ret ; dec r20 ; 1 sbrc r19,6 ; 1/2...
Friday, 2 June 2006 - 21:09
General C: Determine MSB position in 32 Bit variable
I'm not claiming my last method was completely practical, but I expect it would have the best weighted average. glitch wrote:Umm, not quite.. it takes more than 4 cycles to...
Friday, 2 June 2006 - 18:44
General C: Determine MSB position in 32 Bit variable
If you want a laugh, take a look at my entry for best weighted average. It has a minimum execution time of 15 cycles, including 11 cycles of overhead for parameter-setup and the...
Friday, 2 June 2006 - 09:29
General C: Determine MSB position in 32 Bit variable
Lee, I've only worked with the Mega8, so I have a strong prejudice against jamming large tables into the sram. On the other hand, if the table is placed into sram it can easily be...
Friday, 2 June 2006 - 06:04
General C: Determine MSB position in 32 Bit variable
Here's my assembly version that uses a 256-byte lookup table. I didn't plan for this, but it _always_ takes 25 cycles. It could be reduced to 23 cycles if the lookup table is put...
Friday, 2 June 2006 - 05:03
General C: Determine MSB position in 32 Bit variable
Ok, since we're cycle-counting. Here's a version in assembly. If each of bits in value you are checking has a 50% chance of being set, then 50% of the time the MSB will be the...
Friday, 2 June 2006 - 04:47
General C: Determine MSB position in 32 Bit variable
Here's my size optimized version: #include int8_t FindMSB( uint32_t value ) // returns -1, if value == 0 { int8_t BitIndex = 31; do { if( (int32_t) value...
Wednesday, 31 May 2006 - 08:47
Mixing C with ASM Assembler
In the "I/O View"==>"Processor" section, there's a "Cycle Counter" item that's available while debugging. --Brian
Friday, 10 March 2006 - 07:55