ASM fast fertig
This commit is contained in:
14
Hades/Not.hds
Normal file
14
Hades/Not.hds
Normal file
@@ -0,0 +1,14 @@
|
||||
# hades.models.Design file
|
||||
#
|
||||
[name] unnamed
|
||||
[components]
|
||||
hades.models.io.LED i3 25800 9600 @N 1001 0
|
||||
hades.models.gates.Nand2 i2 21300 8400 @N 1001 1.0E-8
|
||||
hades.models.io.Ipin i1 20400 9600 @N 1001 U
|
||||
hades.models.io.Opin i0 25800 9600 @N 1001 5.0E-9
|
||||
[end components]
|
||||
[signals]
|
||||
hades.signals.SignalStdLogic1164 n1 3 i1 Y i2 A i2 B 3 2 20400 9600 21300 9600 2 21300 9000 21300 9600 2 21300 10200 21300 9600 1 21300 9600
|
||||
hades.signals.SignalStdLogic1164 n0 2 i2 Y i3 A 1 2 25800 9600 24900 9600 0
|
||||
[end signals]
|
||||
[end]
|
||||
31
Hades/hades_models_gates_Nand2.vhd
Normal file
31
Hades/hades_models_gates_Nand2.vhd
Normal file
@@ -0,0 +1,31 @@
|
||||
-- VHDL for hades.models.gates.Nand2: /unnamed/i2
|
||||
--
|
||||
|
||||
library IEEE;
|
||||
use IEEE.std_logic_1164.all;
|
||||
|
||||
|
||||
entity hades_models_gates_Nand2 is
|
||||
port (
|
||||
Y : out std_logic;
|
||||
A : in std_logic;
|
||||
B : in std_logic
|
||||
);
|
||||
end hades_models_gates_Nand2;
|
||||
|
||||
|
||||
-- default architecture for: hades.models.gates.Nand2: /unnamed/i2
|
||||
--
|
||||
architecture SIMPLE of hades_models_gates_Nand2 is
|
||||
begin
|
||||
Y <= not (A and B);
|
||||
end SIMPLE;
|
||||
|
||||
|
||||
|
||||
configuration cfg_hades_models_gates_Nand2 of hades_models_gates_Nand2 is
|
||||
for SIMPLE
|
||||
end for;
|
||||
end cfg_hades_models_gates_Nand2;
|
||||
|
||||
|
||||
34
Hades/not.v
Normal file
34
Hades/not.v
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 16-bit Not gate: for i = 0..15: out[i] = Not in[i]
|
||||
*
|
||||
* Adapted from "The Elements of Computer Systems"
|
||||
* by Nisan and Schocken, MIT Press.
|
||||
*
|
||||
* Adapted by Jeremiah Biard
|
||||
* 7/19/2013
|
||||
*
|
||||
*/
|
||||
|
||||
module not16(
|
||||
output [15:0] out,
|
||||
input [15:0] in);
|
||||
|
||||
not
|
||||
n0(out[0], in[0]),
|
||||
n1(out[1], in[1]),
|
||||
n2(out[2], in[2]),
|
||||
n3(out[3], in[3]),
|
||||
n4(out[4], in[4]),
|
||||
n5(out[5], in[5]),
|
||||
n6(out[6], in[6]),
|
||||
n7(out[7], in[7]),
|
||||
n8(out[8], in[8]),
|
||||
n9(out[9], in[9]),
|
||||
n10(out[10], in[10]),
|
||||
n11(out[11], in[11]),
|
||||
n12(out[12], in[12]),
|
||||
n13(out[13], in[13]),
|
||||
n14(out[14], in[14]),
|
||||
n15(out[15], in[15]);
|
||||
|
||||
endmodule
|
||||
126
asm/asm02.py
126
asm/asm02.py
@@ -93,27 +93,135 @@ def searchSymbols(asm):
|
||||
i = 16
|
||||
for line in asm:
|
||||
if line.startswith('@'):
|
||||
#ic (i, " ",line[1:])
|
||||
if line[1:].isdigit():
|
||||
if line not in symboltable:
|
||||
addtoSymboltable(line, int(line[1:]))
|
||||
elif line not in symboltable:
|
||||
#ic("Symbol nicht in Table")
|
||||
addtoSymboltable(line, i)
|
||||
i = i+1
|
||||
|
||||
def ciinstruction(ci):
|
||||
c = "1110000000000000"
|
||||
|
||||
c = "111"
|
||||
if ci.__contains__('='):
|
||||
c2 = ci.split('=')
|
||||
comp = c2[1]
|
||||
dest = c2[0]
|
||||
c = c + c_comp(comp) + c_dest(dest) +"000"
|
||||
elif ci.__contains__(";"):
|
||||
jmp = ci.split(';')
|
||||
comp = jmp[0]
|
||||
jmpinst = jmp[1]
|
||||
c = c + c_comp(comp) + "000" + c_jump(jmpinst)
|
||||
|
||||
ic(c2)
|
||||
|
||||
#ic("Dest = ", ci[0], " Comp = ", ci[2])
|
||||
return c +"\n"
|
||||
|
||||
def c_jump(jmp):
|
||||
match jmp:
|
||||
case "JGT":
|
||||
return "001"
|
||||
case "JEQ":
|
||||
return "010"
|
||||
case "JGE":
|
||||
return "011"
|
||||
case "JLT":
|
||||
return "100"
|
||||
case "JNE":
|
||||
return "101"
|
||||
case "JLE":
|
||||
return "110"
|
||||
case "JMP":
|
||||
return "111"
|
||||
case _:
|
||||
return "000"
|
||||
|
||||
|
||||
return c +"\n"
|
||||
|
||||
|
||||
def c_comp(comp):
|
||||
match comp:
|
||||
# A = 0
|
||||
case "D":
|
||||
return "0001100"
|
||||
case "0":
|
||||
return "0001100"
|
||||
case "1":
|
||||
return "0111111"
|
||||
case "-1":
|
||||
return "0111010"
|
||||
case "A":
|
||||
return "0110000"
|
||||
case "!D":
|
||||
return "0001101"
|
||||
case "!A":
|
||||
return "0110001"
|
||||
case "-D":
|
||||
return "0001111"
|
||||
case "-A":
|
||||
return "0110011"
|
||||
case "D+1":
|
||||
return "0011111"
|
||||
case "A+1":
|
||||
return "0110111"
|
||||
case "D-1":
|
||||
return "0001110"
|
||||
case "A-1":
|
||||
return "0110010"
|
||||
case "D+A":
|
||||
return "0000010"
|
||||
case "D-A":
|
||||
return "0010011"
|
||||
case "A-D":
|
||||
return "0000111"
|
||||
case "D&A":
|
||||
return "0000000"
|
||||
case "D|A":
|
||||
return "0010101"
|
||||
# a = 1
|
||||
case "M":
|
||||
return "1110000"
|
||||
case "!M":
|
||||
return "1110001"
|
||||
case "-M":
|
||||
return "1110011"
|
||||
case "M+1":
|
||||
return "1110111"
|
||||
case "M-1":
|
||||
return "1110010"
|
||||
case "D+M":
|
||||
return "1000010"
|
||||
case "D-M":
|
||||
return "1010011"
|
||||
case "M-D":
|
||||
return "1000111"
|
||||
case "D&M":
|
||||
return "1000000"
|
||||
case "D|M":
|
||||
return "1010101"
|
||||
case _:
|
||||
return ""
|
||||
|
||||
def c_dest(dest):
|
||||
match dest:
|
||||
case "M":
|
||||
return "001"
|
||||
case "D":
|
||||
return "010"
|
||||
case "MD":
|
||||
return "011"
|
||||
case "A":
|
||||
return "100"
|
||||
case "AM":
|
||||
return "101"
|
||||
case "AD":
|
||||
return "110"
|
||||
case "AMD":
|
||||
return "111"
|
||||
case _:
|
||||
return "000"
|
||||
|
||||
|
||||
|
||||
#return '{0:016b}'.format(c)+"\n"
|
||||
#return bin(c)[2:]+"\n" # 111 in binär --> falscher Weg
|
||||
# dest = comp; jump
|
||||
@@ -121,19 +229,16 @@ def ciinstruction(ci):
|
||||
|
||||
|
||||
def addtoSymboltable(key,value):
|
||||
ic(key, value)
|
||||
symboltable[key]=value
|
||||
|
||||
|
||||
def createAsmFile():
|
||||
datename = os.path.splitext(os.path.basename(filename))[0]+".hack"
|
||||
ic(datename)
|
||||
f = open(datename,"w")
|
||||
for line in asm:
|
||||
if line in symboltable:
|
||||
f.write('{0:016b}'.format(symboltable[line]) + "\n")
|
||||
else:
|
||||
#M=D
|
||||
f.write(ciinstruction(line))
|
||||
f.close()
|
||||
|
||||
@@ -147,7 +252,6 @@ if __name__ == "__main__":
|
||||
searchSymbols(asm)
|
||||
createAsmFile()
|
||||
|
||||
#print("Symtable = ",symboltable)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user