print("Some assembler") import sys args=sys.argv if(len(args)<2): print(len(args)) args.append(input("input filename:")) file=open(args[1]) filedat=file.read() file.close() fdat_upper="""library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity biosram is port ( clka : IN STD_LOGIC; ena : IN STD_LOGIC; wea : IN STD_LOGIC; addra : IN STD_LOGIC_VECTOR(13 DOWNTO 0); dina : IN STD_LOGIC_VECTOR(7 DOWNTO 0); douta : OUT STD_LOGIC_VECTOR(7 DOWNTO 0) ); end biosram; architecture Behavioral of biosram is --Declaration of type and signal of a 512 element RAM --with each element being 8 bit wide. type ram_t is array (0 to """ fdat_mid=""") of std_logic_vector(7 downto 0); signal ram : ram_t := (""" fdat_lower="""); signal data_o : std_logic_vector(7 downto 0); signal adr : std_logic_vector(5 downto 0); begin --process for read and write operation. process(CLKa) begin if(rising_edge(CLKa))then if(wea='1' and ena='1')then ram(to_integer(unsigned(addra))) <= dina; end if; end if; end process; douta <= ram(to_integer(unsigned(addra))) when wea='0' and ena='1'; end Behavioral;""" split=False com=False tmp="" tokens=[] for i in filedat: if i==';': com=True elif(com): if i=='\n' or i=='\r': com=False elif i=='"': split=not split if(tmp!=""): tokens.append(tmp) tmp="" if split: tokens.append('"') elif (i.isspace() or i==',' or i=='\t')and tmp!="'" and not split: if(tmp!=""): tokens.append(tmp) tmp="" else: tmp+=i tokens.append(tmp) names={} location=0 i=0 regs=["ax","bx","cx","dx","si","di","sp",'pc'] def to_int(s): base=10 if(str(s)[:2]=="0x"): base=16 #exec("y="+s) try: return int(str(s),base) except: if(s[0]=="'" and s[2]=="'"): return ord(s[1]) def is_int(s): base=10 s=str(s) if(str(s)[:2]=="0x"): base=16 try: if(len(s)>=3 and s[0]=="'" and s[2]=="'"): return True int(s,base) return True except ValueError: return False while i>8)&255) out.append((names[x]>>16)&255) out.append((names[x]>>24)&255) elif is_int(x): out.append(to_int(x)&255) out.append((to_int(x)>>8)&255) out.append((to_int(x)>>16)&255) out.append((to_int(x)>>24)&255) elif x=='$': out.append(to_int(location)&255) out.append((to_int(location)>>8)&255) out.append((to_int(location)>>16)&255) out.append((to_int(location)>>24)&255) else: print("Error: '"+x+"' is not a valid number, identifier, or symbol.") i=0 while i