This snippet of python is called:
asm2include.py filein fileout
import sys, os
def asm2include(infile, outfile):
line = ""
with open(infile, 'r') as IN:
for line in IN:
line = line.strip(' ')
if (line != ""):
line = line.replace(' ',' ')
OUT = open(outfile, "a")
if (line.startswith("//") == False):
OUT.write("asm(\"")
OUT.write(line[:-1])
OUT.write("\");\n")
else:
OUT.write(line)
OUT.write("\n")
OUT.close()
print '.',
""" --------------------------------------------------------------
MAIN APPLICATION
"""
print "ASM2include 0.1"
asm2include(sys.argv[1], sys.argv[2])
print "Done"
produces this : (not all pasted)
asm("");
asm("#define r_temp1 r16 ");
asm("#define r_temp2 r17");
asm("#define r_command r18");
asm("#define r_addr_lo r19");
asm("#define r_addr_hi r20");
asm("");
asm("#define CMD_POLL 1");
asm("#define CMD_B 2");
asm("#define CMD_W 3");
asm("");
asm("#define ACK 6");
asm("#define NAK 15");
asm("");
asm("WDT_vect:");
asm("push r16");
asm("in r16,SREG");
asm("push r16");
asm("push r17");
asm("push r18");
asm("push r19");
asm("push r20");
asm("push r28");
asm("push r29");
asm("push r30");
asm("push r31");
asm("");
// kick the watch dog
asm("wdr");
asm("");
asm("SHIFTIN r_command");
asm("");
asm("cpi r_command,CMD_POLL");
asm("brne not_poll");
asm("ldi r_temp1, ACK");
asm("rjmp transmit_answer_byte");
asm("");
I know this is not what you want, but what should be improved?
- update
- recognize the // commentlines in code above