ASM Code - Memory Allocation Advice

Hi

My apologies if this is in the wrong section couldn't find anywhere relevant.

I used to do some coding on the old Z80 processor and in these difficult times of enforced house arrest I'm REALLY BORED!!

So I'm dabbling with Assembly again but this time on a genuine UNO Rev3 (ATMega328P) and I'm struggling with understanding the info in the data-sheet concerning memory allocations for program and memory locations and looking for a bit of advice.

Short Question - what is the first location of Program memory that I can safely use for 50-70 lines of Assembly?

By way of a longer explanation - I am struggling with the concept that the Reset Vector is located at 0000h and the first location of programmable space is also 0000h. I think I need to protect this location as I would like to retain native Bootloader functionality. It is my understanding that the Reset Vector points to the Bootloader code in higher memory and returns after checking for Serial (USB) Comms at boot up.

Therefore, I was going to use the .ORG command in Atmel Studio to offset my code further up in program space - I think I saw 0100h was a suitable start location or was that for the nano and 0200h was the UNO anyway.....

I appreciate I do not fully understand the nuts and bolts of this mechanism hence my question.

Some background - I have an old air rifle that belonged to my late father and I would like to find out if it is legal in the UK by measuring the muzzle velocity. Shops are all closed due to the world hysteria so trying to get an accurate chronometer measured value is a problem - (and I'm bored!!)

I have constructed two twin foil 'plates' which will send a low signals to the UNO when the pellet get fired between them and I want to start and stop the 16bit Timer 1 to 'guestimate' the speed over a given distance. (4ft is the maximum calculated distance before the Timer overflows.) Using Assembly should deliver the minimum amount of latency (please advise if direct port manipulation via the IDE and the compiler would be as fast).

Thanks in advance

I used to do some coding on the old Z80 processor

Me Too !! the only way to get some speed out of a zx81 !
For the purpose you describe i think this reply#2 is your easiest option.

You could easily achieve what you want using the timer hardware, without recourse to assembler.

I always use the following flash memory map (Fig-1) while programming the stand-alone ATmega328P using Assembly in the Atmel Studio 7.0 Platform.
CodeMemoOrg.png
Figure-1:

The ATmega328P chip released from the factory has the boot location at 0x0000 where I execute the rjmp LX instruction to arrive at a suitable location (usually at 0x0010) of the application area.

CodeMemoOrg.png

Thank you all for you replies, very helpful :slight_smile: