flat assembler
Message board for the users of flat assembler.
Index
> Non-x86 architectures > Fasm megaAVR ATmega microcontroller output |
Author |
|
Matrix 17 Sep 2014, 21:04
|
|||
17 Sep 2014, 21:04 |
|
edfed 18 Sep 2014, 08:59
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) |
|||
18 Sep 2014, 08:59 |
|
Matrix 18 Sep 2014, 09:30
edfed wrote: macro can do that. but the avr is like the pic, you cannot access/read/write the program memory... Hi dude sorry, AVR is not PIC it can write its own memory, you can put a bootloader in it... |
|||
18 Sep 2014, 09:30 |
|
Tomasz Grysztar 18 Sep 2014, 15:46
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.
|
|||
18 Sep 2014, 15:46 |
|
den_po 28 Sep 2015, 09:06
my old AVR macro library http://board.flatassembler.net/topic.php?t=5546
|
|||
28 Sep 2015, 09:06 |
|
Tomasz Grysztar 28 Sep 2015, 11:23
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.
|
|||
28 Sep 2015, 11:23 |
|
shoorick 25 Nov 2015, 08:00
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 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! |
|||
25 Nov 2015, 08:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.