initial commit

This commit is contained in:
Christoffer Müller Madsen 2016-01-03 13:29:05 +01:00
commit e2e36f9f0d
54 changed files with 1949 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.DS_Store

Binary file not shown.

Binary file not shown.

BIN
Afl3-dComArk-Overloeb.pdf Normal file

Binary file not shown.

Binary file not shown.

BIN
Afl5-dComArk-x86-64.pdf Normal file

Binary file not shown.

View File

@ -0,0 +1,281 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project source="2.7.1" version="1.0">
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0"/>
<lib desc="#Gates" name="1">
<tool name="AND Gate">
<a name="inputs" val="4"/>
</tool>
<tool name="OR Gate">
<a name="inputs" val="8"/>
</tool>
</lib>
<lib desc="#Plexers" name="2"/>
<lib desc="#Arithmetic" name="3"/>
<lib desc="#Memory" name="4">
<tool name="ROM">
<a name="contents">addr/data: 8 8
0
</a>
</tool>
</lib>
<lib desc="#I/O" name="5"/>
<lib desc="#Base" name="6">
<tool name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
</lib>
<main name="main"/>
<options>
<a name="gateUndefined" val="ignore"/>
<a name="simlimit" val="1000"/>
<a name="simrand" val="0"/>
</options>
<mappings>
<tool lib="6" map="Button2" name="Menu Tool"/>
<tool lib="6" map="Button3" name="Menu Tool"/>
<tool lib="6" map="Ctrl Button1" name="Menu Tool"/>
</mappings>
<toolbar>
<tool lib="6" name="Poke Tool"/>
<tool lib="6" name="Edit Tool"/>
<tool lib="6" name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
<sep/>
<tool lib="0" name="Pin">
<a name="tristate" val="false"/>
</tool>
<tool lib="0" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="labelloc" val="east"/>
</tool>
<tool lib="1" name="NOT Gate"/>
<tool lib="1" name="AND Gate"/>
<tool lib="1" name="OR Gate"/>
</toolbar>
<circuit name="main">
<a name="circuit" val="main"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<wire from="(350,490)" to="(350,570)"/>
<wire from="(290,40)" to="(290,110)"/>
<wire from="(310,120)" to="(310,250)"/>
<wire from="(260,430)" to="(260,460)"/>
<wire from="(150,490)" to="(350,490)"/>
<wire from="(330,480)" to="(380,480)"/>
<wire from="(110,220)" to="(110,250)"/>
<wire from="(150,140)" to="(290,140)"/>
<wire from="(200,450)" to="(200,530)"/>
<wire from="(110,340)" to="(110,370)"/>
<wire from="(290,110)" to="(290,140)"/>
<wire from="(220,260)" to="(390,260)"/>
<wire from="(380,460)" to="(390,460)"/>
<wire from="(330,20)" to="(330,70)"/>
<wire from="(500,60)" to="(500,290)"/>
<wire from="(310,250)" to="(310,330)"/>
<wire from="(290,240)" to="(380,240)"/>
<wire from="(110,460)" to="(110,490)"/>
<wire from="(290,40)" to="(390,40)"/>
<wire from="(490,300)" to="(500,300)"/>
<wire from="(380,130)" to="(380,140)"/>
<wire from="(260,80)" to="(260,290)"/>
<wire from="(330,350)" to="(330,370)"/>
<wire from="(220,540)" to="(390,540)"/>
<wire from="(200,530)" to="(200,580)"/>
<wire from="(240,560)" to="(390,560)"/>
<wire from="(110,460)" to="(260,460)"/>
<wire from="(310,400)" to="(310,580)"/>
<wire from="(220,20)" to="(220,190)"/>
<wire from="(260,290)" to="(390,290)"/>
<wire from="(350,220)" to="(350,360)"/>
<wire from="(470,350)" to="(470,410)"/>
<wire from="(220,260)" to="(220,470)"/>
<wire from="(110,110)" to="(200,110)"/>
<wire from="(440,200)" to="(480,200)"/>
<wire from="(150,250)" to="(310,250)"/>
<wire from="(480,310)" to="(500,310)"/>
<wire from="(350,360)" to="(390,360)"/>
<wire from="(330,210)" to="(390,210)"/>
<wire from="(260,500)" to="(390,500)"/>
<wire from="(220,470)" to="(220,540)"/>
<wire from="(110,140)" to="(120,140)"/>
<wire from="(350,150)" to="(350,220)"/>
<wire from="(330,70)" to="(390,70)"/>
<wire from="(490,370)" to="(490,550)"/>
<wire from="(380,250)" to="(390,250)"/>
<wire from="(260,290)" to="(260,430)"/>
<wire from="(200,20)" to="(200,110)"/>
<wire from="(290,180)" to="(290,240)"/>
<wire from="(100,110)" to="(110,110)"/>
<wire from="(100,220)" to="(110,220)"/>
<wire from="(290,240)" to="(290,580)"/>
<wire from="(480,200)" to="(480,310)"/>
<wire from="(350,150)" to="(390,150)"/>
<wire from="(440,270)" to="(470,270)"/>
<wire from="(330,210)" to="(330,350)"/>
<wire from="(220,190)" to="(220,220)"/>
<wire from="(240,560)" to="(240,580)"/>
<wire from="(290,180)" to="(390,180)"/>
<wire from="(350,20)" to="(350,150)"/>
<wire from="(440,550)" to="(490,550)"/>
<wire from="(100,340)" to="(110,340)"/>
<wire from="(470,350)" to="(500,350)"/>
<wire from="(110,370)" to="(120,370)"/>
<wire from="(200,390)" to="(390,390)"/>
<wire from="(380,240)" to="(380,250)"/>
<wire from="(470,320)" to="(500,320)"/>
<wire from="(220,470)" to="(390,470)"/>
<wire from="(110,250)" to="(120,250)"/>
<wire from="(310,330)" to="(310,400)"/>
<wire from="(290,140)" to="(290,180)"/>
<wire from="(490,130)" to="(490,300)"/>
<wire from="(110,220)" to="(220,220)"/>
<wire from="(310,50)" to="(310,120)"/>
<wire from="(260,430)" to="(390,430)"/>
<wire from="(220,540)" to="(220,580)"/>
<wire from="(550,330)" to="(580,330)"/>
<wire from="(240,130)" to="(240,280)"/>
<wire from="(440,130)" to="(490,130)"/>
<wire from="(310,400)" to="(390,400)"/>
<wire from="(260,460)" to="(260,500)"/>
<wire from="(260,500)" to="(260,580)"/>
<wire from="(350,570)" to="(390,570)"/>
<wire from="(200,530)" to="(390,530)"/>
<wire from="(100,460)" to="(110,460)"/>
<wire from="(310,120)" to="(390,120)"/>
<wire from="(330,370)" to="(330,480)"/>
<wire from="(330,480)" to="(330,580)"/>
<wire from="(440,340)" to="(500,340)"/>
<wire from="(440,60)" to="(500,60)"/>
<wire from="(240,340)" to="(240,420)"/>
<wire from="(380,490)" to="(390,490)"/>
<wire from="(240,130)" to="(380,130)"/>
<wire from="(290,20)" to="(290,40)"/>
<wire from="(200,450)" to="(380,450)"/>
<wire from="(260,20)" to="(260,80)"/>
<wire from="(240,280)" to="(390,280)"/>
<wire from="(440,410)" to="(470,410)"/>
<wire from="(350,570)" to="(350,580)"/>
<wire from="(330,70)" to="(330,210)"/>
<wire from="(470,270)" to="(470,320)"/>
<wire from="(310,20)" to="(310,50)"/>
<wire from="(240,420)" to="(390,420)"/>
<wire from="(480,360)" to="(500,360)"/>
<wire from="(240,20)" to="(240,130)"/>
<wire from="(200,110)" to="(200,320)"/>
<wire from="(200,320)" to="(390,320)"/>
<wire from="(240,280)" to="(240,340)"/>
<wire from="(350,220)" to="(390,220)"/>
<wire from="(200,390)" to="(200,450)"/>
<wire from="(200,320)" to="(200,390)"/>
<wire from="(490,370)" to="(500,370)"/>
<wire from="(150,370)" to="(330,370)"/>
<wire from="(380,480)" to="(380,490)"/>
<wire from="(220,190)" to="(390,190)"/>
<wire from="(310,50)" to="(390,50)"/>
<wire from="(240,420)" to="(240,560)"/>
<wire from="(330,350)" to="(390,350)"/>
<wire from="(380,450)" to="(380,460)"/>
<wire from="(110,340)" to="(240,340)"/>
<wire from="(310,330)" to="(390,330)"/>
<wire from="(110,490)" to="(120,490)"/>
<wire from="(110,110)" to="(110,140)"/>
<wire from="(380,140)" to="(390,140)"/>
<wire from="(260,80)" to="(390,80)"/>
<wire from="(290,110)" to="(390,110)"/>
<wire from="(480,360)" to="(480,480)"/>
<wire from="(220,220)" to="(220,260)"/>
<wire from="(440,480)" to="(480,480)"/>
<wire from="(350,360)" to="(350,490)"/>
<comp lib="0" loc="(580,330)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="P"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="0" loc="(100,340)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="C"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="0" loc="(100,110)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="A"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="0" loc="(100,460)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="D"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="6" loc="(239,16)" name="Text">
<a name="text" val="C"/>
</comp>
<comp lib="1" loc="(150,370)" name="NOT Gate"/>
<comp lib="1" loc="(440,60)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="6" loc="(350,16)" name="Text">
<a name="text" val="~D"/>
</comp>
<comp lib="1" loc="(150,250)" name="NOT Gate"/>
<comp lib="6" loc="(330,16)" name="Text">
<a name="text" val="~C"/>
</comp>
<comp lib="6" loc="(291,16)" name="Text">
<a name="text" val="~A"/>
</comp>
<comp lib="6" loc="(219,16)" name="Text">
<a name="text" val="B"/>
</comp>
<comp lib="1" loc="(440,130)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="1" loc="(440,340)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="1" loc="(440,270)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="6" loc="(309,16)" name="Text">
<a name="text" val="~B"/>
</comp>
<comp lib="1" loc="(440,550)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="1" loc="(440,410)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="6" loc="(261,16)" name="Text">
<a name="text" val="D"/>
</comp>
<comp lib="6" loc="(199,16)" name="Text">
<a name="text" val="A"/>
</comp>
<comp lib="1" loc="(150,140)" name="NOT Gate"/>
<comp lib="1" loc="(440,480)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="1" loc="(440,200)" name="AND Gate">
<a name="inputs" val="4"/>
</comp>
<comp lib="1" loc="(150,490)" name="NOT Gate"/>
<comp lib="0" loc="(100,220)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="B"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="1" loc="(550,330)" name="OR Gate">
<a name="inputs" val="8"/>
</comp>
</circuit>
</project>

View File

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project source="2.7.1" version="1.0">
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0"/>
<lib desc="#Gates" name="1">
<tool name="AND Gate">
<a name="inputs" val="2"/>
</tool>
<tool name="OR Gate">
<a name="inputs" val="2"/>
</tool>
<tool name="XOR Gate">
<a name="inputs" val="2"/>
</tool>
</lib>
<lib desc="#Plexers" name="2"/>
<lib desc="#Arithmetic" name="3"/>
<lib desc="#Memory" name="4">
<tool name="ROM">
<a name="contents">addr/data: 8 8
0
</a>
</tool>
</lib>
<lib desc="#I/O" name="5"/>
<lib desc="#Base" name="6">
<tool name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
</lib>
<main name="main"/>
<options>
<a name="gateUndefined" val="ignore"/>
<a name="simlimit" val="1000"/>
<a name="simrand" val="0"/>
</options>
<mappings>
<tool lib="6" map="Button2" name="Menu Tool"/>
<tool lib="6" map="Button3" name="Menu Tool"/>
<tool lib="6" map="Ctrl Button1" name="Menu Tool"/>
</mappings>
<toolbar>
<tool lib="6" name="Poke Tool"/>
<tool lib="6" name="Edit Tool"/>
<tool lib="6" name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
<sep/>
<tool lib="0" name="Pin">
<a name="tristate" val="false"/>
</tool>
<tool lib="0" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="labelloc" val="east"/>
</tool>
<tool lib="1" name="NOT Gate"/>
<tool lib="1" name="AND Gate"/>
<tool lib="1" name="OR Gate"/>
</toolbar>
<circuit name="main">
<a name="circuit" val="main"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<wire from="(290,100)" to="(300,100)"/>
<wire from="(90,160)" to="(150,160)"/>
<wire from="(90,120)" to="(150,120)"/>
<wire from="(210,140)" to="(220,140)"/>
<wire from="(300,100)" to="(310,100)"/>
<wire from="(220,120)" to="(240,120)"/>
<wire from="(210,60)" to="(220,60)"/>
<wire from="(90,80)" to="(150,80)"/>
<wire from="(90,40)" to="(150,40)"/>
<wire from="(220,80)" to="(240,80)"/>
<wire from="(220,60)" to="(220,80)"/>
<wire from="(220,120)" to="(220,140)"/>
<comp lib="0" loc="(90,160)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="D"/>
</comp>
<comp lib="0" loc="(90,40)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="A"/>
</comp>
<comp lib="1" loc="(300,100)" name="XOR Gate">
<a name="inputs" val="2"/>
</comp>
<comp lib="1" loc="(210,140)" name="XOR Gate">
<a name="inputs" val="2"/>
</comp>
<comp lib="1" loc="(210,60)" name="XOR Gate">
<a name="inputs" val="2"/>
</comp>
<comp lib="0" loc="(90,80)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="B"/>
</comp>
<comp lib="0" loc="(310,100)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="P"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="0" loc="(90,120)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="C"/>
</comp>
</circuit>
<circuit name="main2">
<a name="circuit" val="main2"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<wire from="(120,80)" to="(120,90)"/>
<wire from="(50,30)" to="(130,30)"/>
<wire from="(130,90)" to="(150,90)"/>
<wire from="(210,70)" to="(230,70)"/>
<wire from="(130,30)" to="(130,50)"/>
<wire from="(130,50)" to="(150,50)"/>
<wire from="(120,80)" to="(150,80)"/>
<wire from="(50,90)" to="(120,90)"/>
<wire from="(130,90)" to="(130,120)"/>
<wire from="(50,60)" to="(150,60)"/>
<wire from="(50,120)" to="(130,120)"/>
<comp lib="0" loc="(50,30)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="A"/>
</comp>
<comp lib="0" loc="(50,120)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="D"/>
</comp>
<comp lib="0" loc="(50,90)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="C"/>
</comp>
<comp lib="0" loc="(50,60)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="B"/>
</comp>
<comp lib="0" loc="(230,70)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="P"/>
<a name="labelloc" val="north"/>
</comp>
<comp lib="1" loc="(210,70)" name="XOR Gate">
<a name="inputs" val="4"/>
<a name="xor" val="odd"/>
</comp>
</circuit>
</project>

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project source="2.7.1" version="1.0">
This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/).
<lib desc="#Wiring" name="0"/>
<lib desc="#Gates" name="1"/>
<lib desc="#Plexers" name="2"/>
<lib desc="#Arithmetic" name="3"/>
<lib desc="#Memory" name="4"/>
<lib desc="#I/O" name="5"/>
<lib desc="#Base" name="6">
<tool name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
</lib>
<main name="main"/>
<options>
<a name="gateUndefined" val="ignore"/>
<a name="simlimit" val="1000"/>
<a name="simrand" val="0"/>
</options>
<mappings>
<tool lib="6" map="Button2" name="Menu Tool"/>
<tool lib="6" map="Ctrl Button1" name="Menu Tool"/>
<tool lib="6" map="Button3" name="Menu Tool"/>
</mappings>
<toolbar>
<tool lib="6" name="Poke Tool"/>
<tool lib="6" name="Edit Tool"/>
<tool lib="6" name="Text Tool">
<a name="text" val=""/>
<a name="font" val="SansSerif plain 12"/>
<a name="halign" val="center"/>
<a name="valign" val="base"/>
</tool>
<sep/>
<tool lib="0" name="Pin">
<a name="tristate" val="false"/>
</tool>
<tool lib="0" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="labelloc" val="east"/>
</tool>
<tool lib="1" name="NOT Gate"/>
<tool lib="1" name="AND Gate"/>
<tool lib="1" name="OR Gate"/>
</toolbar>
<circuit name="main">
<a name="circuit" val="main"/>
<a name="clabel" val=""/>
<a name="clabelup" val="east"/>
<a name="clabelfont" val="SansSerif plain 12"/>
<wire from="(120,80)" to="(120,90)"/>
<wire from="(50,30)" to="(130,30)"/>
<wire from="(130,90)" to="(150,90)"/>
<wire from="(210,70)" to="(230,70)"/>
<wire from="(130,30)" to="(130,50)"/>
<wire from="(130,50)" to="(150,50)"/>
<wire from="(120,80)" to="(150,80)"/>
<wire from="(50,90)" to="(120,90)"/>
<wire from="(130,90)" to="(130,120)"/>
<wire from="(50,120)" to="(130,120)"/>
<wire from="(50,60)" to="(150,60)"/>
<comp lib="0" loc="(50,30)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="A"/>
</comp>
<comp lib="0" loc="(50,60)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="B"/>
</comp>
<comp lib="0" loc="(50,90)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="C"/>
</comp>
<comp lib="1" loc="(210,70)" name="XOR Gate">
<a name="inputs" val="4"/>
<a name="xor" val="odd"/>
</comp>
<comp lib="0" loc="(50,120)" name="Pin">
<a name="tristate" val="false"/>
<a name="label" val="D"/>
</comp>
<comp lib="0" loc="(230,70)" name="Pin">
<a name="facing" val="west"/>
<a name="output" val="true"/>
<a name="label" val="P"/>
<a name="labelloc" val="north"/>
</comp>
</circuit>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

13
Aflevering3-Overloeb/eq.j Normal file
View File

@ -0,0 +1,13 @@
.method main
.args 3
.define a = 1
.define b = 2
iload a
iload b
isub // Find the difference between a and b
ifeq true // If a and b are equal, return 1
false: bipush 0 // else: return 0
ireturn
true: bipush 1
ireturn

View File

@ -0,0 +1,26 @@
.method main
.args 3
.define a = 1
.define b = 2
sign: iload a // Check for negative signs
iflt aneg // If a is negative, go check if b is too
iload b
iflt true // If only b is negative, a > b
// a > b is a subset of a >= b
// return 1
comp: iload a // Compare the two values to check a >= b
iload b
isub
iflt false // If (a-b) < 0, return 0, else return 1
true: bipush 1 // Push 1 to top of stack and return
ireturn
aneg: iload b // Check if b is negative
iflt comp // If a and b are negative go compare them
// else a < b; a < b is not part of a >= b;
// return 0
false: bipush 0 // Push 0 to top of stack and return
ireturn

View File

@ -0,0 +1,24 @@
0x10 bipush byte
0x59 dup
0xA7 goto label
0x60 iadd
0x7E iand
0x99 ifeq label
0x9B iflt label
0x9F if_icmpeq label
0x84 iinc varnum, byte
0x15 iload varnum-wide
0xB6 invokevirtual method
0x80 ior
0xAC ireturn
0x36 istore varnum-wide
0x64 isub
0x13 ldc_w constant
0x00 nop
0x57 pop
0x5F swap
0xC4 wide
0x78 ishl
0x7A ishr
0x7C iushr

View File

@ -0,0 +1,303 @@
#
# Extensions to MAL:
# ------------------
#
# - absolute labels; the syntax for labels have been extended to
# allow for absolute placement of instructions, as required
# by the implementation of IJVM. To have an instruction
# placed e.g. at address 0x2A, write:
#
# imul = 0x2A:
# MAR = SP = SP - 1; rd
# ...
#
# The micro code immediately following is guaranteed to be
# placed at address 0x2A, provided it does not collide with
# other absolute labels. The label `imul' will also serve as
# a target for both conditional and unconditional gotos.
#
# - nop instruction; since the assembler ignores blank lines, a
# means to instruct the assembler to generate an empty cycle
# is needed. This is used in the implementation of pop and
# ireturn. More specifically, in the control word generated
# by nop, NEXT_ADDRESS points to the following instruction,
# the JAM field is 0, the ALU operation is unspecified, all C
# and memory bits are 0 and B is unspecified.
#
#
# Wed Apr 21 19:48:26 CEST 1999
# -----------------------------
#
# Okay, "nop" is not a clever name since it is a java bytecode.
# How about "empty"? But what about the label "goto"?
#
goto mic1_entry
main:
PC = PC + 1; fetch; goto (MBR)
nop = 0x00:
goto main
iadd = 0x60:
MAR = SP = SP - 1; rd
H = TOS
MDR = TOS = MDR + H; wr; goto main
isub = 0x64:
MAR = SP = SP - 1; rd
H = TOS
MDR = TOS = MDR - H; wr; goto main
iand = 0x7E:
MAR = SP = SP - 1; rd
H = TOS
MDR = TOS = MDR AND H; wr; goto main
ior = 0x80:
MAR = SP = SP - 1; rd
H = TOS
MDR = TOS = MDR OR H; wr; goto main
dup = 0x59:
MAR = SP = SP + 1
MDR = TOS; wr; goto main
pop = 0x57:
MAR = SP = SP - 1; rd
empty
TOS = MDR; goto main
swap = 0x5F:
MAR = SP - 1; rd
MAR = SP
H = MDR; wr
MDR = TOS
MAR = SP - 1; wr
TOS = H; goto main
bipush = 0x10:
SP = MAR = SP + 1
PC = PC + 1; fetch
MDR = TOS = MBR; wr; goto main
iload = 0x15:
H = LV
MAR = MBRU + H; rd
iload_cont:
MAR = SP = SP + 1
PC = PC + 1; fetch; wr
TOS = MDR; goto main
istore = 0x36:
H = LV
MAR = MBRU + H
istore_cont:
MDR = TOS; wr
SP = MAR = SP - 1; rd
PC = PC + 1; fetch
TOS = MDR; goto main
wide = 0xC4:
PC = PC + 1; fetch; goto (MBR OR 0x100)
wide_iload = 0x115:
PC = PC + 1; fetch
H = MBRU << 8
H = MBRU OR H
MAR = LV + H; rd; goto iload_cont
wide_istore = 0x136:
PC = PC + 1; fetch
H = MBRU << 8
H = MBRU OR H
MAR = LV + H; goto istore_cont
ldc_w = 0x13:
PC = PC + 1; fetch
H = MBRU << 8
H = MBRU OR H
MAR = H + CPP; rd; goto iload_cont
iinc = 0x84:
H = LV
MAR = MBRU + H; rd
PC = PC + 1; fetch
H = MDR
PC = PC + 1; fetch
MDR = MBR + H; wr; goto main
ijvm_goto = 0xA7:
OPC = PC - 1
goto_cont:
PC = PC + 1; fetch
H = MBR << 8
H = MBRU OR H
PC = OPC + H; fetch
goto main
iflt = 0x9B:
MAR = SP = SP - 1; rd
OPC = TOS
TOS = MDR
N = OPC; if (N) goto T; else goto F
ifeq = 0x99:
MAR = SP = SP - 1; rd
OPC = TOS
TOS = MDR
Z = OPC; if (Z) goto T; else goto F
if_icmpeq = 0x9F:
MAR = SP = SP - 1; rd
MAR = SP = SP - 1
H = MDR; rd
OPC = TOS
TOS = MDR
Z = OPC - H; if (Z) goto T; else goto F
T:
OPC = PC - 1; fetch; goto goto_cont
F:
PC = PC + 1
PC = PC + 1; fetch
goto main
invokevirtual = 0xB6:
PC = PC + 1; fetch
H = MBRU << 8
H = MBRU OR H
mic1_entry:
MAR = CPP + H; rd
OPC = PC + 1
PC = MDR; fetch
PC = PC + 1; fetch
H = MBRU << 8
H = MBRU OR H
PC = PC + 1; fetch
TOS = SP - H
TOS = MAR = TOS + 1
PC = PC + 1; fetch
H = MBRU << 8
H = MBRU OR H
MDR = SP + H + 1; wr
MAR = SP = MDR
MDR = OPC; wr
MAR = SP = SP + 1
MDR = LV; wr
PC = PC + 1; fetch
LV = TOS; goto main
ireturn = 0xAC:
MAR = SP = LV; rd
empty
LV = MAR = MDR; rd
MAR = LV + 1
PC = MDR; rd; fetch
MAR = SP
LV = MDR
MDR = TOS; wr
Z = PC - 1; if (Z) goto mic1_exit; else goto main
mic1_exit:
halt
ishl = 0x78:
# It is possible to use the value of
# the MBRU register to create the mask.
H = MBRU >> 1 # MBRU = 1111000, H = 111100
H = H >> 1 # H = 11110
H = H + 1 # H = 11111
# Read second-to-top word from stack and
# set SP to point to this position.
MAR = SP = SP - 1; rd
TOS = TOS AND H # Apply bit mask to the top word from
# the stack which signifies the number
# of shifts to perform.
H = OPC = MDR # Load the value to be shifted.
ishl_loop: # If the counter (TOS) is 0, end loop.
Z = TOS; if (Z) goto ishl_end; else goto ishl_shift
ishl_shift:
H = OPC = OPC + H # Perform an arithmetic left-shift by
# multiplying H and OPC. H and OPC is
# loaded with the result to prepare for
# possible further multiplications.
TOS = TOS - 1 # Decrease the counter by one.
goto ishl_loop
ishl_end: # Customary push of result to the TOS
# register and the stack in memory.
# MAR = SP is not necessary, due to
# MAR already being set to SP earlier.
MDR = TOS = H; wr; goto main
ishr = 0x7A:
# It is possible to use the value of
# the MBRU register to create the mask.
H = MBRU >> 1 # MBRU = 1111010, H = 111101
H = H >> 1 # H = 11110
H = H + 1 # H = 11111
# Read second-to-top word from stack and
# set SP to point to this position.
MAR = SP = SP - 1; rd
TOS = TOS AND H # Apply bit mask to the top word from
# the stack.
H = MDR # Load the value to be shifted into H.
ishr_loop: # If the counter (TOS) is 0, end loop.
Z = TOS; if (Z) goto ishr_end; else goto ishr_shift
ishr_shift: # The actual shifting takes place here
H = H >> 1 # The value is shifted arithmetically
# right by 1-bit using the ALU.
TOS = TOS - 1 # The counter is decreased.
goto ishr_loop
ishr_end: # Customary push of result to the TOS
# register and the stack in memory.
MDR = TOS = H; wr; goto main
iushr = 0x7C:
H = MBRU >> 1 # MBRU = 1111100, H = 111110
# Set H to the value of OPC to prepare
# for the creation of a new bit-mask
# later in the instruction.
OPC = H = H >> 1 # H = 11111
# Read second-to-top word from stack and
# set SP to point to this position.
MAR = SP = SP - 1; rd
TOS = TOS AND H # Apply bit mask to the top word from
# the stack.
# Create new bit mask from the previous
# bit mask.
H = OPC = OPC + 1 # H = 100000
H = OPC = H + OPC # H, OPC = 01000000
# The value of OPC after the following
# instructions is listed in the
# comments of each line:
OPC = H + OPC # 00000000 00000000 00000000 10000000
OPC = OPC << 8 # 00000000 00000000 10000000 00000000
OPC = OPC << 8 # 00000000 10000000 00000000 00000000
OPC = OPC << 8 # 10000000 00000000 00000000 00000000
OPC = inv(OPC) # 01111111 11111111 11111111 11111111
# If anything is AND with OPC, it will
# remove the most significant bit of
# that value with OPC.
H = MDR # Load H with the value to be shifted
iushr_loop:
Z = TOS; if (Z) goto iushr_end; else goto iushr_shift
iushr_shift:
H = H >> 1 # Do a 1-bit arithmetic right-shift
H = H AND OPC # Use the bit-mask to remove the most
# significant bit, effectively making
# the arithmetic right-shift into a
# logical right-shift.
TOS = TOS - 1 # Decrease the counter by one.
goto iushr_loop
iushr_end: # Customary push of result to the TOS
# register and the stack in memory.
MDR = TOS = H; wr; goto main

View File

@ -0,0 +1,513 @@
entry: 006
000: 0010000000 goto 0x002;
001: 0220350201 PC = PC + 1; goto 0x044;
002: 0004350211 PC = PC + 1; fetch; goto (MBR);
003: 03703cc008 OPC = H = H + OPC; goto 0x06e;
004: 03b0588000 H = (H) >> 1; goto 0x076;
005: 0450588000 H = (H) >> 1; goto 0x08a;
006: 0240000000 goto 0x048;
007: 0040148007 H = TOS; goto 0x008;
008: 00103c2140 MDR = TOS = H + MDR; wr; goto 0x002;
009: 0050148007 H = TOS; goto 0x00a;
00a: 00103f2140 MDR = TOS = MDR - H; wr; goto 0x002;
00b: 0060148007 H = TOS; goto 0x00c;
00c: 00100c2140 MDR = TOS = H and MDR; wr; goto 0x002;
00d: 0070148007 H = TOS; goto 0x00e;
00e: 00101c2140 MDR = TOS = H or MDR; wr; goto 0x002;
00f: 0010140147 MDR = TOS; wr; goto 0x002;
010: 00d0350484 MAR = SP = SP + 1; goto 0x01a;
011: 0090000000 goto 0x012;
012: 0010142000 TOS = MDR; goto 0x002;
013: 0158350211 PC = PC + 1; fetch; goto 0x02b;
014: 00b0140084 MAR = SP; goto 0x016;
015: 00e0148005 H = LV; goto 0x01c;
016: 00b8148040 H = MDR; wr; goto 0x017;
017: 00c0140107 MDR = TOS; goto 0x018;
018: 00c83700c4 MAR = SP - 1; wr; goto 0x019;
019: 0010182000 TOS = H; goto 0x002;
01a: 00d8350211 PC = PC + 1; fetch; goto 0x01b;
01b: 0010142142 MDR = TOS = MBR; wr; goto 0x002;
01c: 00e83c00a3 MAR = H + MBRU; rd; goto 0x01d;
01d: 00f0350484 MAR = SP = SP + 1; goto 0x01e;
01e: 00f8350251 PC = PC + 1; wr; fetch; goto 0x01f;
01f: 0010142000 TOS = MDR; goto 0x002;
020: 01083c0083 MAR = H + MBRU; goto 0x021;
021: 0110140147 MDR = TOS; wr; goto 0x022;
022: 01183704a4 MAR = SP = SP - 1; rd; goto 0x023;
023: 0120350211 PC = PC + 1; fetch; goto 0x024;
024: 0010142000 TOS = MDR; goto 0x002;
025: 0130948003 H = (MBRU) << 8; goto 0x026;
026: 01381c8003 H = H or MBRU; goto 0x027;
027: 00e83c00a5 MAR = H + LV; rd; goto 0x01d;
028: 0148948003 H = (MBRU) << 8; goto 0x029;
029: 01501c8003 H = H or MBRU; goto 0x02a;
02a: 01083c0085 MAR = H + LV; goto 0x021;
02b: 0160948003 H = (MBRU) << 8; goto 0x02c;
02c: 01681c8003 H = H or MBRU; goto 0x02d;
02d: 00e83c00a6 MAR = H + CPP; rd; goto 0x01d;
02e: 01783c00a3 MAR = H + MBRU; rd; goto 0x02f;
02f: 0180350211 PC = PC + 1; fetch; goto 0x030;
030: 0188148000 H = MDR; goto 0x031;
031: 0190350211 PC = PC + 1; fetch; goto 0x032;
032: 00103c0142 MDR = H + MBR; wr; goto 0x002;
033: 01a0350211 PC = PC + 1; fetch; goto 0x034;
034: 01a8948002 H = (MBR) << 8; goto 0x035;
035: 01b81c8003 H = H or MBRU; goto 0x037;
036: 0100148005 H = LV; goto 0x020;
037: 01c03c0218 PC = H + OPC; fetch; goto 0x038;
038: 0010000000 goto 0x002;
039: 01d0144007 OPC = TOS; goto 0x03a;
03a: 01d8142000 TOS = MDR; goto 0x03b;
03b: 000a140008 N = OPC; if (N) goto 0x101; else goto 0x001;
03c: 01e8144007 OPC = TOS; goto 0x03d;
03d: 01f0142000 TOS = MDR; goto 0x03e;
03e: 0009140008 Z = OPC; if (Z) goto 0x101; else goto 0x001;
03f: 0200370484 MAR = SP = SP - 1; goto 0x040;
040: 0208148020 H = MDR; rd; goto 0x041;
041: 0210144007 OPC = TOS; goto 0x042;
042: 0218142000 TOS = MDR; goto 0x043;
043: 00093f0008 Z = OPC - H; if (Z) goto 0x101; else goto 0x001;
044: 0228350211 PC = PC + 1; fetch; goto 0x045;
045: 0010000000 goto 0x002;
046: 0238948003 H = (MBRU) << 8; goto 0x047;
047: 02401c8003 H = H or MBRU; goto 0x048;
048: 02483c00a6 MAR = H + CPP; rd; goto 0x049;
049: 0250354001 OPC = PC + 1; goto 0x04a;
04a: 0258140210 PC = MDR; fetch; goto 0x04b;
04b: 0260350211 PC = PC + 1; fetch; goto 0x04c;
04c: 0268948003 H = (MBRU) << 8; goto 0x04d;
04d: 02701c8003 H = H or MBRU; goto 0x04e;
04e: 0278350211 PC = PC + 1; fetch; goto 0x04f;
04f: 02803f2004 TOS = SP - H; goto 0x050;
050: 0288352087 MAR = TOS = TOS + 1; goto 0x051;
051: 0290350211 PC = PC + 1; fetch; goto 0x052;
052: 0298948003 H = (MBRU) << 8; goto 0x053;
053: 02a01c8003 H = H or MBRU; goto 0x054;
054: 02a83d0144 MDR = H + SP + 1; wr; goto 0x055;
055: 02b0140480 MAR = SP = MDR; goto 0x056;
056: 02c0140148 MDR = OPC; wr; goto 0x058;
057: 00883704a4 MAR = SP = SP - 1; rd; goto 0x011;
058: 02d0350484 MAR = SP = SP + 1; goto 0x05a;
059: 0078350484 MAR = SP = SP + 1; goto 0x00f;
05a: 02d8140145 MDR = LV; wr; goto 0x05b;
05b: 02e0350211 PC = PC + 1; fetch; goto 0x05c;
05c: 0010140807 LV = TOS; goto 0x002;
05d: 02f0000000 goto 0x05e;
05e: 03081408a0 MAR = LV = MDR; rd; goto 0x061;
05f: 00a03700a4 MAR = SP - 1; rd; goto 0x014;
060: 00383704a4 MAR = SP = SP - 1; rd; goto 0x007;
061: 0310350085 MAR = LV + 1; goto 0x062;
062: 0318140230 PC = MDR; rd; fetch; goto 0x063;
063: 0328140084 MAR = SP; goto 0x065;
064: 00483704a4 MAR = SP = SP - 1; rd; goto 0x009;
065: 0330140800 LV = MDR; goto 0x066;
066: 0338140147 MDR = TOS; wr; goto 0x067;
067: 0011370001 Z = PC - 1; if (Z) goto 0x102; else goto 0x002;
068: 0348588000 H = (H) >> 1; goto 0x069;
069: 0350398000 H = H + 1; goto 0x06a;
06a: 03583704a4 MAR = SP = SP - 1; rd; goto 0x06b;
06b: 03600c2007 TOS = H and TOS; goto 0x06c;
06c: 036814c000 OPC = H = MDR; goto 0x06d;
06d: 0019140007 Z = TOS; if (Z) goto 0x103; else goto 0x003;
06e: 0378372007 TOS = TOS - 1; goto 0x06f;
06f: 0368000000 goto 0x06d;
070: 0388588000 H = (H) >> 1; goto 0x071;
071: 0390398000 H = H + 1; goto 0x072;
072: 03983704a4 MAR = SP = SP - 1; rd; goto 0x073;
073: 03a00c2007 TOS = H and TOS; goto 0x074;
074: 03a8148000 H = MDR; goto 0x075;
075: 0021140007 Z = TOS; if (Z) goto 0x104; else goto 0x004;
076: 03b8372007 TOS = TOS - 1; goto 0x077;
077: 03a8000000 goto 0x075;
078: 0340548003 H = (MBRU) >> 1; goto 0x068;
079: 03d858c000 OPC = H = (H) >> 1; goto 0x07b;
07a: 0380548003 H = (MBRU) >> 1; goto 0x070;
07b: 03e83704a4 MAR = SP = SP - 1; rd; goto 0x07d;
07c: 03c8548003 H = (MBRU) >> 1; goto 0x079;
07d: 03f80c2007 TOS = H and TOS; goto 0x07f;
07e: 00583704a4 MAR = SP = SP - 1; rd; goto 0x00b;
07f: 040835c008 OPC = H = OPC + 1; goto 0x081;
080: 00683704a4 MAR = SP = SP - 1; rd; goto 0x00d;
081: 04103cc008 OPC = H = H + OPC; goto 0x082;
082: 04183c4008 OPC = H + OPC; goto 0x083;
083: 0428944008 OPC = (OPC) << 8; goto 0x085;
084: 0170148005 H = LV; goto 0x02e;
085: 0430944008 OPC = (OPC) << 8; goto 0x086;
086: 0438944008 OPC = (OPC) << 8; goto 0x087;
087: 04402c4008 OPC = inv (OPC); goto 0x088;
088: 0448148000 H = MDR; goto 0x089;
089: 0029140007 Z = TOS; if (Z) goto 0x105; else goto 0x005;
08a: 04580c8008 H = H and OPC; goto 0x08b;
08b: 0460372007 TOS = TOS - 1; goto 0x08c;
08c: 0448000000 goto 0x089;
08d: 0000000000 goto 0x000;
08e: 0000000000 goto 0x000;
08f: 0000000000 goto 0x000;
090: 0000000000 goto 0x000;
091: 0000000000 goto 0x000;
092: 0000000000 goto 0x000;
093: 0000000000 goto 0x000;
094: 0000000000 goto 0x000;
095: 0000000000 goto 0x000;
096: 0000000000 goto 0x000;
097: 0000000000 goto 0x000;
098: 0000000000 goto 0x000;
099: 01e03704a4 MAR = SP = SP - 1; rd; goto 0x03c;
09a: 0000000000 goto 0x000;
09b: 01c83704a4 MAR = SP = SP - 1; rd; goto 0x039;
09c: 0000000000 goto 0x000;
09d: 0000000000 goto 0x000;
09e: 0000000000 goto 0x000;
09f: 01f83704a4 MAR = SP = SP - 1; rd; goto 0x03f;
0a0: 0000000000 goto 0x000;
0a1: 0000000000 goto 0x000;
0a2: 0000000000 goto 0x000;
0a3: 0000000000 goto 0x000;
0a4: 0000000000 goto 0x000;
0a5: 0000000000 goto 0x000;
0a6: 0000000000 goto 0x000;
0a7: 0198374001 OPC = PC - 1; goto 0x033;
0a8: 0000000000 goto 0x000;
0a9: 0000000000 goto 0x000;
0aa: 0000000000 goto 0x000;
0ab: 0000000000 goto 0x000;
0ac: 02e81404a5 MAR = SP = LV; rd; goto 0x05d;
0ad: 0000000000 goto 0x000;
0ae: 0000000000 goto 0x000;
0af: 0000000000 goto 0x000;
0b0: 0000000000 goto 0x000;
0b1: 0000000000 goto 0x000;
0b2: 0000000000 goto 0x000;
0b3: 0000000000 goto 0x000;
0b4: 0000000000 goto 0x000;
0b5: 0000000000 goto 0x000;
0b6: 0230350211 PC = PC + 1; fetch; goto 0x046;
0b7: 0000000000 goto 0x000;
0b8: 0000000000 goto 0x000;
0b9: 0000000000 goto 0x000;
0ba: 0000000000 goto 0x000;
0bb: 0000000000 goto 0x000;
0bc: 0000000000 goto 0x000;
0bd: 0000000000 goto 0x000;
0be: 0000000000 goto 0x000;
0bf: 0000000000 goto 0x000;
0c0: 0000000000 goto 0x000;
0c1: 0000000000 goto 0x000;
0c2: 0000000000 goto 0x000;
0c3: 0000000000 goto 0x000;
0c4: 0804350211 PC = PC + 1; fetch; goto (MBR or 0x100);
0c5: 0000000000 goto 0x000;
0c6: 0000000000 goto 0x000;
0c7: 0000000000 goto 0x000;
0c8: 0000000000 goto 0x000;
0c9: 0000000000 goto 0x000;
0ca: 0000000000 goto 0x000;
0cb: 0000000000 goto 0x000;
0cc: 0000000000 goto 0x000;
0cd: 0000000000 goto 0x000;
0ce: 0000000000 goto 0x000;
0cf: 0000000000 goto 0x000;
0d0: 0000000000 goto 0x000;
0d1: 0000000000 goto 0x000;
0d2: 0000000000 goto 0x000;
0d3: 0000000000 goto 0x000;
0d4: 0000000000 goto 0x000;
0d5: 0000000000 goto 0x000;
0d6: 0000000000 goto 0x000;
0d7: 0000000000 goto 0x000;
0d8: 0000000000 goto 0x000;
0d9: 0000000000 goto 0x000;
0da: 0000000000 goto 0x000;
0db: 0000000000 goto 0x000;
0dc: 0000000000 goto 0x000;
0dd: 0000000000 goto 0x000;
0de: 0000000000 goto 0x000;
0df: 0000000000 goto 0x000;
0e0: 0000000000 goto 0x000;
0e1: 0000000000 goto 0x000;
0e2: 0000000000 goto 0x000;
0e3: 0000000000 goto 0x000;
0e4: 0000000000 goto 0x000;
0e5: 0000000000 goto 0x000;
0e6: 0000000000 goto 0x000;
0e7: 0000000000 goto 0x000;
0e8: 0000000000 goto 0x000;
0e9: 0000000000 goto 0x000;
0ea: 0000000000 goto 0x000;
0eb: 0000000000 goto 0x000;
0ec: 0000000000 goto 0x000;
0ed: 0000000000 goto 0x000;
0ee: 0000000000 goto 0x000;
0ef: 0000000000 goto 0x000;
0f0: 0000000000 goto 0x000;
0f1: 0000000000 goto 0x000;
0f2: 0000000000 goto 0x000;
0f3: 0000000000 goto 0x000;
0f4: 0000000000 goto 0x000;
0f5: 0000000000 goto 0x000;
0f6: 0000000000 goto 0x000;
0f7: 0000000000 goto 0x000;
0f8: 0000000000 goto 0x000;
0f9: 0000000000 goto 0x000;
0fa: 0000000000 goto 0x000;
0fb: 0000000000 goto 0x000;
0fc: 0000000000 goto 0x000;
0fd: 0000000000 goto 0x000;
0fe: 0000000000 goto 0x000;
0ff: 0000000000 goto 0x000;
100: 0000000000 goto 0x000;
101: 0198374011 OPC = PC - 1; fetch; goto 0x033;
102: 000000000f halt
103: 0010182140 MDR = TOS = H; wr; goto 0x002;
104: 0010182140 MDR = TOS = H; wr; goto 0x002;
105: 0010182140 MDR = TOS = H; wr; goto 0x002;
106: 0000000000 goto 0x000;
107: 0000000000 goto 0x000;
108: 0000000000 goto 0x000;
109: 0000000000 goto 0x000;
10a: 0000000000 goto 0x000;
10b: 0000000000 goto 0x000;
10c: 0000000000 goto 0x000;
10d: 0000000000 goto 0x000;
10e: 0000000000 goto 0x000;
10f: 0000000000 goto 0x000;
110: 0000000000 goto 0x000;
111: 0000000000 goto 0x000;
112: 0000000000 goto 0x000;
113: 0000000000 goto 0x000;
114: 0000000000 goto 0x000;
115: 0128350211 PC = PC + 1; fetch; goto 0x025;
116: 0000000000 goto 0x000;
117: 0000000000 goto 0x000;
118: 0000000000 goto 0x000;
119: 0000000000 goto 0x000;
11a: 0000000000 goto 0x000;
11b: 0000000000 goto 0x000;
11c: 0000000000 goto 0x000;
11d: 0000000000 goto 0x000;
11e: 0000000000 goto 0x000;
11f: 0000000000 goto 0x000;
120: 0000000000 goto 0x000;
121: 0000000000 goto 0x000;
122: 0000000000 goto 0x000;
123: 0000000000 goto 0x000;
124: 0000000000 goto 0x000;
125: 0000000000 goto 0x000;
126: 0000000000 goto 0x000;
127: 0000000000 goto 0x000;
128: 0000000000 goto 0x000;
129: 0000000000 goto 0x000;
12a: 0000000000 goto 0x000;
12b: 0000000000 goto 0x000;
12c: 0000000000 goto 0x000;
12d: 0000000000 goto 0x000;
12e: 0000000000 goto 0x000;
12f: 0000000000 goto 0x000;
130: 0000000000 goto 0x000;
131: 0000000000 goto 0x000;
132: 0000000000 goto 0x000;
133: 0000000000 goto 0x000;
134: 0000000000 goto 0x000;
135: 0000000000 goto 0x000;
136: 0140350211 PC = PC + 1; fetch; goto 0x028;
137: 0000000000 goto 0x000;
138: 0000000000 goto 0x000;
139: 0000000000 goto 0x000;
13a: 0000000000 goto 0x000;
13b: 0000000000 goto 0x000;
13c: 0000000000 goto 0x000;
13d: 0000000000 goto 0x000;
13e: 0000000000 goto 0x000;
13f: 0000000000 goto 0x000;
140: 0000000000 goto 0x000;
141: 0000000000 goto 0x000;
142: 0000000000 goto 0x000;
143: 0000000000 goto 0x000;
144: 0000000000 goto 0x000;
145: 0000000000 goto 0x000;
146: 0000000000 goto 0x000;
147: 0000000000 goto 0x000;
148: 0000000000 goto 0x000;
149: 0000000000 goto 0x000;
14a: 0000000000 goto 0x000;
14b: 0000000000 goto 0x000;
14c: 0000000000 goto 0x000;
14d: 0000000000 goto 0x000;
14e: 0000000000 goto 0x000;
14f: 0000000000 goto 0x000;
150: 0000000000 goto 0x000;
151: 0000000000 goto 0x000;
152: 0000000000 goto 0x000;
153: 0000000000 goto 0x000;
154: 0000000000 goto 0x000;
155: 0000000000 goto 0x000;
156: 0000000000 goto 0x000;
157: 0000000000 goto 0x000;
158: 0000000000 goto 0x000;
159: 0000000000 goto 0x000;
15a: 0000000000 goto 0x000;
15b: 0000000000 goto 0x000;
15c: 0000000000 goto 0x000;
15d: 0000000000 goto 0x000;
15e: 0000000000 goto 0x000;
15f: 0000000000 goto 0x000;
160: 0000000000 goto 0x000;
161: 0000000000 goto 0x000;
162: 0000000000 goto 0x000;
163: 0000000000 goto 0x000;
164: 0000000000 goto 0x000;
165: 0000000000 goto 0x000;
166: 0000000000 goto 0x000;
167: 0000000000 goto 0x000;
168: 0000000000 goto 0x000;
169: 0000000000 goto 0x000;
16a: 0000000000 goto 0x000;
16b: 0000000000 goto 0x000;
16c: 0000000000 goto 0x000;
16d: 0000000000 goto 0x000;
16e: 0000000000 goto 0x000;
16f: 0000000000 goto 0x000;
170: 0000000000 goto 0x000;
171: 0000000000 goto 0x000;
172: 0000000000 goto 0x000;
173: 0000000000 goto 0x000;
174: 0000000000 goto 0x000;
175: 0000000000 goto 0x000;
176: 0000000000 goto 0x000;
177: 0000000000 goto 0x000;
178: 0000000000 goto 0x000;
179: 0000000000 goto 0x000;
17a: 0000000000 goto 0x000;
17b: 0000000000 goto 0x000;
17c: 0000000000 goto 0x000;
17d: 0000000000 goto 0x000;
17e: 0000000000 goto 0x000;
17f: 0000000000 goto 0x000;
180: 0000000000 goto 0x000;
181: 0000000000 goto 0x000;
182: 0000000000 goto 0x000;
183: 0000000000 goto 0x000;
184: 0000000000 goto 0x000;
185: 0000000000 goto 0x000;
186: 0000000000 goto 0x000;
187: 0000000000 goto 0x000;
188: 0000000000 goto 0x000;
189: 0000000000 goto 0x000;
18a: 0000000000 goto 0x000;
18b: 0000000000 goto 0x000;
18c: 0000000000 goto 0x000;
18d: 0000000000 goto 0x000;
18e: 0000000000 goto 0x000;
18f: 0000000000 goto 0x000;
190: 0000000000 goto 0x000;
191: 0000000000 goto 0x000;
192: 0000000000 goto 0x000;
193: 0000000000 goto 0x000;
194: 0000000000 goto 0x000;
195: 0000000000 goto 0x000;
196: 0000000000 goto 0x000;
197: 0000000000 goto 0x000;
198: 0000000000 goto 0x000;
199: 0000000000 goto 0x000;
19a: 0000000000 goto 0x000;
19b: 0000000000 goto 0x000;
19c: 0000000000 goto 0x000;
19d: 0000000000 goto 0x000;
19e: 0000000000 goto 0x000;
19f: 0000000000 goto 0x000;
1a0: 0000000000 goto 0x000;
1a1: 0000000000 goto 0x000;
1a2: 0000000000 goto 0x000;
1a3: 0000000000 goto 0x000;
1a4: 0000000000 goto 0x000;
1a5: 0000000000 goto 0x000;
1a6: 0000000000 goto 0x000;
1a7: 0000000000 goto 0x000;
1a8: 0000000000 goto 0x000;
1a9: 0000000000 goto 0x000;
1aa: 0000000000 goto 0x000;
1ab: 0000000000 goto 0x000;
1ac: 0000000000 goto 0x000;
1ad: 0000000000 goto 0x000;
1ae: 0000000000 goto 0x000;
1af: 0000000000 goto 0x000;
1b0: 0000000000 goto 0x000;
1b1: 0000000000 goto 0x000;
1b2: 0000000000 goto 0x000;
1b3: 0000000000 goto 0x000;
1b4: 0000000000 goto 0x000;
1b5: 0000000000 goto 0x000;
1b6: 0000000000 goto 0x000;
1b7: 0000000000 goto 0x000;
1b8: 0000000000 goto 0x000;
1b9: 0000000000 goto 0x000;
1ba: 0000000000 goto 0x000;
1bb: 0000000000 goto 0x000;
1bc: 0000000000 goto 0x000;
1bd: 0000000000 goto 0x000;
1be: 0000000000 goto 0x000;
1bf: 0000000000 goto 0x000;
1c0: 0000000000 goto 0x000;
1c1: 0000000000 goto 0x000;
1c2: 0000000000 goto 0x000;
1c3: 0000000000 goto 0x000;
1c4: 0000000000 goto 0x000;
1c5: 0000000000 goto 0x000;
1c6: 0000000000 goto 0x000;
1c7: 0000000000 goto 0x000;
1c8: 0000000000 goto 0x000;
1c9: 0000000000 goto 0x000;
1ca: 0000000000 goto 0x000;
1cb: 0000000000 goto 0x000;
1cc: 0000000000 goto 0x000;
1cd: 0000000000 goto 0x000;
1ce: 0000000000 goto 0x000;
1cf: 0000000000 goto 0x000;
1d0: 0000000000 goto 0x000;
1d1: 0000000000 goto 0x000;
1d2: 0000000000 goto 0x000;
1d3: 0000000000 goto 0x000;
1d4: 0000000000 goto 0x000;
1d5: 0000000000 goto 0x000;
1d6: 0000000000 goto 0x000;
1d7: 0000000000 goto 0x000;
1d8: 0000000000 goto 0x000;
1d9: 0000000000 goto 0x000;
1da: 0000000000 goto 0x000;
1db: 0000000000 goto 0x000;
1dc: 0000000000 goto 0x000;
1dd: 0000000000 goto 0x000;
1de: 0000000000 goto 0x000;
1df: 0000000000 goto 0x000;
1e0: 0000000000 goto 0x000;
1e1: 0000000000 goto 0x000;
1e2: 0000000000 goto 0x000;
1e3: 0000000000 goto 0x000;
1e4: 0000000000 goto 0x000;
1e5: 0000000000 goto 0x000;
1e6: 0000000000 goto 0x000;
1e7: 0000000000 goto 0x000;
1e8: 0000000000 goto 0x000;
1e9: 0000000000 goto 0x000;
1ea: 0000000000 goto 0x000;
1eb: 0000000000 goto 0x000;
1ec: 0000000000 goto 0x000;
1ed: 0000000000 goto 0x000;
1ee: 0000000000 goto 0x000;
1ef: 0000000000 goto 0x000;
1f0: 0000000000 goto 0x000;
1f1: 0000000000 goto 0x000;
1f2: 0000000000 goto 0x000;
1f3: 0000000000 goto 0x000;
1f4: 0000000000 goto 0x000;
1f5: 0000000000 goto 0x000;
1f6: 0000000000 goto 0x000;
1f7: 0000000000 goto 0x000;
1f8: 0000000000 goto 0x000;
1f9: 0000000000 goto 0x000;
1fa: 0000000000 goto 0x000;
1fb: 0000000000 goto 0x000;
1fc: 0000000000 goto 0x000;
1fd: 0000000000 goto 0x000;
1fe: 0000000000 goto 0x000;
1ff: 0000000000 goto 0x000;

View File

@ -0,0 +1,5 @@
main index: 0
method area: 10 bytes
00 03 00 00 15 01 15 02 78 ac
constant pool: 1 words
00000000

View File

@ -0,0 +1,8 @@
.method main
.args 3
.define a = 1
.define b = 2
iload a
iload b
ishl
ireturn

View File

@ -0,0 +1,5 @@
main index: 0
method area: 10 bytes
00 03 00 00 15 01 15 02 7a ac
constant pool: 1 words
00000000

View File

@ -0,0 +1,8 @@
.method main
.args 3
.define a = 1
.define b = 2
iload a
iload b
ishr
ireturn

View File

@ -0,0 +1,5 @@
main index: 0
method area: 10 bytes
00 03 00 00 15 01 15 02 7c ac
constant pool: 1 words
00000000

View File

@ -0,0 +1,8 @@
.method main
.args 3
.define a = 1
.define b = 2
iload a
iload b
iushr
ireturn

Binary file not shown.

View File

@ -0,0 +1,16 @@
public class Fib {
public static long fib(long n) {
if (n == 0) return 0;
if (n == 1) return 1;
return fib(n-1) + fib(n-2);
}
public static void main(String[] args) {
long a = 0;
long r = 0;
a = Long.parseUnsignedLong(args[0]);
r = fib(a);
System.out.println("fib("+ Long.toUnsignedString(a) + ") = " + r);
}
}

View File

@ -0,0 +1,35 @@
/**
* Created by Casper on 08-12-2015.
*/
public class FibIter {
private static long fib_iter(long a) {
long r = 0;
long minus_one = 1;
long minus_two = 0;
if (a == 0) {
r = 0;
} else if (a == 1) {
r = 1;
} else {
for (long i = 2; i <= a; i++) {
r = minus_one + minus_two;
minus_two = minus_one;
minus_one = r;
}
}
return r;
}
public static void main(String[] args) {
long a = 0;
long r = 0;
a = Long.parseUnsignedLong(args[0]);
r = fib_iter(a);
System.out.println("fib(" + Long.toUnsignedString(a) + ") = " + r);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Aflevering5-x86-64/bin/fib Executable file

Binary file not shown.

BIN
Aflevering5-x86-64/bin/fib-as Executable file

Binary file not shown.

Binary file not shown.

BIN
Aflevering5-x86-64/bin/fib_iter Executable file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,13 @@
#!/bin/bash
echo "Iterative"
echo " N: ${1}"
echo "---------"
/usr/bin/time --output=fib_iter.log -f %e ./fib_iter $1 &> /dev/null;
echo "fib_iter : `cat fib_iter.log`"
rm fib_iter.log
/usr/bin/time --output=fib_iter-as.log -f %e ./fib_iter-as $1 &> /dev/null;
echo "fib_iter-as : `cat fib_iter-as.log`"
rm fib_iter-as.log
/usr/bin/time --output=fib_iter-java.log -f %e ./fib_iter-java $1 &> /dev/null;
echo "fib_iter-java : `cat fib_iter-java.log`"
rm fib_iter-java.log

View File

@ -0,0 +1,13 @@
#!/bin/bash
echo "Recursive"
echo " N: ${1}"
echo "---------"
/usr/bin/time --output=fib.log -f %e ./fib $1 &> /dev/null;
echo "fib : `cat fib.log`"
rm fib.log
/usr/bin/time --output=fib-as.log -f %e ./fib-as $1 &> /dev/null;
echo "fib-as : `cat fib-as.log`"
rm fib-as.log
/usr/bin/time --output=fib-java.log -f %e ./fib-java $1 &> /dev/null;
echo "fib-java : `cat fib-java.log`"
rm fib-java.log

View File

@ -0,0 +1,21 @@
#!/bin/bash
echo " N: ${1}"
echo "---------"
/usr/bin/time --output=fib.log -f %e ./fib $1 &> /dev/null;
echo "fib : `cat fib.log`"
rm fib.log
/usr/bin/time --output=fib-as.log -f %e ./fib-as $1 &> /dev/null;
echo "fib-as : `cat fib-as.log`"
rm fib-as.log
/usr/bin/time --output=fib_iter.log -f %e ./fib_iter $1 &> /dev/null;
echo "fib_iter : `cat fib_iter.log`"
rm fib_iter.log
/usr/bin/time --output=fib_iter-as.log -f %e ./fib_iter-as $1 &> /dev/null;
echo "fib_iter-as : `cat fib_iter-as.log`"
rm fib_iter-as.log
/usr/bin/time --output=fib_iter-java.log -f %e ./fib_iter-java $1 &> /dev/null;
echo "fib_iter-java : `cat fib_iter-java.log`"
rm fib_iter-java.log
/usr/bin/time --output=fib-java.log -f %e ./fib-java $1 &> /dev/null;
echo "fib-java : `cat fib-java.log`"
rm fib-java.log

View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
extern unsigned long long fib(unsigned long long n);
int main(int argc, char *argv[]) {
unsigned long long n, r;
n = atoll(argv[1]);
r = fib(n);
printf("fib(%llu) = %llu\n", n, r);
return 0;
}

View File

@ -0,0 +1,96 @@
.global main
.section .data
result: .asciz "fib(%llu) = %llu\n"
a: .quad 0
.section .text
main: push %rbp # Save the old base pointer to the
# stack.
# This also makes sure that rsp is
# 16-byte aligned.
movq %rsp, %rbp # Write the new base pointer.
subq $16, %rsp # The stack frame is extended to fit
# the three local variables and the
# old value of the base pointer.
# ABI requires 16-byte alignment!
# This is not a problem here but it
# is very noteworthy!
movq 8(%rsi), %rdi # Retrieve the first argument from
# the array of arguments.
# The retrieved value is n in fib(n)
call atoll # Convert the argument to long long
movq %rax, %rdi # Save the long long as the argument
# for the fib(n) function.
movq %rax, a # Save the long long in a to use it
# later in the printed output.
call fib # Call the Fibonacci-function
movq a, %rsi # Move the number a to rsi to use it
# as the second argument for print.
movq %rax, %rdx # Move to result of the fib(n)-call
# to rdx, to use it as the third
# argument for printf.
movq $result, %rdi # Move the string to rdi, for use as
# as the first argument for print.
xor %al,%al # Specify that no vector arguments
# are to be used.
call printf # Print the string with values
xor %rax, %rax # Make sure to return 0 to indicate
# a successful run of the program.
jmp end # Jump to end to return from the
# program with the return value 0.
fib: push %rbp # Save old rbp to stack and align
# the stack pointer to 16-bytes,
# since the return address already
# has been pushed. Thus, the size
# of the two values totals to
# a size of 16-bytes.
movq %rsp, %rbp # Write new base pointer.
cmpq $1, %rdi # Compare the argument to 1.
je one # If equal to one, return 1.
cmpq $0, %rdi # Compare the argument to 0.
jle zero # If equal to zero or negative go
# to 'zero' and return zero.
decq %rdi # Decrement n by 1.
push %rdi # Save the value n - 1 in stack to
# be able to recover it later.
call fib # Call the function. The value of
# rax is now equal to the return
# value of fib(n-1).
pop %rdi # Restore rdi = n-1
decq %rdi # Decrement rdi by 1.
push %rax # Save the result of fib(n-1)
call fib # Call the function. The value of
# rax is now equal to the return
# value of fib(n-2).
addq (%rsp),%rax # Add fib(n-1) to rax which contains
# the reuslt of fib(n-2). fib(n-1)
# is retrieved from the stack.
jmp end # Jump to 'end' to leave and return
# from this call.
zero: movq $0, %rax # Set return value to 0.
jmp end
one: movq $1, %rax # Set return value to 1.
end: leave # Return the state of the base and
# stack pointers to their
# original state. By moving the
# base pointers value into the
# stack pointer and moving the old
# base pointer value into the stack
# pointer.
ret # Return from the current function
# with the contents of rax as the
# return value.

27
Aflevering5-x86-64/fib.c Normal file
View File

@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
unsigned long long fib(unsigned long long n) {
unsigned long long r; // Declare a local variable r
if (n == 0) { // If n is zero, return 0.
r = 0;
} else if (n == 1) { // If n is one, return 1.
r = 1;
} else { // Else, calculate the number
r = fib(n-1) + fib(n-2); // to return by utilising
} // recursion.
return r;
}
int main(int argc, char *argv[]) {
unsigned long long n, r; // Define local variables
n = atoll(argv[1]); // Convert the first argument
// to a long long value and
// load it into n.
r = fib(n); // Set the variable r to the
// n'th Fibonacci number.
// Print the number found.
printf("fib(%lld) = %lld\n", n, r);
return 0; // Return 0 to indicate a
// successful execution.
}

33
Aflevering5-x86-64/fib.s Normal file
View File

@ -0,0 +1,33 @@
.global fib
.section .text
fib: push %rbp # Save old rbp to stack and align
# the stack pointer to 16-bytes.
movq %rsp, %rbp # Write new base pointer.
cmpq $1, %rdi # Compare the argument to 1.
je one # If equal to one go to 'one' and
# return 1.
cmpq $0, %rdi # Compare the argument to 0.
je zero # If equal to zero go to 'zero'
# and return zero.
decq %rdi # Decrement n by 1.
push %rdi # Save the value n - 1 on the stack.
call fib # Call the function.
pop %rdi # Restore rdi = n-1
decq %rdi # Decrement rdi by 1.
push %rax # Save the result of fib(n-1)
call fib # Call the function.
addq (%rsp),%rax # Add the top element (fib(n-1)) to
# rax which contains fib(n-2).
jmp end # Jump to 'end' to leave and return
# from this call to the caller.
zero: movq $0, %rax # Set return value to 0.
jmp end
one: movq $1, %rax # Set return value to 1.
end: leave # Return the state of the base and
# stack pointers to their
# original state.
ret # Return from the current function
# with the contents of rax as the
# return value.

View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
extern unsigned long long fib_iter(unsigned long long n);
int main(int argc, char *argv[]) {
unsigned long long n, r;
n = atoll(argv[1]);
r = fib_iter(n);
printf("fib(%llu) = %llu\n", n, r);
return 0;
}

View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
unsigned long long fib_iter(unsigned long long a)
{
unsigned long long r = 0;
unsigned long long minus_one = 1;
unsigned long long minus_two = 0;
unsigned long long i;
if (a == 0) {
r = 0;
} else if (a == 1) {
r = 1;
} else {
for (i = 2; i <= a; i++) {
r = minus_one + minus_two;
minus_two = minus_one;
minus_one = r;
}
}
return r;
}
int main(int argc, char *argv[])
{
unsigned long long a = 0;
unsigned long long r = 0;
a = atol(argv[1]);
r = fib_iter(a);
printf("fib(%llu) = %llu\n",a,r);
return 0;
}

View File

@ -0,0 +1,117 @@
fib_iter.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <fib_iter>:
#include <stdio.h>
#include <stdlib.h>
unsigned long long fib_iter(unsigned long long a)
{
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 89 7d d8 mov %rdi,-0x28(%rbp)
unsigned long long r = 0;
8: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
f: 00
unsigned long long minus_one = 1;
10: 48 c7 45 f0 01 00 00 movq $0x1,-0x10(%rbp)
17: 00
unsigned long long minus_two = 0;
18: 48 c7 45 e8 00 00 00 movq $0x0,-0x18(%rbp)
1f: 00
unsigned long long i;
if (a == 0) {
20: 48 83 7d d8 00 cmpq $0x0,-0x28(%rbp)
25: 75 0a jne 31 <fib_iter+0x31>
r = 0;
27: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
2e: 00
2f: eb 49 jmp 7a <fib_iter+0x7a>
} else if (a == 1) {
31: 48 83 7d d8 01 cmpq $0x1,-0x28(%rbp)
36: 75 0a jne 42 <fib_iter+0x42>
r = 1;
38: 48 c7 45 f8 01 00 00 movq $0x1,-0x8(%rbp)
3f: 00
40: eb 38 jmp 7a <fib_iter+0x7a>
} else {
for (i = 2; i <= a; i++) {
42: 48 c7 45 e0 02 00 00 movq $0x2,-0x20(%rbp)
49: 00
4a: eb 24 jmp 70 <fib_iter+0x70>
r = minus_one + minus_two;
4c: 48 8b 55 f0 mov -0x10(%rbp),%rdx
50: 48 8b 45 e8 mov -0x18(%rbp),%rax
54: 48 01 d0 add %rdx,%rax
57: 48 89 45 f8 mov %rax,-0x8(%rbp)
minus_two = minus_one;
5b: 48 8b 45 f0 mov -0x10(%rbp),%rax
5f: 48 89 45 e8 mov %rax,-0x18(%rbp)
minus_one = r;
63: 48 8b 45 f8 mov -0x8(%rbp),%rax
67: 48 89 45 f0 mov %rax,-0x10(%rbp)
if (a == 0) {
r = 0;
} else if (a == 1) {
r = 1;
} else {
for (i = 2; i <= a; i++) {
6b: 48 83 45 e0 01 addq $0x1,-0x20(%rbp)
70: 48 8b 45 e0 mov -0x20(%rbp),%rax
74: 48 3b 45 d8 cmp -0x28(%rbp),%rax
78: 76 d2 jbe 4c <fib_iter+0x4c>
minus_two = minus_one;
minus_one = r;
}
}
return r;
7a: 48 8b 45 f8 mov -0x8(%rbp),%rax
}
7e: 5d pop %rbp
7f: c3 retq
0000000000000080 <main>:
int main(int argc, char *argv[])
{
80: 55 push %rbp
81: 48 89 e5 mov %rsp,%rbp
84: 48 83 ec 20 sub $0x20,%rsp
88: 89 7d ec mov %edi,-0x14(%rbp)
8b: 48 89 75 e0 mov %rsi,-0x20(%rbp)
unsigned long long a = 0;
8f: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
96: 00
unsigned long long r = 0;
97: 48 c7 45 f0 00 00 00 movq $0x0,-0x10(%rbp)
9e: 00
a = atol(argv[1]);
9f: 48 8b 45 e0 mov -0x20(%rbp),%rax
a3: 48 83 c0 08 add $0x8,%rax
a7: 48 8b 00 mov (%rax),%rax
aa: 48 89 c7 mov %rax,%rdi
ad: e8 00 00 00 00 callq b2 <main+0x32>
b2: 48 89 45 f8 mov %rax,-0x8(%rbp)
r = fib_iter(a);
b6: 48 8b 45 f8 mov -0x8(%rbp),%rax
ba: 48 89 c7 mov %rax,%rdi
bd: e8 00 00 00 00 callq c2 <main+0x42>
c2: 48 89 45 f0 mov %rax,-0x10(%rbp)
printf("fib(%llu) = %llu\n",a,r);
c6: 48 8b 55 f0 mov -0x10(%rbp),%rdx
ca: 48 8b 45 f8 mov -0x8(%rbp),%rax
ce: 48 89 c6 mov %rax,%rsi
d1: bf 00 00 00 00 mov $0x0,%edi
d6: b8 00 00 00 00 mov $0x0,%eax
db: e8 00 00 00 00 callq e0 <main+0x60>
return 0;
e0: b8 00 00 00 00 mov $0x0,%eax
}
e5: c9 leaveq
e6: c3 retq

View File

@ -0,0 +1,39 @@
.section .text
.global fib_iter
fib_iter:
push %rbp # Save old base pointer to stack.
# This also makes sure that rsp is
# 16-byte aligned.
movq %rsp, %rbp # Write new base pointer
cmpq $1, %rdi # Compare the argument to 1
je one # If n = 1 go to 'one' label.
cmpq $0, %rdi
je zero # If n = 0, go to 'zero' label.
movq $1, %rcx # Set minus_one (rcx) to 1
movq $0, %rdx # Set minus_two (rdx) to 0
movq %rcx, %rax # Set r (rax) to minus_one (rcx)
loop: addq %rdx, %rax # r (rax) = minus_one (rcx)
# + minus_two (rdx)
# rax is already set to minus_one
# due to the last line in the loop
# The first time the loop is run,
# this is handled before the loop.
movq %rcx, %rdx # minus_two (rdx) = minus_one (rcx)
movq %rax, %rcx # minus_one (rcx) = r (rax)
decq %rdi # Decrement the counter by 1.
cmpq $1, %rdi # Loop if the counter is over 1:
jle end # If counter is 1:
# End and return r (rax)
jmp loop # If counter is 0: loop.
zero: movq $0, %rax # Return 0.
jmp end
one: movq $1, %rax # Return 1.
end: leave # Return the state of the base and
# stack pointers to their
# original state.
ret # Return r (rax)

View File

@ -0,0 +1,24 @@
CC=gcc
CFLAGS=
INSTALL_PATH=/usr/local
all: fib fib-as fib_iter fib_iter-as fib-pure-as
fib: fib.c
$(CC) $(CFLAGS) fib.c -o bin/fib
fib-as: fib-ext.c fib.s
$(CC) $(CFLAGS) fib-ext.c fib.s -o bin/fib-as
fib_iter: fib_iter.c
$(CC) $(CFLAGS) fib_iter.c -o bin/fib_iter
fib_iter-as: fib_iter-ext.c fib_iter.s
$(CC) $(CFLAGS) fib_iter-ext.c fib_iter.s -o bin/fib_iter-as
fib-pure-as: fib-pure-as.s
$(CC) $(CFLAGS) fib-pure-as.s -o bin/fib-pure-as
install:
cp bin/fib* ${INSTALL_PATH}/bin
uninstall:
rm ${INSTALL_PATH}/bin/fib
rm ${INSTALL_PATH}/bin/fib_iter
rm ${INSTALL_PATH}/bin/fib-as
rm ${INSTALL_PATH}/bin/fib_iter-as
rm ${INSTALL_PATH}/bin/fib-pure-as
clean:
rm bin/fib*

1
README.md Normal file
View File

@ -0,0 +1 @@
This repository contains files from the course dComArk15.