Author Topic: Need for Speed - C++ versus Assembly Language  (Read 3213 times)

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: Need for Speed - C++ versus Assembly Language
« Reply #75 on: May 30, 2017, 05:08:03 AM »
While I agree with you Felipe, unfortunately, everyone is using C to program their microprocessors these days.  Very disheartening.

I noticed the same, especially since the internet of things modules such as arduino and stuff. Most of them use the c++ compiler that comes with it. The young people don't even know what an assembler is. Here in europe there are still many people programming microcontrollers in assembly. There are great forums in Germany.

One thing is for sure, assembly has a very big advantage in speed and size over C/C++ for the very small rams of the tiny microcontrollers.

jimg

  • Member
  • **
  • Posts: 196
Re: Need for Speed - C++ versus Assembly Language
« Reply #76 on: May 30, 2017, 06:30:47 AM »
For the esp8266 I've been working with, everything is in C, I haven't seen an assembler for it.  So I'm using ZBasic which converts basic to C for the esp.

jj2007

  • Member
  • *****
  • Posts: 7758
  • Assembler is fun ;-)
    • MasmBasic
Re: Need for Speed - C++ versus Assembly Language
« Reply #77 on: May 30, 2017, 06:31:13 AM »
Don't be so negative: assembler is on the rise again: https://www.tiobe.com/tiobe-index/

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: Need for Speed - C++ versus Assembly Language
« Reply #78 on: May 30, 2017, 09:33:35 AM »
With an Atmega microcontroller programmed in assembly you can send and receive the AT commands from and to the esp8266 module.
This is not hard at all, because the ATmega has a UART on board.

Here is an example in assembly how to use the UART of an ATmel ATtiny2313 microcontroller:

Code: [Select]
.include <tn2313def.inc>    ; ATtiny2313 definitie bestand

.equ F_CPU = 11059200       ; Hz "cpu kloksnelheid definitie voor Wacht-macro"

; Instellingen RS232 communicatie
.equ BaudRate        = 115200
.equ RxBufferLengte  = 64       ; Inhoud van de ringbuffer in bytes


.org 0x0000    ; Code laad adres 0x0000
    rjmp Init  ; Maak een Relatieve sprong naar Init
.org URXCaddr
    rjmp Receive_Byte ; Ontvangst interrupt

.DSEG
                                   
RS232_Buffer:                 .byte RxBufferLengte
RS232_BufferSchrijfPositie:   .byte 1
RS232_BufferLeesPositie:      .byte 1
RS232_BufferLeesPositieNieuw: .byte 1

.CSEG


Init:
    ldi     r16,low(RAMEND) ; Initialisatie STACK
    out     SPL,r16

    cli

    rcall   RS232_Init      ; RS232 protocol initialisieren

    sei

Start:
;   rcall   PrintRS232data
;   ldi     r16,0x4F            ; zend "O"
;   sts     RS232_Karakter,r16
;   rcall   Send_Byte
;   ldi     r16,0x4B            ; zend "K"
;   sts     RS232_Karakter,r16
;   rcall   Send_Byte
    rjmp    Start

RS232_Init:
    eor     r16,r16
    sts     RS232_BufferSchrijfPositie,r16
    sts     RS232_BufferLeesPositie,r16
    sts     RS232_BufferLeesPositieNieuw,r16
    sts     RS232_NieuweRegel,r16

    ldi     r16,(0<<U2X) ; geen dubbele snelheid
    out     UCSRA,r16
    ; Stel baud rate in:
    ldi     r16,High(F_CPU/(16*BaudRate)-1)
    out     UBRRH,r16
    ldi     r16,Low(F_CPU/(16*BaudRate)-1)
    out     UBRRL,r16
    ; Stel ontvanger (RXEN), zender (TXEN) en ontvang_interrupt (RXCIE) in.
    ldi     r16,(1<<RXCIE)|(1<<RXEN)|(1<<TXEN)
    out     UCSRB,r16
    ; Stel transfer formaat in: 8 data (UCSZn1 = 1 & UCSZ0 =1), 1 stop bit (USBS = 0, == 1 stopbit)
    ldi     r16,(1<<UCSZ1)|(1<<UCSZ0)|(0<<USBS) ; 8N1
    out     UCSRC,r16
    ret


Receive_Byte:
    push    r16     
    in      r16,SREG
    push    r16

    ldi     YH,high(RS232_Buffer)
    ldi     YL,low(RS232_Buffer)
    lds     r16,RS232_BufferSchrijfPositie
    add     YL,r16                  ; zet positie in RS232_Buffer
    mov     r17,r16
    inc     r17
    andi    r17,RxBufferLengte-1    ; blijf in de "Ringbuffer"
    sts     RS232_BufferSchrijfPositie,r17  ;

    in      r16,UDR                 ; ontvangen karakter

    sts     RS232_Karakter,r16      ; opslaan voor echo
    st      Y,r16                   ; sla karakter op in RS232_Buffer
    cpi     r16,0                   ; testen op einde commando
    brne    geen_nieuwe_regel
    sts     RS232_BufferLeesPositieNieuw,r17    ; nieuwe positie voor volgende regel
    ldi     r16,1
    sts     RS232_NieuweRegel,r16   ; meld nieuwe regel aan ( we zitten in een Interrupt )

geen_nieuwe_regel:
    pop     r16
    out     SREG,r16
    pop     r16
    reti


Send_Byte:
    sbis    UCSRA,UDRE              ; wachten tot zendbuffer leeg is.
    rjmp    Send_Byte

    lds     r16,RS232_Karakter
    out     UDR,r16
    ret

« Last Edit: May 30, 2017, 10:34:46 AM by Siekmanski »

K_F

  • Member
  • *****
  • Posts: 1295
  • Anybody out there?
Re: Need for Speed - C++ versus Assembly Language
« Reply #79 on: May 30, 2017, 10:15:32 AM »
Don't be so negative: assembler is on the rise again: https://www.tiobe.com/tiobe-index/
It's just about awareness....
Once the younger generation discover assembler ... :eusa_boohoo:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'