Browse Source

added inf2270 and inf2810 stuff

master
mortie 7 years ago
parent
commit
246dcb3745

+ 432
- 77
inf2270/hw2/cpu.circ View File

@@ -3,21 +3,26 @@
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0">
<tool name="Splitter">
<a name="facing" val="north"/>
<a name="facing" val="south"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</tool>
</lib>
<lib desc="#Gates" name="1">
<tool name="NOT Gate">
<a name="facing" val="north"/>
</tool>
<tool name="Buffer">
<a name="facing" val="south"/>
<a name="width" val="8"/>
</tool>
<tool name="AND Gate">
<a name="facing" val="north"/>
<a name="facing" val="south"/>
<a name="size" val="30"/>
<a name="inputs" val="2"/>
</tool>
<tool name="OR Gate">
<a name="facing" val="north"/>
<a name="width" val="2"/>
<a name="size" val="30"/>
<a name="inputs" val="2"/>
@@ -33,6 +38,7 @@ This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<a name="width" val="4"/>
</tool>
<tool name="Decoder">
<a name="facing" val="north"/>
<a name="select" val="2"/>
</tool>
<tool name="BitSelector">
@@ -52,8 +58,8 @@ This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
</tool>
</lib>
<lib desc="#I/O" name="5">
<tool name="Button">
<a name="facing" val="north"/>
<tool name="LED">
<a name="facing" val="south"/>
</tool>
</lib>
<lib desc="#Base" name="6">
@@ -86,10 +92,11 @@ This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
</tool>
<sep/>
<tool lib="0" name="Pin">
<a name="facing" val="south"/>
<a name="tristate" val="false"/>
</tool>
<tool lib="0" name="Pin">
<a name="facing" val="west"/>
<a name="facing" val="south"/>
<a name="output" val="true"/>
<a name="labelloc" val="east"/>
</tool>
@@ -102,109 +109,457 @@ This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<wire from="(190,180)" to="(190,190)"/>
<wire from="(150,180)" to="(150,190)"/>
<wire from="(190,230)" to="(190,240)"/>
<wire from="(200,180)" to="(200,190)"/>
<wire from="(240,190)" to="(240,200)"/>
<wire from="(200,220)" to="(200,230)"/>
<wire from="(440,220)" to="(440,230)"/>
<wire from="(510,190)" to="(510,200)"/>
<wire from="(460,190)" to="(460,200)"/>
<wire from="(460,220)" to="(460,230)"/>
<wire from="(500,190)" to="(500,210)"/>
<wire from="(470,190)" to="(470,210)"/>
<wire from="(480,190)" to="(480,210)"/>
<wire from="(120,130)" to="(120,150)"/>
<wire from="(450,190)" to="(450,220)"/>
<wire from="(490,190)" to="(490,220)"/>
<wire from="(490,230)" to="(490,260)"/>
<wire from="(270,170)" to="(270,200)"/>
<wire from="(220,160)" to="(220,190)"/>
<wire from="(220,130)" to="(220,160)"/>
<wire from="(120,130)" to="(220,130)"/>
<wire from="(490,220)" to="(530,220)"/>
<wire from="(150,220)" to="(180,220)"/>
<wire from="(240,200)" to="(270,200)"/>
<wire from="(450,260)" to="(480,260)"/>
<wire from="(500,210)" to="(530,210)"/>
<wire from="(420,170)" to="(440,170)"/>
<wire from="(510,200)" to="(530,200)"/>
<wire from="(220,190)" to="(240,190)"/>
<wire from="(440,220)" to="(450,220)"/>
<wire from="(210,190)" to="(210,240)"/>
<wire from="(520,190)" to="(530,190)"/>
<wire from="(270,170)" to="(280,170)"/>
<wire from="(170,160)" to="(180,160)"/>
<wire from="(190,230)" to="(200,230)"/>
<wire from="(210,160)" to="(220,160)"/>
<wire from="(200,190)" to="(210,190)"/>
<wire from="(120,150)" to="(130,150)"/>
<comp lib="2" loc="(490,260)" name="Decoder">
<a name="selloc" val="tr"/>
<a name="select" val="2"/>
<wire from="(660,260)" to="(660,270)"/>
<wire from="(450,400)" to="(450,470)"/>
<wire from="(580,180)" to="(580,190)"/>
<wire from="(210,170)" to="(210,180)"/>
<wire from="(250,170)" to="(250,180)"/>
<wire from="(500,300)" to="(550,300)"/>
<wire from="(300,180)" to="(300,190)"/>
<wire from="(560,210)" to="(600,210)"/>
<wire from="(580,190)" to="(620,190)"/>
<wire from="(640,480)" to="(640,510)"/>
<wire from="(280,120)" to="(280,150)"/>
<wire from="(560,160)" to="(560,180)"/>
<wire from="(700,260)" to="(700,280)"/>
<wire from="(570,250)" to="(570,290)"/>
<wire from="(680,480)" to="(680,520)"/>
<wire from="(550,460)" to="(570,460)"/>
<wire from="(450,470)" to="(480,470)"/>
<wire from="(440,390)" to="(440,500)"/>
<wire from="(270,180)" to="(270,290)"/>
<wire from="(260,180)" to="(270,180)"/>
<wire from="(270,150)" to="(280,150)"/>
<wire from="(180,140)" to="(190,140)"/>
<wire from="(230,150)" to="(240,150)"/>
<wire from="(440,500)" to="(520,500)"/>
<wire from="(720,440)" to="(720,490)"/>
<wire from="(460,490)" to="(720,490)"/>
<wire from="(560,440)" to="(570,440)"/>
<wire from="(430,380)" to="(430,510)"/>
<wire from="(250,260)" to="(250,270)"/>
<wire from="(250,220)" to="(250,230)"/>
<wire from="(230,290)" to="(270,290)"/>
<wire from="(560,210)" to="(560,230)"/>
<wire from="(550,440)" to="(550,460)"/>
<wire from="(550,160)" to="(550,180)"/>
<wire from="(570,180)" to="(570,200)"/>
<wire from="(600,210)" to="(600,230)"/>
<wire from="(580,190)" to="(580,230)"/>
<wire from="(620,190)" to="(620,230)"/>
<wire from="(600,250)" to="(600,290)"/>
<wire from="(430,510)" to="(640,510)"/>
<wire from="(490,290)" to="(490,400)"/>
<wire from="(480,160)" to="(500,160)"/>
<wire from="(650,310)" to="(740,310)"/>
<wire from="(640,300)" to="(730,300)"/>
<wire from="(230,270)" to="(250,270)"/>
<wire from="(530,460)" to="(530,520)"/>
<wire from="(250,220)" to="(260,220)"/>
<wire from="(460,410)" to="(540,410)"/>
<wire from="(710,440)" to="(720,440)"/>
<wire from="(600,250)" to="(610,250)"/>
<wire from="(740,180)" to="(740,310)"/>
<wire from="(480,460)" to="(480,470)"/>
<wire from="(550,220)" to="(590,220)"/>
<wire from="(570,200)" to="(610,200)"/>
<wire from="(550,300)" to="(590,300)"/>
<wire from="(560,180)" to="(560,210)"/>
<wire from="(180,120)" to="(180,140)"/>
<wire from="(730,220)" to="(730,300)"/>
<wire from="(580,160)" to="(580,180)"/>
<wire from="(180,120)" to="(280,120)"/>
<wire from="(440,390)" to="(480,390)"/>
<wire from="(430,380)" to="(470,380)"/>
<wire from="(450,400)" to="(490,400)"/>
<wire from="(520,460)" to="(520,500)"/>
<wire from="(420,290)" to="(420,520)"/>
<wire from="(210,210)" to="(240,210)"/>
<wire from="(480,290)" to="(480,390)"/>
<wire from="(570,140)" to="(590,140)"/>
<wire from="(550,380)" to="(640,380)"/>
<wire from="(560,390)" to="(650,390)"/>
<wire from="(270,290)" to="(420,290)"/>
<wire from="(610,280)" to="(700,280)"/>
<wire from="(500,440)" to="(510,440)"/>
<wire from="(460,440)" to="(470,440)"/>
<wire from="(720,220)" to="(730,220)"/>
<wire from="(540,440)" to="(550,440)"/>
<wire from="(550,220)" to="(550,230)"/>
<wire from="(570,320)" to="(570,330)"/>
<wire from="(590,220)" to="(590,230)"/>
<wire from="(610,320)" to="(610,330)"/>
<wire from="(610,280)" to="(610,290)"/>
<wire from="(500,290)" to="(500,300)"/>
<wire from="(260,170)" to="(260,180)"/>
<wire from="(260,210)" to="(260,220)"/>
<wire from="(560,270)" to="(660,270)"/>
<wire from="(420,520)" to="(530,520)"/>
<wire from="(570,200)" to="(570,230)"/>
<wire from="(610,200)" to="(610,230)"/>
<wire from="(640,300)" to="(640,380)"/>
<wire from="(650,310)" to="(650,390)"/>
<wire from="(460,410)" to="(460,440)"/>
<wire from="(280,150)" to="(280,180)"/>
<wire from="(330,160)" to="(330,190)"/>
<wire from="(560,270)" to="(560,290)"/>
<wire from="(570,160)" to="(570,180)"/>
<wire from="(470,290)" to="(470,380)"/>
<wire from="(590,140)" to="(590,180)"/>
<wire from="(550,180)" to="(550,220)"/>
<wire from="(540,370)" to="(540,410)"/>
<wire from="(530,520)" to="(680,520)"/>
<wire from="(590,180)" to="(740,180)"/>
<wire from="(300,190)" to="(330,190)"/>
<wire from="(280,180)" to="(300,180)"/>
<wire from="(250,270)" to="(460,270)"/>
<wire from="(460,450)" to="(460,490)"/>
<wire from="(460,450)" to="(470,450)"/>
<wire from="(490,200)" to="(500,200)"/>
<wire from="(330,160)" to="(340,160)"/>
<wire from="(550,380)" to="(550,440)"/>
<wire from="(560,390)" to="(560,440)"/>
<wire from="(490,200)" to="(490,260)"/>
<comp lib="0" loc="(570,140)" name="Splitter">
<a name="facing" val="south"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="4" loc="(480,160)" name="ROM">
<a name="addrWidth" val="4"/>
<a name="contents">addr/data: 4 8
85 97 b1 81 94 a1
</a>
</comp>
<comp lib="0" loc="(490,230)" name="Splitter">
<comp lib="1" loc="(250,230)" name="NOT Gate">
<a name="facing" val="north"/>
</comp>
<comp lib="4" loc="(970,810)" name="RAM">
<a name="addrWidth" val="4"/>
<comp lib="0" loc="(700,260)" name="Splitter">
<a name="facing" val="north"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="4" loc="(270,150)" name="Register">
<a name="width" val="4"/>
</comp>
<comp loc="(570,320)" name="mux-4">
<a name="facing" val="south"/>
</comp>
<comp lib="5" loc="(210,240)" name="Button">
<comp lib="0" loc="(500,160)" name="Splitter">
<a name="facing" val="south"/>
<a name="fanout" val="8"/>
<a name="incoming" val="8"/>
</comp>
<comp lib="0" loc="(570,250)" name="Splitter">
<a name="facing" val="north"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="1" loc="(460,220)" name="NOT Gate">
<comp lib="0" loc="(610,330)" name="Splitter">
<a name="facing" val="south"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="0" loc="(130,170)" name="Constant">
<comp lib="0" loc="(540,370)" name="Splitter">
<a name="facing" val="north"/>
<a name="fanout" val="8"/>
<a name="incoming" val="8"/>
<a name="appear" val="right"/>
</comp>
<comp lib="0" loc="(610,250)" name="Splitter">
<a name="facing" val="north"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="1" loc="(210,210)" name="NOT Gate">
<a name="facing" val="south"/>
</comp>
<comp lib="0" loc="(190,160)" name="Constant">
<a name="width" val="4"/>
</comp>
<comp lib="6" loc="(157,116)" name="Text">
<a name="text" val="Instruction counter"/>
<comp lib="0" loc="(720,220)" name="Splitter">
<a name="facing" val="south"/>
<a name="fanout" val="8"/>
<a name="incoming" val="8"/>
<a name="appear" val="right"/>
</comp>
<comp lib="5" loc="(300,180)" name="Hex Digit Display"/>
<comp lib="5" loc="(230,290)" name="Button">
<a name="label" val="Reset"/>
<a name="labelloc" val="west"/>
</comp>
<comp lib="4" loc="(540,440)" name="Register">
<a name="trigger" val="falling"/>
</comp>
<comp lib="6" loc="(190,279)" name="Text">
<a name="text" val="+"/>
<comp lib="6" loc="(411,111)" name="Text">
<a name="text" val="Program ROM"/>
</comp>
<comp lib="5" loc="(190,240)" name="Button">
<comp loc="(500,440)" name="mux-8"/>
<comp lib="0" loc="(660,260)" name="Splitter">
<a name="facing" val="north"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="1" loc="(190,190)" name="AND Gate">
<comp lib="0" loc="(500,200)" name="Splitter">
<a name="facing" val="north"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="right"/>
</comp>
<comp loc="(610,320)" name="mux-4">
<a name="facing" val="south"/>
</comp>
<comp lib="3" loc="(230,150)" name="Adder">
<a name="width" val="4"/>
</comp>
<comp lib="4" loc="(710,440)" name="RAM">
<a name="addrWidth" val="4"/>
<a name="bus" val="separate"/>
</comp>
<comp lib="5" loc="(230,270)" name="Button">
<a name="label" val="Clock"/>
<a name="labelloc" val="west"/>
</comp>
<comp loc="(480,260)" name="decode"/>
<comp lib="1" loc="(250,180)" name="AND Gate">
<a name="facing" val="north"/>
<a name="size" val="30"/>
<a name="inputs" val="2"/>
</comp>
<comp lib="4" loc="(210,160)" name="Register">
<comp lib="0" loc="(570,330)" name="Splitter">
<a name="facing" val="south"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="6" loc="(231,108)" name="Text">
<a name="text" val="Program counter"/>
</comp>
</circuit>
<circuit name="mux-4">
<a name="circuit" val="mux-4"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<appear>
<rect fill="none" height="30" stroke="#000000" stroke-width="2" width="30" x="50" y="50"/>
<text font-family="SansSerif" font-size="12" text-anchor="middle" x="65" y="72">4</text>
<circ-port height="8" pin="220,230" width="8" x="46" y="56"/>
<circ-port height="8" pin="220,270" width="8" x="46" y="66"/>
<circ-port height="10" pin="370,250" width="10" x="75" y="55"/>
<circ-port height="8" pin="250,340" width="8" x="56" y="76"/>
<circ-anchor facing="east" height="6" width="6" x="77" y="57"/>
</appear>
<wire from="(260,230)" to="(260,250)"/>
<wire from="(260,250)" to="(260,270)"/>
<wire from="(250,310)" to="(280,310)"/>
<wire from="(260,250)" to="(370,250)"/>
<wire from="(250,200)" to="(250,220)"/>
<wire from="(280,200)" to="(280,310)"/>
<wire from="(250,280)" to="(250,310)"/>
<wire from="(250,310)" to="(250,340)"/>
<wire from="(220,230)" to="(240,230)"/>
<wire from="(220,270)" to="(240,270)"/>
<comp lib="1" loc="(260,230)" name="Controlled Buffer">
<a name="width" val="4"/>
<a name="control" val="left"/>
</comp>
<comp lib="6" loc="(372,115)" name="Text">
<a name="text" val="Program ROM"/>
<comp lib="1" loc="(250,200)" name="NOT Gate">
<a name="facing" val="west"/>
</comp>
<comp lib="0" loc="(220,270)" name="Pin">
<a name="width" val="4"/>
<a name="tristate" val="false"/>
<a name="label" val="Input 1"/>
</comp>
<comp lib="3" loc="(170,160)" name="Adder">
<comp lib="1" loc="(260,270)" name="Controlled Buffer">
<a name="width" val="4"/>
</comp>
<comp lib="5" loc="(240,190)" name="Hex Digit Display"/>
<comp lib="1" loc="(150,220)" name="NOT Gate">
<comp lib="0" loc="(250,340)" name="Pin">
<a name="facing" val="north"/>
<a name="tristate" val="false"/>
<a name="label" val="Control"/>
</comp>
<comp lib="0" loc="(370,250)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="width" val="4"/>
<a name="label" val="Output"/>
<a name="labelloc" val="east"/>
</comp>
<comp lib="0" loc="(220,230)" name="Pin">
<a name="width" val="4"/>
<a name="tristate" val="false"/>
<a name="label" val="Input 0"/>
</comp>
</circuit>
<circuit name="mux-8">
<a name="circuit" val="mux-8"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<appear>
<rect fill="none" height="30" stroke="#000000" stroke-width="2" width="30" x="50" y="50"/>
<text font-family="SansSerif" font-size="12" text-anchor="middle" x="65" y="70">8</text>
<circ-port height="8" pin="220,230" width="8" x="46" y="56"/>
<circ-port height="8" pin="220,270" width="8" x="46" y="66"/>
<circ-port height="10" pin="370,250" width="10" x="75" y="55"/>
<circ-port height="8" pin="250,340" width="8" x="56" y="76"/>
<circ-anchor facing="east" height="6" width="6" x="77" y="57"/>
</appear>
<wire from="(260,230)" to="(260,250)"/>
<wire from="(260,250)" to="(260,270)"/>
<wire from="(250,310)" to="(280,310)"/>
<wire from="(260,250)" to="(370,250)"/>
<wire from="(250,200)" to="(250,220)"/>
<wire from="(280,200)" to="(280,310)"/>
<wire from="(250,310)" to="(250,340)"/>
<wire from="(250,280)" to="(250,310)"/>
<wire from="(220,230)" to="(240,230)"/>
<wire from="(220,270)" to="(240,270)"/>
<comp lib="1" loc="(260,230)" name="Controlled Buffer">
<a name="width" val="8"/>
<a name="control" val="left"/>
</comp>
<comp lib="1" loc="(260,270)" name="Controlled Buffer">
<a name="width" val="8"/>
</comp>
<comp lib="0" loc="(370,250)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="width" val="8"/>
<a name="label" val="Output"/>
<a name="labelloc" val="east"/>
</comp>
<comp lib="1" loc="(250,200)" name="NOT Gate">
<a name="facing" val="west"/>
</comp>
<comp lib="0" loc="(220,270)" name="Pin">
<a name="width" val="8"/>
<a name="tristate" val="false"/>
<a name="label" val="Input 1"/>
</comp>
<comp lib="0" loc="(220,230)" name="Pin">
<a name="width" val="8"/>
<a name="tristate" val="false"/>
<a name="label" val="Input 0"/>
</comp>
<comp lib="0" loc="(250,340)" name="Pin">
<a name="facing" val="north"/>
<a name="tristate" val="false"/>
<a name="label" val="Control"/>
</comp>
</circuit>
<circuit name="decode">
<a name="circuit" val="decode"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<appear>
<rect fill="none" height="30" stroke="#000000" stroke-width="2" width="45" x="50" y="50"/>
<text font-family="SansSerif" font-size="12" text-anchor="middle" x="73" y="69">decode</text>
<circ-port height="8" pin="230,160" width="8" x="76" y="46"/>
<circ-port height="10" pin="330,390" width="10" x="55" y="75"/>
<circ-port height="10" pin="330,350" width="10" x="65" y="75"/>
<circ-port height="10" pin="330,310" width="10" x="75" y="75"/>
<circ-port height="10" pin="330,270" width="10" x="85" y="75"/>
<circ-port height="8" pin="190,200" width="8" x="46" y="56"/>
<circ-anchor facing="east" height="6" width="6" x="67" y="47"/>
</appear>
<wire from="(220,210)" to="(220,220)"/>
<wire from="(250,260)" to="(250,270)"/>
<wire from="(280,390)" to="(330,390)"/>
<wire from="(270,320)" to="(270,340)"/>
<wire from="(230,230)" to="(230,250)"/>
<wire from="(200,200)" to="(200,220)"/>
<wire from="(250,270)" to="(250,360)"/>
<wire from="(250,360)" to="(290,360)"/>
<wire from="(280,300)" to="(280,390)"/>
<wire from="(260,260)" to="(260,350)"/>
<wire from="(260,350)" to="(290,350)"/>
<wire from="(270,320)" to="(290,320)"/>
<wire from="(270,340)" to="(290,340)"/>
<wire from="(240,200)" to="(240,240)"/>
<wire from="(210,180)" to="(210,220)"/>
<wire from="(280,260)" to="(280,300)"/>
<wire from="(210,250)" to="(230,250)"/>
<wire from="(230,230)" to="(250,230)"/>
<wire from="(280,300)" to="(290,300)"/>
<wire from="(320,310)" to="(330,310)"/>
<wire from="(320,350)" to="(330,350)"/>
<wire from="(250,270)" to="(330,270)"/>
<wire from="(190,200)" to="(200,200)"/>
<wire from="(240,240)" to="(250,240)"/>
<wire from="(270,260)" to="(270,320)"/>
<comp lib="0" loc="(330,270)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="low=MSB, high=LSB"/>
<a name="labelloc" val="east"/>
</comp>
<comp lib="0" loc="(190,200)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="Enable"/>
</comp>
<comp lib="0" loc="(230,160)" name="Splitter">
<a name="facing" val="south"/>
<a name="fanout" val="4"/>
<a name="incoming" val="4"/>
<a name="appear" val="center"/>
</comp>
<comp lib="2" loc="(250,240)" name="Decoder">
<a name="facing" val="south"/>
<a name="select" val="2"/>
<a name="disabled" val="0"/>
</comp>
<comp lib="4" loc="(1250,680)" name="Register"/>
<comp lib="6" loc="(209,280)" name="Text">
<a name="text" val="0"/>
<comp lib="0" loc="(330,390)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="write RAM"/>
<a name="labelloc" val="east"/>
</comp>
<comp lib="1" loc="(450,260)" name="AND Gate">
<comp lib="1" loc="(210,250)" name="AND Gate">
<a name="facing" val="south"/>
<a name="size" val="30"/>
<a name="inputs" val="3"/>
</comp>
<comp lib="1" loc="(320,310)" name="OR Gate">
<a name="size" val="30"/>
<a name="inputs" val="2"/>
</comp>
<comp lib="0" loc="(440,170)" name="Splitter">
<comp lib="1" loc="(220,210)" name="NOT Gate">
<a name="facing" val="south"/>
<a name="fanout" val="8"/>
<a name="incoming" val="8"/>
</comp>
<comp lib="4" loc="(420,170)" name="ROM">
<a name="addrWidth" val="4"/>
<a name="contents">addr/data: 4 8
80 90 a0 b0
</a>
<comp lib="0" loc="(330,350)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="write R"/>
<a name="labelloc" val="east"/>
</comp>
<comp lib="0" loc="(230,160)" name="Pin">
<a name="facing" val="south"/>
<a name="width" val="4"/>
<a name="tristate" val="false"/>
</comp>
<comp lib="0" loc="(240,200)" name="Splitter">
<a name="facing" val="north"/>
<a name="appear" val="center"/>
</comp>
<comp lib="1" loc="(320,350)" name="OR Gate">
<a name="size" val="30"/>
<a name="inputs" val="3"/>
</comp>
<comp lib="0" loc="(330,310)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="low=input, high=ram"/>
<a name="labelloc" val="east"/>
</comp>
</circuit>
</project>

+ 3
- 0
inf2270/hw2/rapport.mdn View File

@@ -0,0 +1,3 @@
# Rapport - Martin Dørum (martindn)



+ 3
- 0
inf2270/hw2/test1.raw View File

@@ -0,0 +1,3 @@
v2.0 raw
85 97 B1 81 94 A1 00 00
00 00 00 00 00 00 00 00

+ 3
- 0
inf2270/hw2/test2.raw View File

@@ -0,0 +1,3 @@
v2.0 raw
8C 9D B0 B3 81 91 A0 B4
00 00 00 00 00 00 00 00

+ 142
- 2
inf2810/hw2.a/oppgave.scm View File

@@ -1,3 +1,8 @@
;; Jeg har med huffman.scm i leveringen, men ingenting der er endret.

;; Beklager blandingen av norsk og engelsk. Svar på oppgaver er skrevet
;; på norsk, kodekommentarer er skrevet på engelsk.

(load "huffman.scm")

;;;;;;;
@@ -58,7 +63,7 @@
;; D

;; Resultatet blir en "not a procedure"-feil. Dette er fordi at når vi bruker
;; quote er / et symbol, ikke en prosedyre. `(/) er dermed en liste som
;; quote er / et symbol, ikke en prosedyre. '(/) er dermed en liste som
;; inneholder symbolet /, mens (list /) blir en liste som inneholder prosedyren
;; med navn /.

@@ -82,8 +87,143 @@

;; C

;; TODO
(define (decode bits tree)
(define (decode-1 bits current-branch acc)
(if (null? bits)
(reverse acc)
(let ((next-branch
(choose-branch (car bits) current-branch)))
(cond ((leaf? next-branch)
(decode-1 (cdr bits) tree (cons (symbol-leaf next-branch) acc)))
(else (decode-1 (cdr bits) next-branch acc))))))
(decode-1 bits tree '()))

;; D

(decode sample-code sample-tree)
;; -> (ninjas fight ninjas by night)

;; E

;; This procedure isn't inside the encode function, as it's
;; useful later
(define (encode-symbol sym tree)
(cond ((leaf? tree) '())
((member? eq? sym (symbols (left-branch tree)))
(cons 0 (encode-symbol sym (left-branch tree))))
(else
(cons 1 (encode-symbol sym (right-branch tree))))))

(define (encode syms tree)
(if (null? syms)
'()
(append (encode-symbol (car syms) tree)
(encode (cdr syms) tree))))

;; F

(define (grow-huffman-tree freqs)
(define (get-biggest freqs)
(define (get-biggest-1 freqs biggest)
(cond ((null? freqs) biggest)
((> (cadr(car freqs)) (cadr biggest))
(get-biggest-1 (cdr freqs) (car freqs)))
(else (get-biggest-1 (cdr freqs) biggest))))
(get-biggest-1 freqs (car freqs)))

;; Returns a new list with the element removed.
;; The list is reversed because we don't care about the order.
(define (remove-from-list items elem)
(define (remove-1 items elem acc)
(cond ((null? items) acc)
((eq? elem (car items)) (remove-1 (cdr items) elem acc))
(else (remove-1 (cdr items) elem (cons (car items) acc)))))
(remove-1 items elem '()))

;; Inner function because I don't want to define get-biggest
;; and remove-from-list for every single iteration.
;; Maybe scheme optimizes that away, but it felt weird.
(define (grow-tree-1 freqs)
(if (null? (cdr freqs))
(make-leaf (caar freqs) (cadar freqs))
(let ((biggest (get-biggest freqs)))
(make-code-tree (make-leaf (car biggest) (cadr biggest))
(grow-tree-1 (remove-from-list freqs biggest))))))
(grow-tree-1 freqs))

;; G

(define g-freqs
'((samurais 57) (ninjas 20) (fight 45) (night 12) (hide 3) (in 2)
(ambush 2) (defeat 1) (the 5) (sword 4) (by 12) (assassin 1)
(river 2) (forest 1) (wait 1) (poison 1)))

(define g-tree (grow-huffman-tree g-freqs))

(define g-msg '(ninjas fight
ninjas fight ninjas
ninjas fight samurais
samurais fight
samurais fight ninjas
ninjas fight by night))

(encode g-msg g-tree)
;; -> (1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 0 1 0 0 0 1
;; 0 0 1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 1 1 1 0)

;; - 42 bits.
;; - Den gjennomsnittlige lengden av hvert ord er rundt 2.47 bits (42 / 17).
;; - Den minste mengden bits vi kan få med en fixed-length code er 51.
;; Dette er fordi vi har forskjellige 5 symboler, og den minste antall bits
;; som har minst 5 forskjellige verdier er 3. Meldingen er 17 symboler lang,
;; og 17 * 3 = 51.

;; H

(define (huffman-leaves tree)
(define (sym s)
(list (list (symbol-leaf s) (weight-leaf s))))

(if (leaf? tree)
(sym tree)
(append (huffman-leaves (left-branch tree))
(huffman-leaves (right-branch tree)))))

(huffman-leaves sample-tree)
;; -> ((ninjas 8) (fight 5) (night 1) (by 1))

;; I

;; This is kind of big and ugly. I found out that you apparently can't
;; first define a procedure, then define a variable whose definition
;; uses that procedure. As a result, I have to define code-length-1 within
;; a let, even though it seems kind of unnecessary.
(define (expected-code-length tree)
(define syms (huffman-leaves tree))

;; Function to count the total frequencies
(define (total-freqs-1 syms acc)
(cond ((null? syms) acc)
(else (total-freqs-1 (cdr syms) (+ acc (cadar syms))))))

(let ((total-freqs (total-freqs-1 syms 0)))

;; Get the number of bits for a symbol
(define (c sym)
(length (encode-symbol (car sym) tree)))

;; Get the relative frequency of a symbol
(define (p sym)
(/ (cadr sym)
total-freqs))

(define (code-length-1 syms)
(if (null? syms)
0
(+ (* (p (car syms))
(c (car syms)))
(code-length-1 (cdr syms)))))
(code-length-1 syms)))

(expected-code-length sample-tree)
;; -> 8/5

+ 1
- 0
inf2810/hw2.b/oppgave.scm View File

@@ -0,0 +1 @@
(load "prekode2b.scm")

+ 40
- 0
inf2810/hw2.b/prekode2b.scm View File

@@ -0,0 +1,40 @@
;;;; Diverse hjelpekode for innlevering 3a i INF2810, 2017.
;;;; erikve [at] ifi.uio.no


;; Tabell-abstraksjon fra seksjon 3.3.3 i SICP:

(define (make-table)
(list '*table*))

(define (lookup key table)
(let ((record (assoc key (cdr table))))
(and record (cdr record))))

(define (insert! key value table)
(let ((record (assoc key (cdr table))))
(if record
(set-cdr! record value)
(set-cdr! table
(cons (cons key value) (cdr table))))))


;; mem-testprosedyre 1; fibonacci-tallene
(define (fib n)
(display "computing fib of ")
(display n) (newline)
(cond ((= n 0) 0)
((= n 1) 1)
(else (+ (fib (- n 1))
(fib (- n 2))))))


;; mem-testprosedyre 2; tar virkårlig mange argumenter (null eller flere).
;; (Returnerer summen av argumentenes kvadrerte forskjell fra 42.)
(define (test-proc . args)
(display "computing test-proc of ")
(display args) (newline)
(if (null? args)
0
(+ (expt (- 42 (car args)) 2)
(apply test-proc (cdr args)))))

Loading…
Cancel
Save