This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

A road less traveled, ASM for Stellaris

I have to admit that I am kind of weird. I am an old hobbyist starting from the Intel 4004 days, but I have ignored ARM for decades. It is only very recent that I start to poke at TI's Stellaris Launchpad when a friend loaned me one. There is a lot for me to catch up.

To start with, I tried to blink the RGB LEDs on the Launchpad. This is similar to one of the TI examples "Blinky". But I did it with the IAR Assembler and Linker to generate a binary file. And I used FLASHER to download that binary file to the Launchpad. It works the way I intended -- an infinity loop that cycles through 7 colors, a short pause, 3 prime colors, a long pause, and repeat.

Here is the binary file: 8154.Blinky.bin.txt -- But you need to rename that file by deleting the last four characters ".txt" so that the file name becomes "Blinky.bin".


And here is the assembly listing:

###############################################################################
#                                                                             #
#     IAR Assembler V6.40.1.53790/W32 for ARM 03/Feb/2013  07:10:25           #
#     Copyright 1999-2012 IAR Systems AB.                                     #
#                                                                             #
#           Source file   =  C:\MyWork\Bllinky.s                              #
#           List file     =  C:\MyWork\Debug\Bllinky.lst                      #
#           Object file   =  C:\MyWork\Debug\Bllinky.o                        #
#           Command line  =  C:\MyWork\Bllinky.s -OC:\MyWork\Debug\ -s+ -M<>  #
#                            -w+ -r -LC:\MyWork\Debug\ -t8 --cpu Cortex-M4F   #
#                            --fpu VFPv4_sp                                   #
#                                                                             #
###############################################################################

    1                                   PUBLIC  __iar_program_start
    2                                   SECTION .intvec : CODE
    3                                   DATA
    4    00000000 00800020              DC32    0x20008000
    5    00000004 ........              DC32    __iar_program_start
    6                                   CODE
    7                           __iar_program_start:
    8    00000008 0848          main:   LDR     R0, rcgc2
    9    0000000A 2021                  MOVS    R1, #0x20       ;clockF
   10    0000000C 0160                  STR     R1, [R0]
   11    0000000E 0848                  LDR     R0, dirF
   12    00000010 48F22E01              MOV     R1, #0x802E     ;magic#
   13    00000014 0160                  STR     R1, [R0]
   14    00000016 C0F81C11              STR     R1, [R0, #0x11C];denF
   15    0000001A C0F22002      loop:   MOVT    R2, #0x20
   16    0000001E 013A          wait:   ADDS    R2, #-1
   17    00000020 FDD1                  BNE     wait       
   18    00000022 40F8041C              STR     R1, [R0,#-4]    ;dataF
   19    00000026 4FEA7101              ROR     R1, R1, #1
   20    0000002A F6E7                  B       loop
   21                                   DATA
   22    0000002C 08E10F40      rcgc2:  DC32    0x400FE108
   23    00000030 00540240      dirF:   DC32    0x40025400
   24                                   END
##############################
#           CRC:0            #
#        Errors:   0         #
#        Warnings: 0         #
#         Bytes: 52          #
##############################




  • Next I tried to  code something similar to another TI examples "uart_echo.c".

    Here is the binary file: 4682.Uart_Echo.bin.txt -- But you need to rename that file by deleting the last four characters ".txt" so that the file name becomes "Uart_Echo.bin".

    And here is the assembly listing.

    ###############################################################################
    #                                                                             #
    #     IAR Assembler V6.40.1.53790/W32 for ARM 09/Feb/2013  08:26:36           #
    #     Copyright 1999-2012 IAR Systems AB.                                     #
    #                                                                             #
    #           Source file   =  C:\MyWork\Uart_Echo.s                            #
    #           List file     =  C:\MyWork\Debug\List\Uart_Echo.lst               #
    #           Object file   =  C:\MyWork\Debug\Obj\Uart_Echo.o                  #
    #           Command line  =  C:\MyWork\Uart_Echo.s -OC:\MyWork\Debug\Obj\     #
    #                            -s+ -M<> -w+ -r -LC:\MyWork\Debug\List\ -t8      #
    #                            --cpu Cortex-M4F --fpu VFPv4_sp                  #
    #                                                                             #
    ###############################################################################

        1                                   PUBLIC  __iar_program_start
        2                                   SECTION .intvec : CODE
        3                                   DATA
        4    00000000 00800020              DC32    0x20008000
        5    00000004 ........              DC32    __iar_program_start
        6                                   CODE
        7                           __iar_program_start:
        8    00000008 1448                  LDR     R0, uart0
        9    0000000A 154C                  LDR     R4, rom
       10    0000000C 256B                  LDR     R5, [R4, #0x30]
       11    0000000E AE69                  LDR     R6, [R5, #0x18]
       12    00000010 B047                  BLX     R6              ;Enable
                                                                     uart0
       13    00000012 1448                  LDR     R0, gpioA
       14    00000014 B047                  BLX     R6              ;Enable
                                                                     gpioA
       15    00000016 4FF04020              MOV.W   R0, #0x40004000 ;baseA
       16    0000001A 0321                  MOVS    R1, #0x03       ;bit1
                                                                     +bit0
       17    0000001C E668                  LDR     R6, [R4, #0x0C]
       18    0000001E 766D                  LDR     R6, [R6, #0x54]
       19    00000020 B047                  BLX     R6              ;pin type
       20    00000022 2E6E                  LDR     R6, [R5, #0x60]
       21    00000024 B047                  BLX     R6              ;get clock
                                                                     frequency
       22    00000026 0146                  MOV     R1, R0
       23    00000028 1048                  LDR     R0, uart0D
       24    0000002A 4FF4E132              MOV     R2, #115200
       25    0000002E 4FF06003              MOV     R3, #0x60
       26    00000032 2568                  LDR     R5, [R4]
       27    00000034 0446                  MOV     R4, R0
       28    00000036 6E69                  LDR     R6, [R5, #0x14]
       29    00000038 B047                  BLX     R6              ;115200,
                                                                     8N1
       30    0000003A AE6B                  LDR     R6, [R5, #0x38]
       31    0000003C 2D68                  LDR     R5, [R5]
       32    0000003E B047          main:   BLX     R6              ;wait for
                                                                     RXD
       33    00000040 0D28                  CMP     R0, #0x0D       ;<CR>?
       34    00000042 03D0                  BEQ     gotCR
       35    00000044 C1B2                  UXTB    R1, R0
       36    00000046 2046                  MOV     R0, R4
       37    00000048 A847                  BLX     R5              ;send to
                                                                     TXD
       38    0000004A F8E7                  B       main
       39    0000004C 7027          gotCR:  MOVS    R7, #0x70       ;the snake
       40    0000004E 3978          next:   LDRB    R1, [R7]
       41    00000050 0137                  ADDS    R7, #1
       42    00000052 0029                  CMP     R1, #0
       43    00000054 F3D0                  BEQ     main
       44    00000056 2046                  MOV     R0, R4
       45    00000058 A847                  BLX     R5
       46    0000005A F8E7                  B       next
       47                                   DATA
       48    0000005C 01000010      uart0:  DC32    0x10000001
       49    00000060 14000001      rom:    DC32    0x01000014
       50    00000064 01000020      gpioA:  DC32    0x20000001
       51    00000068 2C450040      pctlA:  DC32    0x4000452C
       52    0000006C 00C00040      uart0D: DC32    0x4000C000
       53    00000070 0D0A4D7920736 snake:  DC8     "\r\nMy snake is mightier than
                                                     yours. Mine has legs!\r\n"
                      E616B65206973
                      206D696768746
                      9657220746861
                      6E20796F75727
                      32E204D696E65
                      20686173206C6
                      56773210D0A00
       54                                   END
    ##############################
    #           CRC:0            #
    #        Errors:   0         #
    #        Warnings: 0         #
    #         Bytes: 164         #
    ##############################

  • Past tempted to comment/respond - flesh (though weak) resisted.  Now - resistance futile...

    To begin - deep thanks for your long and detailed forum participation - you've helped many.

    While I don't go back to the hallowed 4004 days - we did employ both Intel & Zilog 8 bit MCUs in various control and display applications - and had significant success.  And - in the beginning - such code was always in ASM.  (only real choice)  And Intel attracted so many as they were the first to provide a large number of ASM coding examples - which really helped many - "over the bumps." 

    Now - like many - we also started developing PC applications - and the various PC "pro" programming applications were so far beyond our ASM world - we could not wait for "C" to enter our embedded MCU World.  And gradually - and at last - it did.  And we were over-joyed - even though early C versions were stripped-down & buggy.

    Moving to today's, "Real World" - you have a deep and fine "ASM" knowledge and skill level - likely far beyond that of most here.  And - while I suspect that code you've presented runs flawlessly - the same cannot be said/hoped for the ASM attempts of those newer - and far less skilled...

    Believe that its also generally agreed that programming in "C" produces results far faster than "ASM."   With product development times shrinking - hard for most firms/concerns to "buck this trend."

    Myself/others believe that much of LMI's early success resulted from the extensive Code Library - written almost exclusively in "C."  (even the ISRs)  And every single one of these C source files have been used/exercised repeatedly (perhaps > 10K times) and very few "bug" reports have been reported.  (and those reported - quickly fixed)

    Thus there is over-whelming "Safety, Efficiency & Utility" in, "Following this C Herd" - which goes far to explain (and perhaps justify) ASM's being a, "road less traveled!"

  • Well yeah... but he even wants to use FORTH -- which is bizarre enough ;-)

    Me? I'm holding out for FIFTH before I even touch it.

    I would rather stand on the shoulders of giants...

  • @ Monsieur Robinson:

    Gone, "off medication" - once again? 

    Surely hope I don't receive (yet another) late night/panicked foncon from the "facility" - advising that one "guest" (inmate) is awol...

    Facility's 8 foot, barbed top walls insufficient when - "standing on shoulders..."   Do try to "blend in" - if that's possible...

  • The assembler+disassembler+decompiler+xcompiler+tinyForth(tF) development system has been posted here in
    Special emphasis on algebraic assembly language would be raised.
    The beauty of algebraic assembly language and macroassembler  in additional to structural style instruction could be found here, such as:

      t:  4drop      {nip}
      t:  3drop      {nip}
      t:  2drop      {nip}
      t:  drop       {drop}
      t:  noop       ret'
      t:  nip        {nip}
                     ret'
      t:  ?dup       if'T<>0  t:  dup  {dup}  then'   ret'
      .
      t:  0~F>'0'~'F'    R7n0F    r7:0a ( not 9 )  if'u>=  r7+7  then'   r7+30   ret'   \ digit

      t:  '0'~'F'>0~F                      R7+D0          ( 30 ... 0 )                  \ 32 10 digit --> 2 -1
                                           r7:100
                 IF'c=1           r7nff    R7+F6          \  30~39 => F6~FF
                                  r7:100
                     IF'c=0    (  r7n0f )  R7+0A   r7n0f   ret'  \   0~9
                     ENDIF'                R7nDF          \ lower case -> UPPER CASE
                                           R7+F9          \
                                  r7:100
                     IF'c=1       r7n0ff   R7+FA          \  41~46 => FA~FF
                                  r7:100
                          IF'c=0           R7n0F    ret'  \   A~F
                          ENDIF'
                     ENDIF'
                 ENDIF'
      t:  <t=-1>          begin'           R7=0/    ret'  

      t:  0<       {2*}   until'c=0

    The main program starts from tF  ( tinyForth).

      t:  tF       rd=20000280     r5=20000400 ( sp0 )    PortF_Init ( initialize )   .".tF"
          begin'   GET+EXECUTE.COMMAND
          again'

    Here is the disassembling list.

      \ ------------------------------------------------------------------------
                                        t:  tF                                                      cfa= 964
      (  00000964  40 F2 80 2D       )              RD=280
      (  00000968  C2 F2 00 0D       )              RDt=2000
      (  0000096C  40 F2 00 45       )              R5=400
      (  00000970  C2 F2 00 05       )              R5t=2000
      (  00000974  FF F7 EA FC       )                  PortF_Init                                  \      34C
      (  00000978  FF F7 70 FF       )                  cr                                          \      85C
      (  0000097C  FF F7 9A FE       )                  dup                                         \      6B4
      (  00000980  74 27             )              R7=74
      (  00000982  FF F7 83 FD       )                  emit                                        \      48C
      (  00000986  FF F7 95 FE       )                  dup                                         \      6B4
      (  0000098A  46 27             )              R7=46
      (  0000098C  FF F7 7E FD       )                  emit                                        \      48C
      (  00000990  FF F7 70 FF       )                  space                                       \      874
      (  00000994  FF F7 D0 FF       )                  GET+EXECUTE.COMMAND                         \      938
      (  00000998  FC E7             )              jmp.994

     

    Hope you'll like this kind of ASSEMBLY LANGUAGE.