Skip to main content
Explorer
March 20, 2020
Solved

Are there any assembler example programs to get familiar with the 8S105 series?

  • March 20, 2020
  • 8 replies
  • 3771 views

I have the 8S105C based Discovery. I'm new to STM, but been writing NXP 9S08 assembler >20 yrs. Customer has 2 products using 9S08PA4, but needs them ported to STM8S. Both are pure assembler - I wrote them and now must port. Best of worlds would illustrate ADC, Timer and PWM aspects, but I'd be happy with just some simple GPIO and the framework to assemble, download and debug. I've looked and see all kinds of C, but only an ST7 asm example - enough different to not seem practical. Thanks in advance, Kevin (66yo newby)

    This topic has been closed for replies.
    Best answer by Ozone

    Not many STM8 users here, and even less that fiddle with assembler.

    However, you could go the indirect route.

    Take a C example, compile it, and look at the generated assembler code.

    You might need to tweak the compiler settings to generate asm files at all.

    8 replies

    Explorer
    March 24, 2020

    Ok, Fine, I'll figure it out myself.

    OzoneAnswer
    Explorer
    March 24, 2020

    Not many STM8 users here, and even less that fiddle with assembler.

    However, you could go the indirect route.

    Take a C example, compile it, and look at the generated assembler code.

    You might need to tweak the compiler settings to generate asm files at all.

    Explorer
    March 25, 2025

    I've tried that a couple times, Failing Miserably!!  Compilers aren't meant to be read by people.  Calls to libraries you have NO clue where, OR whether They call Other Libraries.  The central reason I write assembler is It Can't LIE!

    I'll write a Fair Amount More code but, I get to control ALL of it!

    Fave joke: The upside of assembler?  It does EXACTLY what you tell it!

    The downside of assembler?  It does EXACTLY what you tell it!    (teehee)    <<<)))

    Graduate II
    March 24, 2020

    I'm also training for STM8 Assembly Language coding. Hope to see your advancement.

    Explorer
    March 24, 2020

    Thanks for the replies, I was getting discouraged. Ozone is right in a dearth of assembler pilots. But where would OOP and 4GL flyers be without us shrubs writing device drivers and atomic little service routines where speed and size are paramount? When I started out 4MHz and 64k RAM was a big machine, so assembler was a good idea for fairly simple stuff. A steady stream of projects from colleagues and customers and it's 40 years later.

    I'm just at LED blinking, ADC reading and learning the timers. But that's enough to port one project as a start. Structural stuff still confuses me; segments, including address equate files, etc. Single segment linear code may be crude, but enough for now.

    Thanks, MQi.1 for the links. I'll answer stuff if I think I'm helping. Good Hunting, <<<)))

    Visitor II
    March 30, 2020

    Hi CustomSarge!

    I write my programs in assembler for STM8s. I use the asst8 & aslink assembler and linker form asxxxx (https://shop-pdp.net/ashtml/asxxxx.htm).

    After you get used to it and know the instructions it can be way more fun than C. Implementing functions is really easy and can be used across multiple projects especially because of the STM8 architecture and the same type of peripherals in families.

    Below a verry short example of STM8 assembler coding:

    ;Some definitions here...
    .equ VBATT_ICORR,		36
    .equ SRAM_VBATT,		0x00C4
     
    .area MAIN_CODE (ABS,CSEG)
    .org 0x008000
    			int RESET
    			int TRAP_INT
    			int TLI_INT
    ....
    RESET:
    ;select external crystal osc.
    			bset CLK_SWCR, #CLK_SWCR_SWEN_bp
    			mov CLK_SWR, #CLK_SWR_HSE_gc
    ;setup port B
    			ld A, #(1<<BLIN_0)|(1<<BOUT_EN_1)|(1<<BHIN_2)
    			ld PB_DDR, A
    			ld PB_CR1, A
    			ld PB_CR2, A
    ;start RTC
    			call Start_RTC
    ....
     
    Start_RTC:
    ;this is a function called above
    	;setam Frtcclk = Fmaster/128 = 18,432/128 = 144,000 kHz
    			mov CLK_CRTCR, #CLK_CRTCR_DIV_128_gc|CLK_CRTCR_SEL_HSE_gc
    	;activam Frtcclk pentru RTC
    			bset CLK_PCKENR2, #CLK_PCKENR2_RTC_bp
    	;dezactivam write protection pentru registrii RTC
    			mov RTC_WPR, #0xCA
    			mov RTC_WPR, #0x53
    	;intram in init mode sa putem configura RTC
    			bset RTC_ISR1, #RTC_ISR1_INIT_bp
    .....
    			mov RTC_WPR, #0xFF
    			ret

    You would need to fetch the definitions files from some compiler - if you don't want to do it manually, I hope not :) !

    Explorer
    March 30, 2020

    Thanks, Cristian. I'm boots-forward - read the datasheet and set the device registers accordingly.

    When I was learning ('78+), library errors were all too common.

    I vowed to never be held hostage to someone else's definitions / libraries.

    I have the chip (8S105CxT6) doing all I need for now.

    Only thing I really could use is how to get the full set of register address equates included.

    I'm using the ST Visual Development assembler / linker,

    I'm writing my own for now, in the NXP9S08 it was done at project generation.

    There must be a way in STVD, I'm just not seeing it - but it's not a deal breaker.

    It's SO refreshing to have so many addressing modes.

    I learned Z80 first, went HC908 in mid '90s (colleague demanded it), then 9S08 when it came out.

    But I always missed multiple index registers and Mostly indirect addressing.

    I'm asking questions now, but will be answering as I get better with the STM8 series.

    If there's a forum for us "bit bangers", let me know.

    If not, maybe start one? It may not get a lot of traffic, but we know & do tricks compilers can't.

    Thanks to All - now and as we move forward. CS

    Weird - my chevrons don't show and the word hard+core is asterisked out ?

    Had to sub CS & boots-forward - huh?

    Visitor II
    September 8, 2024

    Hello! I wrote a small library for initialization UART, TIM, ADC,CLK,  maybe it will be usefull for you: https://github.com/aaw20904/STM8_library/tree/main/asm

    Graduate
    October 9, 2024

    Adding another link I've found helpful: https://www.circuitstate.com/tutorials/wiring-up-writing-your-first-blink-program-using-assembly-language-learn-microcontroller-with-stm8s-tutorial-part-4

     

    Especially helpful is the discussion around addressing modes.

     

    I'll also mention that if you're going with assembler, asxxxx is probably a better fit than sdcc. sdcc uses an outdated version of asxxxx (possibly with some modifications), and assembler-specific documentation for sdcc is present but sparse.

    Explorer
    March 23, 2025

    Howdy, Sorry, I had a 3 year involuntary hiatus - 5/31/22 center-punched a car with one of my sport bikes (Sniff!) at 40 MPH.

    At 70, ya just don't recover the same (DUH!!), but I'm back now.

    Please see other post for my current issue.

    BTW, ANY are Very Welcome to post queries to me. Nobody knows Everything....   L8R  <<<)))