Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > sci.electronics.design > #473729 > unrolled thread

Microchip ICD4 ?

Started byMartin Riddle <martin_rid@verizon.net>
First post2017-08-17 13:45 -0400
Last post2017-08-18 12:10 +0100
Articles 11 on this page of 91 — 25 participants

Back to article view | Back to sci.electronics.design


Contents

  Microchip ICD4 ? Martin Riddle <martin_rid@verizon.net> - 2017-08-17 13:45 -0400
    Re: Microchip ICD4 ? DemonicTubes <tlackie@gmail.com> - 2017-08-17 12:17 -0700
      Re: Microchip ICD4 ? Martin Riddle <martin_rid@verizon.net> - 2017-08-17 15:32 -0400
      Re: Microchip ICD4 ? speff <spehro@gmail.com> - 2017-08-17 19:02 -0700
    Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 15:52 -0400
      Re: Microchip ICD4 ? piglet <erichpwagner@hotmail.com> - 2017-08-17 21:23 +0100
        Re: Microchip ICD4 ? boB <boB@k7iq.com> - 2017-08-17 13:42 -0700
        Re: Microchip ICD4 ? Lasse Langwadt Christensen <langwadt@fonz.dk> - 2017-08-17 14:23 -0700
          Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 17:46 -0400
        Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 17:44 -0400
          Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 18:40 -0400
            Re: Microchip ICD4 ? DemonicTubes <tlackie@gmail.com> - 2017-08-17 16:19 -0700
              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 22:04 -0400
            Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 20:03 -0400
              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 23:17 -0400
                Re: Microchip ICD4 ? "Michael A. Terrell" <mike.terrell@earthlink.net> - 2017-08-18 07:36 -0400
              Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-17 22:50 -0700
                Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-18 14:43 +0100
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 13:42 +0000
                  Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 12:49 -0400
                    Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 17:11 +0000
                      Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 16:22 -0400
                      Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-19 08:44 +0100
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:19 -0700
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-28 00:22 -0700
                    Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-09-02 16:35 +0000
                Re: Microchip ICD4 ? Cecil Bayona <cbayona@cbayona.com> - 2017-08-18 10:58 -0500
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 09:34 -0700
              Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 13:22 +0200
                Re: Microchip ICD4 ? stephen@mpeforth.com (Stephen Pelc) - 2017-08-18 11:54 +0000
                  Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 14:40 +0000
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 09:29 -0700
                    Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 17:06 +0000
                      Re: Microchip ICD4 ? Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-08-18 19:59 +0100
                        Re: Microchip ICD4 ? dplatt@coop.radagast.org (Dave Platt) - 2017-08-18 12:49 -0700
                          Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 01:52 +0200
                            Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 20:40 -0400
                              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 20:43 -0400
                              Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 13:03 +0200
                                Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-19 10:30 -0400
                                  Re: Microchip ICD4 ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-08-19 21:03 +0200
                          Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:28 -0700
                          Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:49 +0200
                        Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:43 +0200
                      Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:26 -0700
                Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 14:11 +0000
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:49 +0200
            Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 02:40 +0000
              Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-17 22:55 -0400
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 09:14 +0000
                  Re: Microchip ICD4 ? jack4747@gmail.com - 2017-08-18 03:10 -0700
                    Re: Microchip ICD4 ? Clive Arthur <cliveta@nowaytoday.co.uk> - 2017-08-18 11:38 +0100
                      Re: Microchip ICD4 ? Martin Brown <'''newspam'''@nezumi.demon.co.uk> - 2017-08-18 12:13 +0100
                      Re: Microchip ICD4 ? jack4747@gmail.com - 2017-08-18 04:25 -0700
                        Re: Microchip ICD4 ? Clive Arthur <cliveta@nowaytoday.co.uk> - 2017-08-18 13:43 +0100
                        Re: Microchip ICD4 ? Johann Klammer <klammerj@NOSPAM.a1.net> - 2017-08-18 23:40 +0200
                      Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:57 +0200
                        Re: Microchip ICD4 ? Przemek Klosowski <przemek@tux.dot.org> - 2017-08-22 03:24 +0000
                      Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 12:32 -0400
                  Re: Microchip ICD4 ? Neon John <no@never.com> - 2017-08-18 10:02 -0400
                    Re: Microchip ICD4 ? bitrex <bitrex@de.lete.earthlink.net> - 2017-08-18 11:02 -0400
                    Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:46 +0000
                      Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 16:57 +0200
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:54 +0200
              Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-17 23:01 -0400
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 07:58 +0000
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 01:19 -0700
                    Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-18 20:51 +0000
                      Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-18 23:35 -0700
                        Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:42 +0000
                          Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-20 19:49 -0700
                  Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-18 05:18 -0400
                    Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 07:22 +0000
                      Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-22 00:08 -0400
                        Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-21 22:41 -0700
                          Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-22 07:28 +0000
                            Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-23 16:52 -0400
              Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-17 22:54 -0700
              Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-18 16:36 +0200
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-20 08:49 +0000
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-21 17:03 +0200
                Re: Microchip ICD4 ? Terry Porter <terry@tjporter.com.au> - 2017-08-26 02:33 +0000
                  Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-26 01:55 -0400
                  Re: Microchip ICD4 ? Paul Rubin <no.email@nospam.invalid> - 2017-08-27 13:40 -0700
                    Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-09-02 12:58 -0400
                  Re: Microchip ICD4 ? David Brown <david.brown@hesbynett.no> - 2017-08-28 16:25 +0200
            Re: Microchip ICD4 ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-08-18 13:28 +0000
      Re: Microchip ICD4 ? speff <spehro@gmail.com> - 2017-08-17 19:09 -0700
      Re: Microchip ICD4 ? TTman <pcw1.cad@ntlworld.com> - 2017-08-18 10:12 +0100
        Re: Microchip ICD4 ? rickman <gnuarm@gmail.com> - 2017-08-18 05:21 -0400
          Re: Microchip ICD4 ? TTman <pcw1.cad@ntlworld.com> - 2017-08-18 12:10 +0100

Page 5 of 5 — ← Prev page 1 2 3 4 [5]


#474285

FromDavid Brown <david.brown@hesbynett.no>
Date2017-08-21 17:03 +0200
Message-ID<onesft$e1r$1@dont-email.me>
In reply to#474176
On 20/08/17 10:49, Terry Porter wrote:
> On Fri, 18 Aug 2017 16:36:26 +0200, David Brown wrote:
> 
> 
>> But just for a laugh, I tried to get a minimum msp430 blinky program.  I
>> picked an msp430f2619 device, because I have one, and port 2 pin 0 for
>> the LED (driving 0 to turn the LED on).  I have not tested the code at
>> all.
>>
>> I got 22 bytes with C code:
>>
>> #include <stdbool.h>
>> #include <msp430.h>
>> #include <stdint.h>
>>
>> uint8_t resetCounter;
>>
>> "  {
>>     resetCounter++;
>>     if (resetCounter & 0x20) {
>>         P2DIR = 0x01;
>>     }
>>     while (true) {
>>         // Wait for reset
>>     }
>> }
>>
>>
>> 00002100 <reset>:
>>     2100:	5f 42 00 11 	mov.b	&0x1100,r15 2104:	5f 
> 53       	inc.b	r15
>>     2106:	c2 4f 00 11 	mov.b	r15,	&0x1100 210a:	3f f0 20 
> 00 	and	#32,
>>     r15	;#0x0020 210e:	02 24       	jz	$+6      
> 	;abs 0x2114 2110:	d2 43
>>     2a 00 	mov.b	#1,	&0x002a	;r3 As==01 2114:	ff 
> 3f       	jmp	$+0      
>>     ;abs 0x2114
>>
>>
>> Compiled with:
>>
>> msp430-gcc blink.c -mmcu=msp430f2619 -nostartfiles -nodefaultlibs
>> -nostdlib -Os
>>
>>
>> The program relies on the watchdog to reset the chip after approximately
>> 30 milliseconds, and has the LED on for 32 rounds, then off for 32
>> rounds, for around 1 second blink.
>>
>>
>> I am curious about assembly code that will beat that.
> 
> Excellent, Thanks for such a complete and easy to reproduce followup :)

Just to be clear, I am not recommending the above code as a good example
of C programming!  Basing your timing on watchdog resets is rarely
considered good practice - this is just a minimal example.

And if you want to try it out, you will have to change the port used to
match the board as well as changing the "-mmcu" flag to match the real
device.

> 
> I'm waiting for some MSP430 boards and chips I ordered last week (I'm in 
> Australia and these are coming from Hong Kong), but when they arrive, I 
> promise to run your code, and if I'm not waiting for anyone else, I'll 
> publish the MSP430 assembly code that binks in 14 bytes.

It does not look like anyone else is taking your challenge.

> 
> (It's not my code, I'm not a MSP430 Assembly Wizard)
> 
> P.S. I'm just curious, is "void __attribute__((naked)) xreset(void)" a 
> assembly statement or a C statement ? ;-)
> 

It is a C statement, for the start of a function called "xreset" that
takes no parameters and has no return value.  The
"__attribute__((naked))" part is a gcc extension, telling the compiler
not to generate function prologue or epilogue code to keep it minimal.

[toc] | [prev] | [next] | [standalone]


#474820

FromTerry Porter <terry@tjporter.com.au>
Date2017-08-26 02:33 +0000
Message-ID<59a0de06$0$1586$c3e8da3$5496439d@news.astraweb.com>
In reply to#473850
On Fri, 18 Aug 2017 16:36:26 +0200, David Brown wrote:

> On 18/08/17 04:40, Terry Porter wrote:
>> On Thu, 17 Aug 2017 18:40:58 -0400, bitrex wrote:
>> 
>>> On 08/17/2017 05:44 PM, rickman wrote:
>>>> piglet wrote on 8/17/2017 4:23 PM:
>>>>> On 17/08/2017 20:52, bitrex wrote:
>>>>>> On 08/17/2017 01:45 PM, Martin Riddle wrote:
>>>>>>> Any folks using this ICD4?
>>>>>>>
>>>>>>> Cheers
>>>>>>>
>>>>>>>
>>>>>> I hope nobody's still writing uP code in asm in the year 2k17.
>>>>>
>>>>> I do, assembler is the best!
>>>>>
>>>>> With a good suite of macros can do anything better than them darn
>>>>> annoying "high level" languages claim.
>>>>
>>>> I have often thought of Forth as a macro assembler on steroids.
>>>> Mecrisp is being given optimizations that get it even closer to
>>>> working in assembler in terms of speed and code size.  Have you ever
>>>> looked at it?
>>>>
>>>>
>>> My contention is that well-written modern C++1x will destroy any
>>> handwritten asm or compiled-Forth "macro assembler" program on both
>>> execution speed and code size for any nontrivial general computing
>>> task in all but the most extreme edge-cases, even on say AVR 8 bit
>>> devices.
>>>
>>> There should be a contest! ;-)
>> 
>> Why not, personally I believe that hand wrtten assembly will murder any
>> modern C++1x, so here is my challenge.
>> 
>> A human-visible Blinky with the smallest binary size, and without
>> strange electrical states on other pins. A 'Blinky" blinks a LED around
>> once a second but may be faster or slower as long as it's clearly
>> 'blinking' to a human.
>> 
>> The targets:
>> MCU		       | Assembly binary size to beat so far:
>> 1) STM32F051 Discovery | 32 bytes 2) MSP340	       | 14 bytes
>> 
>> Note: The binary sizes above were above hand crafted by Matthias Koch,
>> author of Mecrisp, Mecrisp-Stellaris, Mecrisp-Across and many other
>> programs.
>> 
>> A personal note, my own efforts are tabled below, both are boring, no
>> shortcut tutorial Blinkies:
>> Assembly STM32F051 Discovery Blinky: 84 bytes.
>> GCC STM32F051 Discovery Blinky: 312 bytes.
>> 
>> 
> This is, of course, a completely pointless "contest".  It is like trying
> to compare two athletes in a 2 metre sprint.
> 
> But just for a laugh, I tried to get a minimum msp430 blinky program.  I
> picked an msp430f2619 device, because I have one, and port 2 pin 0 for
> the LED (driving 0 to turn the LED on).  I have not tested the code at
> all.
> 
> I got 22 bytes with C code:
> 
> #include <stdbool.h>
> #include <msp430.h>
> #include <stdint.h>
> 
> uint8_t resetCounter;
> 
> void __attribute__((naked)) xreset(void) {
>     resetCounter++;
>     if (resetCounter & 0x20) {
>         P2DIR = 0x01;
>     }
>     while (true) {
>         // Wait for reset
>     }
> }
> 
> 
> 00002100 <reset>:
>     2100:	5f 42 00 11 	mov.b	&0x1100,r15 2104:	5f 
53       	inc.b	r15
>     2106:	c2 4f 00 11 	mov.b	r15,	&0x1100 210a:	3f f0 20 
00 	and	#32,
>     r15	;#0x0020 210e:	02 24       	jz	$+6      
	;abs 0x2114 2110:	d2 43
>     2a 00 	mov.b	#1,	&0x002a	;r3 As==01 2114:	ff 
3f       	jmp	$+0      
>     ;abs 0x2114
> 
> 
> Compiled with:
> 
> msp430-gcc blink.c -mmcu=msp430f2619 -nostartfiles -nodefaultlibs
> -nostdlib -Os
> 
> 
> The program relies on the watchdog to reset the chip after approximately
> 30 milliseconds, and has the LED on for 32 rounds, then off for 32
> rounds, for around 1 second blink.
> 
> 
> I am curious about assembly code that will beat that.

I compiled your code, but it doesn't blink the LED, so you'll have to 
make it work and submit a binary if you're interested.

This is the working 14 byte binary Blinky written by Matthias Koch, which 
I verified on a MSP-EXP430G2 board with a MSP430G2553 chip.
=========================================================
  cpu msp430

  include "mspregister.asm"
  include "registers-classic.asm"

; 
-----------------------------------------------------------------------------
  org 0FFF2h  ; 14 Bytes to go.
; 
-----------------------------------------------------------------------------

Blinky:
  ; Do not stop the Watchdog timer. Let the free running Watchdog do the 
timing :-)
  mov.b #1, &P1DIR  ; Set LED pin as output
  add.b #8, r4      ; Delay a bit more. Watchdog triggers too fast to see.
  addc.b #0, &P1OUT ; Toggle LED on counter overflow by adding carry 
into: Led is on 1 :-)
- jmp -             ; Wait for next reset

; 
-----------------------------------------------------------------------------
; Vector table
; 
-----------------------------------------------------------------------------

  org 0FFFEh
  .word Blinky

  end

; How to assemble:  asl tinyblinky.asm && p2hex tinyblinky.p -r 
0x0000-0xFFFF
; How to flash:     mspdebug rf2500 "prog tinyblinky.hex"

Programming...
Writing   14 bytes at fff2...
Done, 14 bytes total

===========================================================


I think this shows that a hand written assembly program can be smaller
than a compiler generated binary.

I know the op said 'non trivial', but if a Compiler can't beat hand 
Assembly at the *simple things*, how will it beat hand Assembly at the 
complex things ?


As a matter of interest, this no tricks, standard Forth code Blinky when 
compiled by the Mecrisp-Across Compiler produced a 96 byte binary. 
(verified on my MSP-EXP430G2 board with a MSP430G2553 chip.)
 
: us 0 ?do i i + drop i i + drop loop inline ; 
: ms 0 ?do 998 us loop ;

: blinky ( -- )
  8MHz
  1 p1dir c!
  begin
    1 p1out cxor!
    1000 ms
  again
;

Programming...
Writing   80 bytes at f800...
Writing   16 bytes at fff0...
Done, 96 bytes total

-- 
Mecrisp-Stellaris Unofficial User Doc: http://128.199.141.78/index.html

[toc] | [prev] | [next] | [standalone]


#474824

Fromrickman <gnuarm@gmail.com>
Date2017-08-26 01:55 -0400
Message-ID<onr28c$fuv$1@dont-email.me>
In reply to#474820
Terry Porter wrote on 8/25/2017 10:33 PM:
> On Fri, 18 Aug 2017 16:36:26 +0200, David Brown wrote:
>>
>> But just for a laugh, I tried to get a minimum msp430 blinky program.  I
>> picked an msp430f2619 device, because I have one, and port 2 pin 0 for
>> the LED (driving 0 to turn the LED on).  I have not tested the code at
>> all.
>>
>> I got 22 bytes with C code:
>>
>> #include <stdbool.h>
>> #include <msp430.h>
>> #include <stdint.h>
>>
>> uint8_t resetCounter;
>>
>> void __attribute__((naked)) xreset(void) {
>>     resetCounter++;
>>     if (resetCounter & 0x20) {
>>         P2DIR = 0x01;
>>     }
>>     while (true) {
>>         // Wait for reset
>>     }
>> }
>>
>>
>> 00002100 <reset>:
>>     2100:	5f 42 00 11 	mov.b	&0x1100,r15 2104:	5f
> 53       	inc.b	r15
>>     2106:	c2 4f 00 11 	mov.b	r15,	&0x1100 210a:	3f f0 20
> 00 	and	#32,
>>     r15	;#0x0020 210e:	02 24       	jz	$+6
> 	;abs 0x2114 2110:	d2 43
>>     2a 00 	mov.b	#1,	&0x002a	;r3 As==01 2114:	ff
> 3f       	jmp	$+0
>>     ;abs 0x2114
>>
>>
>> Compiled with:
>>
>> msp430-gcc blink.c -mmcu=msp430f2619 -nostartfiles -nodefaultlibs
>> -nostdlib -Os
>>
>>
>> The program relies on the watchdog to reset the chip after approximately
>> 30 milliseconds, and has the LED on for 32 rounds, then off for 32
>> rounds, for around 1 second blink.
>>
>>
>> I am curious about assembly code that will beat that.
>
> I compiled your code, but it doesn't blink the LED, so you'll have to
> make it work and submit a binary if you're interested.
>
> This is the working 14 byte binary Blinky written by Matthias Koch, which
> I verified on a MSP-EXP430G2 board with a MSP430G2553 chip.
> =========================================================
>   cpu msp430
>
>   include "mspregister.asm"
>   include "registers-classic.asm"
>
> ;
> -----------------------------------------------------------------------------
>   org 0FFF2h  ; 14 Bytes to go.
> ;
> -----------------------------------------------------------------------------
>
> Blinky:
>   ; Do not stop the Watchdog timer. Let the free running Watchdog do the
> timing :-)
>   mov.b #1, &P1DIR  ; Set LED pin as output
>   add.b #8, r4      ; Delay a bit more. Watchdog triggers too fast to see.
>   addc.b #0, &P1OUT ; Toggle LED on counter overflow by adding carry
> into: Led is on 1 :-)
> - jmp -             ; Wait for next reset
>
> ;
> -----------------------------------------------------------------------------
> ; Vector table
> ;
> -----------------------------------------------------------------------------
>
>   org 0FFFEh
>   .word Blinky
>
>   end
>
> ; How to assemble:  asl tinyblinky.asm && p2hex tinyblinky.p -r
> 0x0000-0xFFFF
> ; How to flash:     mspdebug rf2500 "prog tinyblinky.hex"
>
> Programming...
> Writing   14 bytes at fff2...
> Done, 14 bytes total
>
> ===========================================================
>
>
> I think this shows that a hand written assembly program can be smaller
> than a compiler generated binary.
>
> I know the op said 'non trivial', but if a Compiler can't beat hand
> Assembly at the *simple things*, how will it beat hand Assembly at the
> complex things ?

I think the point is that a human is capable of doing some very optimal 
things when the code is small as a lot of thought can be given to optimizing 
the small task relative the total effort.  But with a large program it is 
much harder for a person to optimize the total program while it is still not 
such a hard task for a computer.

-- 

Rick C

Viewed the eclipse at Wintercrest Farms,
on the centerline of totality since 1998

[toc] | [prev] | [next] | [standalone]


#475008

FromPaul Rubin <no.email@nospam.invalid>
Date2017-08-27 13:40 -0700
Message-ID<87r2vwrbgi.fsf@nightsong.com>
In reply to#474820
Terry Porter <terry@tjporter.com.au> writes:
> I know the op said 'non trivial', but if a Compiler can't beat hand 
> Assembly at the *simple things*, how will it beat hand Assembly at the 
> complex things ?

Can you do a handstand?  Probably yes, with some practice.

Can a robot do a handstand?  Maybe not quite as well as you can.

Can you STAY in that handstand 8 hours a day, 5 days a week?  Hell no.

Can the robot?  No problem, even 24/7 is fine, even if that handstand
isn't quite as good as your 2 minute one.

Non-trivial program = one that takes months of full-time programming.
Optimizing asm = doing handstand while writing the code.

If you spend months writing an asm program, most of it will almost
certainly be relatively unoptimized, though you might tune the most
critical loops very carefully.  The robot (compiler) code will be
optimized all the way through, though you might still beat it in a few
critical places.

So the best optimality recipe for now is hand-code the very critical
parts, and let the compiler do the rest.

[toc] | [prev] | [next] | [standalone]


#475992

Fromrickman <gnuarm@gmail.com>
Date2017-09-02 12:58 -0400
Message-ID<ooenng$2fr$1@dont-email.me>
In reply to#475008
Paul Rubin wrote on 8/27/2017 4:40 PM:
> Terry Porter <terry@tjporter.com.au> writes:
>> I know the op said 'non trivial', but if a Compiler can't beat hand
>> Assembly at the *simple things*, how will it beat hand Assembly at the
>> complex things ?
>
> Can you do a handstand?  Probably yes, with some practice.
>
> Can a robot do a handstand?  Maybe not quite as well as you can.
>
> Can you STAY in that handstand 8 hours a day, 5 days a week?  Hell no.
>
> Can the robot?  No problem, even 24/7 is fine, even if that handstand
> isn't quite as good as your 2 minute one.
>
> Non-trivial program = one that takes months of full-time programming.
> Optimizing asm = doing handstand while writing the code.
>
> If you spend months writing an asm program, most of it will almost
> certainly be relatively unoptimized, though you might tune the most
> critical loops very carefully.  The robot (compiler) code will be
> optimized all the way through, though you might still beat it in a few
> critical places.
>
> So the best optimality recipe for now is hand-code the very critical
> parts, and let the compiler do the rest.

I don't agree with your simplistic analysis.  When I code VHDL I am 
constantly thinking of implementation as it is much easier to think of the 
optimal way of doing things early rather than retrofitting.  It is nothing 
like hand stands and I think the analogy is not valid.

-- 

Rick C

Viewed the eclipse at Wintercrest Farms,
on the centerline of totality since 1998

[toc] | [prev] | [next] | [standalone]


#475112

FromDavid Brown <david.brown@hesbynett.no>
Date2017-08-28 16:25 +0200
Message-ID<oo18sm$6vo$1@dont-email.me>
In reply to#474820
On 26/08/17 04:33, Terry Porter wrote:
> On Fri, 18 Aug 2017 16:36:26 +0200, David Brown wrote:
> 
>> On 18/08/17 04:40, Terry Porter wrote:
>>> On Thu, 17 Aug 2017 18:40:58 -0400, bitrex wrote:
>>>
>>>> On 08/17/2017 05:44 PM, rickman wrote:
>>>>> piglet wrote on 8/17/2017 4:23 PM:
>>>>>> On 17/08/2017 20:52, bitrex wrote:
>>>>>>> On 08/17/2017 01:45 PM, Martin Riddle wrote:
>>>>>>>> Any folks using this ICD4?
>>>>>>>>
>>>>>>>> Cheers
>>>>>>>>
>>>>>>>>
>>>>>>> I hope nobody's still writing uP code in asm in the year 2k17.
>>>>>>
>>>>>> I do, assembler is the best!
>>>>>>
>>>>>> With a good suite of macros can do anything better than them darn
>>>>>> annoying "high level" languages claim.
>>>>>
>>>>> I have often thought of Forth as a macro assembler on steroids.
>>>>> Mecrisp is being given optimizations that get it even closer to
>>>>> working in assembler in terms of speed and code size.  Have you ever
>>>>> looked at it?
>>>>>
>>>>>
>>>> My contention is that well-written modern C++1x will destroy any
>>>> handwritten asm or compiled-Forth "macro assembler" program on both
>>>> execution speed and code size for any nontrivial general computing
>>>> task in all but the most extreme edge-cases, even on say AVR 8 bit
>>>> devices.
>>>>
>>>> There should be a contest! ;-)
>>>
>>> Why not, personally I believe that hand wrtten assembly will murder any
>>> modern C++1x, so here is my challenge.
>>>
>>> A human-visible Blinky with the smallest binary size, and without
>>> strange electrical states on other pins. A 'Blinky" blinks a LED around
>>> once a second but may be faster or slower as long as it's clearly
>>> 'blinking' to a human.
>>>
>>> The targets:
>>> MCU		       | Assembly binary size to beat so far:
>>> 1) STM32F051 Discovery | 32 bytes 2) MSP340	       | 14 bytes
>>>
>>> Note: The binary sizes above were above hand crafted by Matthias Koch,
>>> author of Mecrisp, Mecrisp-Stellaris, Mecrisp-Across and many other
>>> programs.
>>>
>>> A personal note, my own efforts are tabled below, both are boring, no
>>> shortcut tutorial Blinkies:
>>> Assembly STM32F051 Discovery Blinky: 84 bytes.
>>> GCC STM32F051 Discovery Blinky: 312 bytes.
>>>
>>>
>> This is, of course, a completely pointless "contest".  It is like trying
>> to compare two athletes in a 2 metre sprint.
>>
>> But just for a laugh, I tried to get a minimum msp430 blinky program.  I
>> picked an msp430f2619 device, because I have one, and port 2 pin 0 for
>> the LED (driving 0 to turn the LED on).  I have not tested the code at
>> all.
>>
>> I got 22 bytes with C code:
>>
>> #include <stdbool.h>
>> #include <msp430.h>
>> #include <stdint.h>
>>
>> uint8_t resetCounter;
>>
>> void __attribute__((naked)) xreset(void) {
>>     resetCounter++;
>>     if (resetCounter & 0x20) {
>>         P2DIR = 0x01;
>>     }
>>     while (true) {
>>         // Wait for reset
>>     }
>> }
>>
>>
>> 00002100 <reset>:
>>     2100:	5f 42 00 11 	mov.b	&0x1100,r15 2104:	5f 
> 53       	inc.b	r15
>>     2106:	c2 4f 00 11 	mov.b	r15,	&0x1100 210a:	3f f0 20 
> 00 	and	#32,
>>     r15	;#0x0020 210e:	02 24       	jz	$+6      
> 	;abs 0x2114 2110:	d2 43
>>     2a 00 	mov.b	#1,	&0x002a	;r3 As==01 2114:	ff 
> 3f       	jmp	$+0      
>>     ;abs 0x2114
>>
>>
>> Compiled with:
>>
>> msp430-gcc blink.c -mmcu=msp430f2619 -nostartfiles -nodefaultlibs
>> -nostdlib -Os
>>
>>
>> The program relies on the watchdog to reset the chip after approximately
>> 30 milliseconds, and has the LED on for 32 rounds, then off for 32
>> rounds, for around 1 second blink.
>>
>>
>> I am curious about assembly code that will beat that.
> 
> I compiled your code, but it doesn't blink the LED, so you'll have to 
> make it work and submit a binary if you're interested.

As I said, I guessed at a pin for the LED because I do not have the
board.  I can't test the code!  But based on the code below, you should
replace :

	P2DIR = 0x01;

with

	P1DIR = 0x01;
	P1OUT = 0x01;

It looks like you also have to change the linker script to fit the reset
vector for the chip in question.  But there is no point in fiddling with
that - it is the principle that we are discussing.

> 
> This is the working 14 byte binary Blinky written by Matthias Koch, which 
> I verified on a MSP-EXP430G2 board with a MSP430G2553 chip.
> =========================================================
>   cpu msp430
> 
>   include "mspregister.asm"
>   include "registers-classic.asm"
> 
> ; 
> -----------------------------------------------------------------------------
>   org 0FFF2h  ; 14 Bytes to go.
> ; 
> -----------------------------------------------------------------------------
> 
> Blinky:
>   ; Do not stop the Watchdog timer. Let the free running Watchdog do the 
> timing :-)
>   mov.b #1, &P1DIR  ; Set LED pin as output
>   add.b #8, r4      ; Delay a bit more. Watchdog triggers too fast to see.
>   addc.b #0, &P1OUT ; Toggle LED on counter overflow by adding carry 
> into: Led is on 1 :-)
> - jmp -             ; Wait for next reset
> 

It is possible to use a gcc extension to put the counter value in a
register rather than in the ram (as I did), but I would say that is
cheating when writing in C.  The "addc" trick here is nice for getting
minimal assembly, and cannot be generated in C.

> ; 
> -----------------------------------------------------------------------------
> ; Vector table
> ; 
> -----------------------------------------------------------------------------
> 
>   org 0FFFEh
>   .word Blinky
> 
>   end
> 
> ; How to assemble:  asl tinyblinky.asm && p2hex tinyblinky.p -r 
> 0x0000-0xFFFF
> ; How to flash:     mspdebug rf2500 "prog tinyblinky.hex"
> 
> Programming...
> Writing   14 bytes at fff2...
> Done, 14 bytes total
> 
> ===========================================================
> 
> 
> I think this shows that a hand written assembly program can be smaller
> than a compiler generated binary.

It does, but in the same way as you can "prove" that walking is faster
than using a car by comparing how long it takes to visit your neighbour.

> 
> I know the op said 'non trivial', but if a Compiler can't beat hand 
> Assembly at the *simple things*, how will it beat hand Assembly at the 
> complex things ?
> 

The compiler will do far better at complex things precisely /because/
they are complex.  As I have already said, in theory a compiler can
never be better than hand assembly because the assembly programmer can
write the same stuff as the compiler generates.  But in practice - when
you add requirements such as clarity, maintainability, flexibility and
reasonable development time - C and a good compiler will beat the
assembly programmer for real-life programming tasks on an msp430 or
other sensible processor.  It is no problem for an assembly programmer
to track a register or two in a trivial task - it is a different matter
entirely when things get serious.

> 
> As a matter of interest, this no tricks, standard Forth code Blinky when 
> compiled by the Mecrisp-Across Compiler produced a 96 byte binary. 
> (verified on my MSP-EXP430G2 board with a MSP430G2553 chip.)
>  
> : us 0 ?do i i + drop i i + drop loop inline ; 
> : ms 0 ?do 998 us loop ;
> 
> : blinky ( -- )
>   8MHz
>   1 p1dir c!
>   begin
>     1 p1out cxor!
>     1000 ms
>   again
> ;
> 
> Programming...
> Writing   80 bytes at f800...
> Writing   16 bytes at fff0...
> Done, 96 bytes total
> 


[toc] | [prev] | [next] | [standalone]


#473840

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-08-18 13:28 +0000
Message-ID<2017Aug18.152854@mips.complang.tuwien.ac.at>
In reply to#473768
bitrex <bitrex@de.lete.earthlink.net> writes:
>My contention is that well-written modern C++1x will destroy any 
>handwritten asm or compiled-Forth "macro assembler" program on both 
>execution speed and code size for any nontrivial general computing task 
>in all but the most extreme edge-cases, even on say AVR 8 bit devices.
>
>There should be a contest! ;-)

Well, go ahead, and try the challenge I have stated for nasal demon
worshippers*:

Write a proof-of-concept Forth interpreter in the language you
advocate that runs at least one of bubble-sort, matrix-mult or sieve
from bench/forth in
<http://www.complang.tuwien.ac.at/forth/bench.zip>

* I don't know if you are of that religion, but belief in compiler
  supremacy often goes with nasal demon worship; if you don't know
  "nasal demon", you probably don't worship them.

Followups set to comp.lang.forth

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2017: http://euro.theforth.net/

[toc] | [prev] | [next] | [standalone]


#473793

Fromspeff <spehro@gmail.com>
Date2017-08-17 19:09 -0700
Message-ID<8decce10-0ad4-4a35-916b-8141adb2cdf6@googlegroups.com>
In reply to#473744
On Thursday, 17 August 2017 15:52:51 UTC-4, bitrex  wrote:
> On 08/17/2017 01:45 PM, Martin Riddle wrote:
> > Any folks using this ICD4?
> > 
> > Cheers
> > 
> 
> I hope nobody's still writing uP code in asm in the year 2k17.

You would use an ICD4 if you are writing code for the Microchip family in C.. it's the flash programming/debug pod, analogous to a J-Link or U-link. 

--sp 

[toc] | [prev] | [next] | [standalone]


#473816

FromTTman <pcw1.cad@ntlworld.com>
Date2017-08-18 10:12 +0100
Message-ID<on6aqc$a2p$1@dont-email.me>
In reply to#473744
On 17/08/2017 20:52, bitrex wrote:
> On 08/17/2017 01:45 PM, Martin Riddle wrote:
>> Any folks using this ICD4?
>>
>> Cheers
>>
> 
> I hope nobody's still writing uP code in asm in the year 2k17.

Why not ? I've written in assembler since mid 70's. Guess that makes me 
a Dinosaur :(

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

[toc] | [prev] | [next] | [standalone]


#473819

Fromrickman <gnuarm@gmail.com>
Date2017-08-18 05:21 -0400
Message-ID<on6bam$b23$2@dont-email.me>
In reply to#473816
TTman wrote on 8/18/2017 5:12 AM:
> On 17/08/2017 20:52, bitrex wrote:
>> On 08/17/2017 01:45 PM, Martin Riddle wrote:
>>> Any folks using this ICD4?
>>>
>>> Cheers
>>>
>>
>> I hope nobody's still writing uP code in asm in the year 2k17.
>
> Why not ? I've written in assembler since mid 70's. Guess that makes me a
> Dinosaur :(
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus

I think writing *any* code since the 70's makes you a dinosaur.  ;)

-- 

Rick C

[toc] | [prev] | [next] | [standalone]


#473828

FromTTman <pcw1.cad@ntlworld.com>
Date2017-08-18 12:10 +0100
Message-ID<on6hmd$u1p$1@dont-email.me>
In reply to#473819
On 18/08/2017 10:21, rickman wrote:
> TTman wrote on 8/18/2017 5:12 AM:
>> On 17/08/2017 20:52, bitrex wrote:
>>> On 08/17/2017 01:45 PM, Martin Riddle wrote:
>>>> Any folks using this ICD4?
>>>>
>>>> Cheers
>>>>
>>>
>>> I hope nobody's still writing uP code in asm in the year 2k17.
>>
>> Why not ? I've written in assembler since mid 70's. Guess that makes me a
>> Dinosaur :(
>>
>> ---
>> This email has been checked for viruses by Avast antivirus software.
>> https://www.avast.com/antivirus
> 
> I think writing *any* code since the 70's makes you a dinosaur.  ;)
> 
Quite right ! I started with the Intel 8047/8 and swiftly moved to the 
87  series with on board Eprom. I designed/built a rally navigation 
time/distance meter with it.....and laterly Laser Tag using 89C51ED2s

[toc] | [prev] | [standalone]


Page 5 of 5 — ← Prev page 1 2 3 4 [5]

Back to top | Article view | sci.electronics.design


csiph-web