flat assembler
Message board for the users of flat assembler.

flat assembler > Non-x86 architectures > Fasm megaAVR ATmega microcontroller output

Author
Thread Post new topic Reply to topic
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Hi guys,

Is megaAVR microcontroller family output support scheduled for Fasm?
ATmega
AVR XMEGA
tinyAVR (no joke! these tiny black stuff are complete computers with cpu, flash program memory, sram, and eeprom)

Or Fasm only likes architectures with at least 32 bits ?
Post 17 Sep 2014, 21:04
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15870
Location: 162173 Ryugu
fasm only assembles x86 class architectures. That includes 16, 32 and 64 bits.

There are derivatives of fasm that support things from Z80 to ARM. Someone might have made a version for the Atmel CPUs but I haven't seen it. Perhaps you could make a version.
Post 18 Sep 2014, 00:06
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4160
Location: 2018
macro can do that. but the avr is like the pic, you cannot access/read/write the program memory...

now i am a c++ programmer (for food) and what i can see is...
macro, even if it slows down fasm by a 1000% factor, is faster than any hll compiler. then, don't hesitate, if you have a little time, to write a macro for any cpu/mcu you meet.

if you want, i made it for pic some years ago, and it was very easy to do. just the time to translate the datasheet (here it was a 39 instructions set) in an equates listing (one or two nights, don't remember) Smile
Post 18 Sep 2014, 08:59
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
edfed wrote:
macro can do that. but the avr is like the pic, you cannot access/read/write the program memory...

now i am a c++ programmer (for food) and what i can see is...
macro, even if it slows down fasm by a 1000% factor, is faster than any hll compiler. then, don't hesitate, if you have a little time, to write a macro for any cpu/mcu you meet.

if you want, i made it for pic some years ago, and it was very easy to do. just the time to translate the datasheet (here it was a 39 instructions set) in an equates listing (one or two nights, don't remember) Smile


Hi dude Smile

sorry, AVR is not PIC
it can write its own memory, you can put a bootloader in it...
Post 18 Sep 2014, 09:30
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6872
Location: Kraków, Poland
Last year, when I was programming some ATmega microcontroller, I did actually consider creating a macro package for fasm that would allow assembling for AVR architecture. The instruction set is very simple, so it would not be a big deal, probably even easier than the JVM macros.
Post 18 Sep 2014, 15:46
View user's profile Send private message Visit poster's website Reply with quote
den_po



Joined: 17 Jul 2006
Posts: 23
Location: Russia, Cheboksary
Post 28 Sep 2015, 09:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6872
Location: Kraków, Poland
I forgot about this old thread, but it should be noted that now there is a set of macros for AVR architecture included in the fasm g package and you can get it on the official download page.
Post 28 Sep 2015, 11:23
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1603
Location: Ukraine
Porting my project from avrasm2 to fasmg I have noticed some things to improve AVR support:

It would be good to be able to include original Atmel definitions, to do this fasmg must skip lines started with "#" and treat ".def" similar to ".equ". To do this macro "?" should be changed (thanks to Tomasz for the help):
Code:
macro ? line& match .=ORG? addr, line if ~ DSEG? org (addr) shl 1 else org addr end if ;++++++++++++++++++++++++++++++++++++++++ else match #any, line else match .=DEVICE? name, line else match .=DEF? name == value, line name? = value ;++++++++++++++++++++++++++++++++++++++++ else match .=EQU? name == value, line name? = value else match .=DSEG?, line if ~ DSEG? virtual at DSEG?.$ DSEG? = 1 end if else match .=CSEG?, line if DSEG? DSEG?.$ = $ end virtual DSEG? = 0 end if else line end match end macro


Also I have noticed the labels with colon in .DSEG are improperly shited (while labels without colons are ok)
To correct this the struc ? should be modified:
Code:
struc ? definition& match :: anything, definition+ . definition else match : command, definition if ~ DSEG? label . at $ shr 1 else label . at $ end if command else match :, definition if ~ DSEG? label . at $ shr 1 else label . at $ end if else . definition end match end struc


but you must not use labels without colon in .CSEG, they will be shifted!
It is because of 8-bit addressing of the SRAM/EEPROM and 16-bit addressing of the FLASH (code segment). i.e.:
Code:
.dseg label1: db 1 ; correct label2 db 2 ; correct .cseg label3: db 3,3 ; correct label4 db 4,4 ; incorrect!!!

Also, .ESEG is missing a while, I think, it should be added similar to .DSEG

Not all commands or their variants are available on different MCU models. It is easy to make a mistake with this, especially while source reuse of different MCU project. To check if commands are matching current device I would suggest to make separate include for each MCU model, where include general avr.inc and then block unsupported commands and rewrite partially supported commands to exclude unsupported variants. It is not easy and fast work, but neccesary if you would like to be sure in your result Cool
This one I made for Attiny2313A:
Code:
include "avr.inc" include "tn2313def.inc" macro show description,value repeat 1, d:value display description,`d,13,10 end repeat end macro iterate instr,MUL,MULS,MULSU,FMUL,FMULS,FMULSU,EIJMP,JMP,EICALL,CALL,ELPM macro instr? params err 'Command is not supported by this device' end macro end iterate iterate instr,XCH,LAS,LAC,LAT macro instr? params err 'Command is not supported by this device' end macro end iterate macro LDS? Rd,k local value,d value = +Rd if value metadata 1 relativeto R & value scale 2 = 0 & value scale 0 = 0 d = value metadata 1 - R value = +k if value >= 0 & value <= 65535 dw d shl 4 + 1001000b shl 9 dw value else err 'address out of range' end if else err 'invalid operand' end if end macro macro STS? k,Rr local value,r value = +Rr if value metadata 1 relativeto R & value scale 2 = 0 & value scale 0 = 0 r = value metadata 1 - R value = +k if value >= 0 & value <= 65535 dw r shl 4 + 1001001b shl 9 dw value else err 'address out of range' end if else err 'invalid operand' end if end macro


Finally, avrasm checks if commands are word aligned. This can be easy violated with unpair "db" definittions in code segment.

Of course, everything might be incomplete and still must be hardly tested! Wink
Post 25 Nov 2015, 08:00
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 2004-2018, Tomasz Grysztar.

Powered by rwasa.