Do bear in mind though the requirement to make best use of 17 different architectures (MUL when you can etc). Handling those variants may be easier in plain Asm with conditional sections. Trying to handle that too in the already fraught inline syntax could be "fun". ;-)
Wouldn't it be easier to just learn to count in hex and then re-define ASCII so that the codes for ABCDEF came right after 0123456789? Ah, wait, no, someone would complain that they want lowercase, forget that.
People who use lower case in hex give me the willies! OK, I suppose 0xDEADBEEF and 0xdeadbeef both work but when you have something like 0xACE81ADE ("Ace Blade") it just doesn't look right as 0xace81ade !!
(oh and in my world the 'x' is always 'x' and never 'X'. Euugh! This does of course mean "0x%08X" though! ;-)
Posted by SprinterSB: Fri. Oct 21, 2016 - 05:53 PM
1
2
3
4
5
Total votes: 0
skeeve wrote:
avr-gcc inline assembly can use R0..R31 in any way one wants. The compiler has to be informed. gcc inline assembly has the syntax and semantics to connect registers with C variables. That is what makes gcc inline assembly so much more powerful than others.
FYI, you can't use just any register in inline asm, for example the following code won't compile:
void f (int*);
void g (int a)
{
f (&a);
__asm (" " ::: "28");
}
Similar code is frequently used — not taking the address of a parameter, but passing down the address of a local, non-static buffer array to some receiver or transmitter routine.
avrfreaks does not support Opera. Profile inactive.
Posted by Rezer: Fri. Oct 21, 2016 - 09:06 PM(Reply to #59)
1
2
3
4
5
Total votes: 0
I'm not an expert on inline asm, but isn't that just failing because you're telling avr-gcc you're clobbering r28, and avr-gcc requires r28 to be saved and restored? I.e. you can use it however you want if you think you know better, but telling the compiler what you're doing will make it angry.
FYI, you can't use just any register in inline asm, for example the following code won't compile:
void f (int*);
void g (int a)
{
f (&a);
__asm (" " ::: "28");
}
Similar code is frequently used — not taking the address of a parameter, but passing down the address of a local, non-static buffer array to some receiver or transmitter routine.
Nothing to do with libc, but in dumping data, say to a 9600 baud serial port, then yes, transmission speed can be the most expensive factor in data acquisition time. It's trivial to write a routine that dumps a byte as two hex digits, but then when you paste that data dump into a spreadsheet program (eg. MS Excel), horrible things happen.
(0x omitted)
1234 is interpreted as 1234 decimal, when it should be 4660 decimal
12A4 is interpreted as hex, or 4772 decimal (as it should).
12E4 is interpreted as 120,000 decimal when it should be 4836.
The horrible solution I came up with is to prefix all values with 'F', which entirely defeats the transmission speed benefit, but does force all the data to be interpreted as hexadecimal.
I had an AVR system in production awhile ago that used base-62 for communication. [0-9],[A-Z],[a-z] were the allowed ASCII characters. I wanted base-64, but the barcode system we were using for input and output wouldn't do punctuation. Ah well... S.
Ah ha - a reinvention of UUcode ? Those of us old enough to remember email before MIME existed will remember passing binary files back and forth UUencoded!
Pretty much!! Although ours was a homegrown incompatible version. I am indeed old - uudecode was our pal! And to be honest, I still have systems out there that are transmission-speed dependent, and I'm always tempted to try. Few of the Powers-With-Money are inclined to concur. S.
Quite a lot of it already is ;-)
Do bear in mind though the requirement to make best use of 17 different architectures (MUL when you can etc). Handling those variants may be easier in plain Asm with conditional sections. Trying to handle that too in the already fraught inline syntax could be "fun". ;-)
- Log in or register to post comments
TopWouldn't it be easier to just learn to count in hex and then re-define ASCII so that the codes for ABCDEF came right after 0123456789? Ah, wait, no, someone would complain that they want lowercase, forget that.
- Log in or register to post comments
TopPeople who use lower case in hex give me the willies! OK, I suppose 0xDEADBEEF and 0xdeadbeef both work but when you have something like 0xACE81ADE ("Ace Blade") it just doesn't look right as 0xace81ade !!
(oh and in my world the 'x' is always 'x' and never 'X'. Euugh! This does of course mean "0x%08X" though! ;-)
- Log in or register to post comments
TopAgreed, lowercase hex is nearly as bad as using spaces instead of tabs, or tab sizes other than 4.
- Log in or register to post comments
TopOk I had some time and here is a ASM version that can run on all AVR's (with RAM).
It is 78 byte, and take max 201 clk (76 200 if you have a defined zero reg.)
But the best is actually the small amount of registers used, only 2 other than input data and pointer
It don't print starting 0's so 123 is printed as 123\0
It's based on the count down up down ....
I will look at a faster version but the code will be bigger, but something like 150 byte and 120clk should be possible
An other way is something like a 40 byte 300 clk version
- Log in or register to post comments
TopThis was better that expected :
54 byte and max 249 clk , and only r18 and r19 added as changed
- Log in or register to post comments
TopLast version before bed time it make both count down and up on each digit (but down with a factor 2 bigger).
It 68 byte and max 188 clk
- Log in or register to post comments
TopFYI, you can't use just any register in inline asm, for example the following code won't compile:
Similar code is frequently used — not taking the address of a parameter, but passing down the address of a local, non-static buffer array to some receiver or transmitter routine.
avrfreaks does not support Opera. Profile inactive.
- Log in or register to post comments
TopI'm not an expert on inline asm, but isn't that just failing because you're telling avr-gcc you're clobbering r28, and avr-gcc requires r28 to be saved and restored? I.e. you can use it however you want if you think you know better, but telling the compiler what you're doing will make it angry.
- Log in or register to post comments
TopDoes it help to put in the r?
Moderation in all things. -- ancient proverb
- Log in or register to post comments
TopAdding "r" won't help, that's just some sugar.
That's because r28 is part of the frame pointer.
avrfreaks does not support Opera. Profile inactive.
- Log in or register to post comments
TopModeration in all things. -- ancient proverb
- Log in or register to post comments
TopI had a look at how small it can be, and I guess that the code like this is one of the smallest I can think of at the moment.
It is zero terminated, but the zeros aren't removed so 123 will print 00123\0
It use a 16/8 div routine and because the digits come in the wrong order the zeros is a pain to remove!
it take r17:r16 as input and Z is the pointer
and it take about 760 clk
But it's only 38 byte in size.
Any smaller code?
Edit forgot an init
- Log in or register to post comments
TopNothing to do with libc, but in dumping data, say to a 9600 baud serial port, then yes, transmission speed can be the most expensive factor in data acquisition time. It's trivial to write a routine that dumps a byte as two hex digits, but then when you paste that data dump into a spreadsheet program (eg. MS Excel), horrible things happen.
(0x omitted)
1234 is interpreted as 1234 decimal, when it should be 4660 decimal
12A4 is interpreted as hex, or 4772 decimal (as it should).
12E4 is interpreted as 120,000 decimal when it should be 4836.
The horrible solution I came up with is to prefix all values with 'F', which entirely defeats the transmission speed benefit, but does force all the data to be interpreted as hexadecimal.
F1234 mod F0000 gives 4660 decimal, always. &c.
Dunno if that helps any. S.
- Log in or register to post comments
TopBut that is a good reason to use decimal numbers in you log.
- Log in or register to post comments
TopI had an AVR system in production awhile ago that used base-62 for communication. [0-9],[A-Z],[a-z] were the allowed ASCII characters. I wanted base-64, but the barcode system we were using for input and output wouldn't do punctuation. Ah well... S.
Edited for typo. S.
- Log in or register to post comments
Top- Log in or register to post comments
TopPretty much!! Although ours was a homegrown incompatible version. I am indeed old - uudecode was our pal! And to be honest, I still have systems out there that are transmission-speed dependent, and I'm always tempted to try. Few of the Powers-With-Money are inclined to concur. S.
- Log in or register to post comments
TopPages