commit e2e36f9f0d1f791c930f7daff5237e38b75a6a5f Author: Christoffer Müller Madsen Date: Sun Jan 3 13:29:05 2016 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/Afl1-dComArk-Paritetsfunktionen.pdf b/Afl1-dComArk-Paritetsfunktionen.pdf new file mode 100644 index 0000000..b012bd1 Binary files /dev/null and b/Afl1-dComArk-Paritetsfunktionen.pdf differ diff --git a/Afl2-dComArk-Heltalsmultiplikation.pdf b/Afl2-dComArk-Heltalsmultiplikation.pdf new file mode 100644 index 0000000..306a620 Binary files /dev/null and b/Afl2-dComArk-Heltalsmultiplikation.pdf differ diff --git a/Afl3-dComArk-Overloeb.pdf b/Afl3-dComArk-Overloeb.pdf new file mode 100644 index 0000000..7fd28d8 Binary files /dev/null and b/Afl3-dComArk-Overloeb.pdf differ diff --git a/Afl4-dComArk-IJVMUdvidelse.pdf b/Afl4-dComArk-IJVMUdvidelse.pdf new file mode 100644 index 0000000..984c41a Binary files /dev/null and b/Afl4-dComArk-IJVMUdvidelse.pdf differ diff --git a/Afl5-dComArk-x86-64.pdf b/Afl5-dComArk-x86-64.pdf new file mode 100644 index 0000000..4a305d1 Binary files /dev/null and b/Afl5-dComArk-x86-64.pdf differ diff --git a/Aflevering1-Paritetsfunktionen/Afl1-dComArk-Paritetsfunktionen.pdf b/Aflevering1-Paritetsfunktionen/Afl1-dComArk-Paritetsfunktionen.pdf new file mode 100644 index 0000000..b012bd1 Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Afl1-dComArk-Paritetsfunktionen.pdf differ diff --git a/Aflevering1-Paritetsfunktionen/Afl1_AND.circ b/Aflevering1-Paritetsfunktionen/Afl1_AND.circ new file mode 100644 index 0000000..dfbdeab --- /dev/null +++ b/Aflevering1-Paritetsfunktionen/Afl1_AND.circ @@ -0,0 +1,281 @@ + + +This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/). + + + + + + + + + + + + + + addr/data: 8 8 +0 + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aflevering1-Paritetsfunktionen/Afl1_XOR.circ b/Aflevering1-Paritetsfunktionen/Afl1_XOR.circ new file mode 100644 index 0000000..d2838c3 --- /dev/null +++ b/Aflevering1-Paritetsfunktionen/Afl1_XOR.circ @@ -0,0 +1,159 @@ + + +This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/). + + + + + + + + + + + + + + + + + addr/data: 8 8 +0 + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aflevering1-Paritetsfunktionen/Afl_XOR2.circ b/Aflevering1-Paritetsfunktionen/Afl_XOR2.circ new file mode 100644 index 0000000..423237c --- /dev/null +++ b/Aflevering1-Paritetsfunktionen/Afl_XOR2.circ @@ -0,0 +1,94 @@ + + +This file is intended to be loaded by Logisim (http://www.cburch.com/logisim/). + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aflevering1-Paritetsfunktionen/Eksempel_0000.png b/Aflevering1-Paritetsfunktionen/Eksempel_0000.png new file mode 100644 index 0000000..936cedd Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Eksempel_0000.png differ diff --git a/Aflevering1-Paritetsfunktionen/Eksempel_1010.png b/Aflevering1-Paritetsfunktionen/Eksempel_1010.png new file mode 100644 index 0000000..8dcd458 Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Eksempel_1010.png differ diff --git a/Aflevering1-Paritetsfunktionen/Eksempel_1110.png b/Aflevering1-Paritetsfunktionen/Eksempel_1110.png new file mode 100644 index 0000000..09fe376 Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Eksempel_1110.png differ diff --git a/Aflevering1-Paritetsfunktionen/Kredsloeb1_AND.png b/Aflevering1-Paritetsfunktionen/Kredsloeb1_AND.png new file mode 100644 index 0000000..223dc81 Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Kredsloeb1_AND.png differ diff --git a/Aflevering1-Paritetsfunktionen/Kredsloeb2_XOR1.png b/Aflevering1-Paritetsfunktionen/Kredsloeb2_XOR1.png new file mode 100644 index 0000000..65814a0 Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Kredsloeb2_XOR1.png differ diff --git a/Aflevering1-Paritetsfunktionen/Kredsloeb3_XOR2.png b/Aflevering1-Paritetsfunktionen/Kredsloeb3_XOR2.png new file mode 100644 index 0000000..b767c24 Binary files /dev/null and b/Aflevering1-Paritetsfunktionen/Kredsloeb3_XOR2.png differ diff --git a/Aflevering3-Overloeb/Afl3-dComArk-Overloeb.pdf b/Aflevering3-Overloeb/Afl3-dComArk-Overloeb.pdf new file mode 100644 index 0000000..7fd28d8 Binary files /dev/null and b/Aflevering3-Overloeb/Afl3-dComArk-Overloeb.pdf differ diff --git a/Aflevering3-Overloeb/eq.j b/Aflevering3-Overloeb/eq.j new file mode 100644 index 0000000..45c9003 --- /dev/null +++ b/Aflevering3-Overloeb/eq.j @@ -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 diff --git a/Aflevering3-Overloeb/geq.j b/Aflevering3-Overloeb/geq.j new file mode 100644 index 0000000..b2666bd --- /dev/null +++ b/Aflevering3-Overloeb/geq.j @@ -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 diff --git a/Aflevering4-IJVM-Udvidelse/Afl4-dComArk-IJVMUdvidelse.pdf b/Aflevering4-IJVM-Udvidelse/Afl4-dComArk-IJVMUdvidelse.pdf new file mode 100644 index 0000000..984c41a Binary files /dev/null and b/Aflevering4-IJVM-Udvidelse/Afl4-dComArk-IJVMUdvidelse.pdf differ diff --git a/Aflevering4-IJVM-Udvidelse/ijvm.spec b/Aflevering4-IJVM-Udvidelse/ijvm.spec new file mode 100644 index 0000000..3000281 --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/ijvm.spec @@ -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 + diff --git a/Aflevering4-IJVM-Udvidelse/ijvm_ext.mal b/Aflevering4-IJVM-Udvidelse/ijvm_ext.mal new file mode 100644 index 0000000..03c09f0 --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/ijvm_ext.mal @@ -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 diff --git a/Aflevering4-IJVM-Udvidelse/ijvm_ext.mic1 b/Aflevering4-IJVM-Udvidelse/ijvm_ext.mic1 new file mode 100644 index 0000000..0409e72 --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/ijvm_ext.mic1 @@ -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; diff --git a/Aflevering4-IJVM-Udvidelse/test_ishl.bc b/Aflevering4-IJVM-Udvidelse/test_ishl.bc new file mode 100644 index 0000000..f78b9eb --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/test_ishl.bc @@ -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 diff --git a/Aflevering4-IJVM-Udvidelse/test_ishl.j b/Aflevering4-IJVM-Udvidelse/test_ishl.j new file mode 100644 index 0000000..7e3251d --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/test_ishl.j @@ -0,0 +1,8 @@ +.method main +.args 3 +.define a = 1 +.define b = 2 + iload a + iload b + ishl + ireturn diff --git a/Aflevering4-IJVM-Udvidelse/test_ishr.bc b/Aflevering4-IJVM-Udvidelse/test_ishr.bc new file mode 100644 index 0000000..a43a33b --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/test_ishr.bc @@ -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 diff --git a/Aflevering4-IJVM-Udvidelse/test_ishr.j b/Aflevering4-IJVM-Udvidelse/test_ishr.j new file mode 100644 index 0000000..fd79599 --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/test_ishr.j @@ -0,0 +1,8 @@ +.method main +.args 3 +.define a = 1 +.define b = 2 + iload a + iload b + ishr + ireturn diff --git a/Aflevering4-IJVM-Udvidelse/test_iushr.bc b/Aflevering4-IJVM-Udvidelse/test_iushr.bc new file mode 100644 index 0000000..26247a9 --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/test_iushr.bc @@ -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 diff --git a/Aflevering4-IJVM-Udvidelse/test_iushr.j b/Aflevering4-IJVM-Udvidelse/test_iushr.j new file mode 100644 index 0000000..654c750 --- /dev/null +++ b/Aflevering4-IJVM-Udvidelse/test_iushr.j @@ -0,0 +1,8 @@ +.method main +.args 3 +.define a = 1 +.define b = 2 + iload a + iload b + iushr + ireturn diff --git a/Aflevering5-x86-64/Afl5-dComArk-x86-64.pdf b/Aflevering5-x86-64/Afl5-dComArk-x86-64.pdf new file mode 100644 index 0000000..4a305d1 Binary files /dev/null and b/Aflevering5-x86-64/Afl5-dComArk-x86-64.pdf differ diff --git a/Aflevering5-x86-64/Fib.java b/Aflevering5-x86-64/Fib.java new file mode 100644 index 0000000..0ce795f --- /dev/null +++ b/Aflevering5-x86-64/Fib.java @@ -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); + } +} diff --git a/Aflevering5-x86-64/FibIter.java b/Aflevering5-x86-64/FibIter.java new file mode 100644 index 0000000..7fc23b9 --- /dev/null +++ b/Aflevering5-x86-64/FibIter.java @@ -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); + } +} diff --git a/Aflevering5-x86-64/Kalddiagram.pdf b/Aflevering5-x86-64/Kalddiagram.pdf new file mode 100644 index 0000000..6c359cc Binary files /dev/null and b/Aflevering5-x86-64/Kalddiagram.pdf differ diff --git a/Aflevering5-x86-64/Stakdiagram.pdf b/Aflevering5-x86-64/Stakdiagram.pdf new file mode 100644 index 0000000..c48f06a Binary files /dev/null and b/Aflevering5-x86-64/Stakdiagram.pdf differ diff --git a/Aflevering5-x86-64/bin/Fib.class b/Aflevering5-x86-64/bin/Fib.class new file mode 100644 index 0000000..03ad15f Binary files /dev/null and b/Aflevering5-x86-64/bin/Fib.class differ diff --git a/Aflevering5-x86-64/bin/FibIter.class b/Aflevering5-x86-64/bin/FibIter.class new file mode 100644 index 0000000..febf5f4 Binary files /dev/null and b/Aflevering5-x86-64/bin/FibIter.class differ diff --git a/Aflevering5-x86-64/bin/fib b/Aflevering5-x86-64/bin/fib new file mode 100755 index 0000000..0bf593d Binary files /dev/null and b/Aflevering5-x86-64/bin/fib differ diff --git a/Aflevering5-x86-64/bin/fib-as b/Aflevering5-x86-64/bin/fib-as new file mode 100755 index 0000000..b327f86 Binary files /dev/null and b/Aflevering5-x86-64/bin/fib-as differ diff --git a/Aflevering5-x86-64/bin/fib-pure-as b/Aflevering5-x86-64/bin/fib-pure-as new file mode 100755 index 0000000..2647032 Binary files /dev/null and b/Aflevering5-x86-64/bin/fib-pure-as differ diff --git a/Aflevering5-x86-64/bin/fib_iter b/Aflevering5-x86-64/bin/fib_iter new file mode 100755 index 0000000..8b68b0a Binary files /dev/null and b/Aflevering5-x86-64/bin/fib_iter differ diff --git a/Aflevering5-x86-64/bin/fib_iter-as b/Aflevering5-x86-64/bin/fib_iter-as new file mode 100755 index 0000000..4d40b6e Binary files /dev/null and b/Aflevering5-x86-64/bin/fib_iter-as differ diff --git a/Aflevering5-x86-64/bin/timetest-iter.sh b/Aflevering5-x86-64/bin/timetest-iter.sh new file mode 100755 index 0000000..9a6fac0 --- /dev/null +++ b/Aflevering5-x86-64/bin/timetest-iter.sh @@ -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 diff --git a/Aflevering5-x86-64/bin/timetest-rec.sh b/Aflevering5-x86-64/bin/timetest-rec.sh new file mode 100755 index 0000000..1d6c87e --- /dev/null +++ b/Aflevering5-x86-64/bin/timetest-rec.sh @@ -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 diff --git a/Aflevering5-x86-64/bin/timetest.sh b/Aflevering5-x86-64/bin/timetest.sh new file mode 100755 index 0000000..37da4db --- /dev/null +++ b/Aflevering5-x86-64/bin/timetest.sh @@ -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 diff --git a/Aflevering5-x86-64/fib-ext.c b/Aflevering5-x86-64/fib-ext.c new file mode 100644 index 0000000..0587475 --- /dev/null +++ b/Aflevering5-x86-64/fib-ext.c @@ -0,0 +1,13 @@ +#include +#include + +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; +} diff --git a/Aflevering5-x86-64/fib-pure-as.s b/Aflevering5-x86-64/fib-pure-as.s new file mode 100644 index 0000000..c1613c3 --- /dev/null +++ b/Aflevering5-x86-64/fib-pure-as.s @@ -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. diff --git a/Aflevering5-x86-64/fib.c b/Aflevering5-x86-64/fib.c new file mode 100644 index 0000000..a2de0a9 --- /dev/null +++ b/Aflevering5-x86-64/fib.c @@ -0,0 +1,27 @@ +#include +#include + +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. +} diff --git a/Aflevering5-x86-64/fib.s b/Aflevering5-x86-64/fib.s new file mode 100644 index 0000000..03d052d --- /dev/null +++ b/Aflevering5-x86-64/fib.s @@ -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. diff --git a/Aflevering5-x86-64/fib_iter-ext.c b/Aflevering5-x86-64/fib_iter-ext.c new file mode 100644 index 0000000..17f452b --- /dev/null +++ b/Aflevering5-x86-64/fib_iter-ext.c @@ -0,0 +1,13 @@ +#include +#include + +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; +} diff --git a/Aflevering5-x86-64/fib_iter.c b/Aflevering5-x86-64/fib_iter.c new file mode 100644 index 0000000..dfcfa08 --- /dev/null +++ b/Aflevering5-x86-64/fib_iter.c @@ -0,0 +1,35 @@ +#include +#include + +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; +} diff --git a/Aflevering5-x86-64/fib_iter.objdump.s b/Aflevering5-x86-64/fib_iter.objdump.s new file mode 100644 index 0000000..307e921 --- /dev/null +++ b/Aflevering5-x86-64/fib_iter.objdump.s @@ -0,0 +1,117 @@ + +fib_iter.o: file format elf64-x86-64 + + +Disassembly of section .text: + +0000000000000000 : +#include +#include + +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 + r = 0; + 27: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp) + 2e: 00 + 2f: eb 49 jmp 7a + } else if (a == 1) { + 31: 48 83 7d d8 01 cmpq $0x1,-0x28(%rbp) + 36: 75 0a jne 42 + r = 1; + 38: 48 c7 45 f8 01 00 00 movq $0x1,-0x8(%rbp) + 3f: 00 + 40: eb 38 jmp 7a + } 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 + 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 + 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
: + +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 + 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 + 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 + return 0; + e0: b8 00 00 00 00 mov $0x0,%eax +} + e5: c9 leaveq + e6: c3 retq diff --git a/Aflevering5-x86-64/fib_iter.s b/Aflevering5-x86-64/fib_iter.s new file mode 100644 index 0000000..777c9a2 --- /dev/null +++ b/Aflevering5-x86-64/fib_iter.s @@ -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) diff --git a/Aflevering5-x86-64/makefile b/Aflevering5-x86-64/makefile new file mode 100644 index 0000000..a633a79 --- /dev/null +++ b/Aflevering5-x86-64/makefile @@ -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* diff --git a/README.md b/README.md new file mode 100644 index 0000000..d408ca8 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This repository contains files from the course dComArk15.