MakePTR.Exe  program documentation

MakePTR creates a pointer (.PTR) file from an AVR symbol (.SYM) file.  The purpose is to generate a list of pointers to (or addresses of) program subroutine labels and other constant address names, such as named string constants and named numeric constants.  Using MakePTR eliminates the need for a linker, since all the program's addresses are resolved to constant values.  Using it requires at least two (2) Assembly passes; the first Assembly creates or updates the .SYM file, which MakePTR then uses to create the .PTR file.  This file just created is then pulled into the source in the second and subsequent Assembly passes, thereby resolving all the addresses, and again updated on that Assembly.

The syntax for the MakePTR program is:
MAKEPTR SymbolFile WriteFile [/d[=][nn]] [/q]
SymbolFile name of the symbol (.SYM) text file to read
[WriteFile] name of the output file to write; *.Ptr if unspecified
/d[=][nn] enable debug mode; optionally, set its value to nn (1-31)
/q suppress the startup version output (quiet mode)

MakePTR reads the .SYM file specified, line by line, searching for lines which declare constant values.  It will only accept lines which have a numeric value in the "Ndx" column.  Lines with "ABS" or "UND" in that column, for example, are discarded.  It then prepends an A (for address) before the constant address name and generates a line with the constant address in the .PTR output file.  Using these addresses in the Assembly source then only requires prepending the A before the label name.

Perhaps this can best be shown with an example.  Consider this SetSameColor.Asm source code file:
SoftVector:
; .INCLUDE "SetSameColor.Ptr" ; Notice that this is initially a comment

DESTINATION = 0x200 ; The starting address in SRAM
LOOP_COUNT = 0x120 ; = 288
RED_INTENSITY = 0

.ORG 0x0D00 ; Set this subroutine's starting address

SetSameColor:
LDI R31, DESTINATION >> 8 ; Load Z with the starting SRAM address of 0x200
LDI R30, DESTINATION & 0xFF
LDI R27, LOOP_COUNT >> 8 ; Load X with the LED count
LDI R26, LOOP_COUNT & 0xFF
LDI R25, 0x80 ; Set the GREEN component intensity
LDI R24, RED_INTENSITY ; Set the RED component intensity (text constant)
LDI R23, 0 ; Set the BLUE component intensity (numeric constant)
RCALL ASetSameColorLoop ; Call the subroutine below to do the work
RET ; And we're done

SetSameColorLoop:
ST Z+, R25 ; Set one pixel's GREEN intensity in SRAM
ST Z+, R24 ; Set the RED and then the BLUE intensities for
ST Z+, R23 ; that same 3-BYTE pixel
SBIW R26, 1 ; Decrement the R27:R26 pair
BRNE ASetSameColorLoop ; Loop back unless R27:R26 just became zero
RET ; Exit when the register pair reaches zero
The subroutine, which is also the start of the loop, is called its name with a prepended 'A'. This means "the address of", a pointer.

Running the command "Asm SetSameColor" from the command line with the .INCLUDE statement commented out, as shown above, generates six (6) files.  The SetSameColor.PTR file will contain these two (2) lines:
ASetSameColor = 0x00d00
ASetSameColorLoop = 0x00d12

The SetSameColor.Dmp listing file, also generated by this first Assembly, will contain this:
00000000 <SoftVector>:
...

00000d00 <SetSameColor>:
d00: f2 e0 ldi r31, 0x02 ; 2
d02: e0 e0 ldi r30, 0x00 ; 0
d04: b1 e0 ldi r27, 0x01 ; 1
d06: a0 e2 ldi r26, 0x20 ; 32
d08: 90 e8 ldi r25, 0x80 ; 128
d0a: 80 e0 ldi r24, 0x00 ; 0
d0c: 70 e0 ldi r23, 0x00 ; 0
d0e: 00 d0 rcall .+0 ; 0xd10 <SetSameColor+0x10>
d10: 08 95 ret

00000d12 <SetSameColorLoop>:
d12: 91 93 st Z+, r25
d14: 81 93 st Z+, r24
d16: 71 93 st Z+, r23
d18: 11 97 sbiw r26, 0x01 ; 1
d1a: 01 f4 brne .+0 ; 0xd1c <SetSameColorLoop+0xa>
d1c: 08 95 ret

Notice the two lines with ".+0" above indicating that the RCALL and BRNE addresses have not yet been resolved.  Simply running Asm SetSameColor another time will not resolve this issue.  To do that, uncomment (i.e., remove the leading ";" from) the .INCLUDE statement and run that very same command again.

After the second Assembly, the SetSameColor.DMP file contains these lines, with the two (2) changed lines highlighted in bold:
00000000 <SoftVector>:
...

00000d00 <SetSameColor>:
d00: f2 e0 ldi r31, 0x02 ; 2
d02: e0 e0 ldi r30, 0x00 ; 0
d04: b1 e0 ldi r27, 0x01 ; 1
d06: a0 e2 ldi r26, 0x20 ; 32
d08: 90 e8 ldi r25, 0x80 ; 128
d0a: 80 e0 ldi r24, 0x00 ; 0
d0c: 70 e0 ldi r23, 0x00 ; 0
d0e: 01 d0 rcall .+2 ; 0xd12 <SetSameColorLoop>
d10: 08 95 ret

00000d12 <SetSameColorLoop>:
d12: 91 93 st Z+, r25
d14: 81 93 st Z+, r24
d16: 71 93 st Z+, r23
d18: 11 97 sbiw r26, 0x01 ; 1
d1a: d9 f7 brne .-10 ; 0xd12 <SetSameColorLoop>
d1c: 08 95 ret
Notice that the RCALL and BRNE address have been correctly resolved to SetSameColorLoop.

If the .INCLUDE statement is active on the first attempt, and the Assembler cannot find the SetSameColor.Ptr file, it will generate an error message and exit without creating any files.  A way around this issue is to create a very temporary SetSameColor.Ptr file which contains no statement that generates Assembly output.  One very simple way to do that is to create a file with a single space in it.  The Assembler finds the file, includes it, but since it does nothing but satisfy the .INCLUDE statement, its content is benign.  That file is then overwritten by MakePTR each time that Asm.Bat is used again.

Here's how to create that SetSameColor.Ptr file with a single BYTE in it:
C:>Copy Con SetSameColor.Ptr
^Z
1 file(s) copied.
The ^Z after the single space above is Control-Z, which is also usually the F6 keypress at a command prompt.  The line can contain a single space, multiple spaces, be a comment, or even have multiple lines.  Comments begin with a semicolon (';') character.

MakePTR has a built-in syntax help sequence which can be invoked from the command line.  It is output when a ? or /? are found anywhere on the command line, even when other valid parameters are present.  For example:
C:>MakePTR InputFile.Sym ?

The values of the five (5) bitmapped Debug constants:
    1    Show file location on startup
    2    Show the "colon column" when it is found
    4    Display each input line as it is read in
    8    Display each line output to the destination file
   16   Display the record count and line count as the program exits

To create a File.Sym input file, for example, this command is suggested:
AVR-ReadELF -s -W File.ELF > File.Sym

Finally, note that the example subroutine presented above also generated two (2) valid hex image files: SetSameColor.Hex and SetSameColor.Trm.  These files contain the information in a format that can be loaded into a MIRTOS-based device to change a portion of its program image.  For more information about these files, refer to the TrimIHex program documentation page.

Downloads page