diff --git a/serie2/Theorieteil.txt b/serie2/Theorieteil.txt index fd1eed6..1c5a40a 100644 --- a/serie2/Theorieteil.txt +++ b/serie2/Theorieteil.txt @@ -66,10 +66,17 @@ for(i=11; i >= 0; i--){ {do soomething}; +int s2 = 11; +while (s2 !=0 ) { + // do something + s2-- ; +} + Aufgabe 5 ---------- +bge $32, $s1, label /* $s2 >= $s1 springe zu label1 */ @@ -82,27 +89,33 @@ a) Big Endian b) Little Endian blockweise vertauschte Reihenfolge der Binärwerte, Adresse 10004 ist Startblock) der Blöcke) +BE +10007 0000 0000 Wert -> 837 900 800 + +LE +10004 0110 1101 Wert -> 2 395 245 + 1. Block 1 ^ 0 -= 1 1 1 += 1 1 1 2 ^ 1 = 2 2 * 2 -= 4 1 4 += 4 1 4 4 * 2 -= 8 1 8 += 8 1 8 8 * 2 = 16 16 * 2 -= 32 1 32 += 32 1 32 32 * 2 -= 64 1 64 += 64 1 64 64 * 2 = 128 @@ -118,22 +131,22 @@ Adresse 10006 10005 = 512 512 * 2 -= 1024 1 1024 1 1024 += 1024 1 1024 1 1024 1024 * 2 -= 2048 1 2048 += 2048 1 2048 2048 * 2 = 4096 4096 * 2 -= 8192 1 8192 += 8192 1 8192 8192 * 2 = 16384 16384 * 2 -= 32768 1 32768 += 32768 1 32768 Adresse 10005 10006 3. Block @@ -144,46 +157,46 @@ Adresse 10005 10006 = 131072 131072 * 2 -= 262144 1 262144 1 262144 += 262144 1 262144 1 262144 262144 * 2 -= 524288 1 524288 += 524288 1 524288 524288 * 2 = 1048576 1048576 * 2 -= 2097152 1 2097152 += 2097152 1 2097152 2097152 * 2 = 4194304 4194304 * 2 -= 8388608 1 8388608 += 8388608 1 8388608 Adresse 10004 10007 4. Block 8388608 * 2 -= 16777216 1 16777216 += 16777216 1 16777216 16777216 * 2 = 33554432 33554432 * 2 -= 67108864 1 67108864 += 67108864 1 67108864 67108864 * 2 -= 134217728 1 134217728 += 134217728 1 134217728 134217728 * 2 = 268435456 268435456 * 2 -= 536870912 1 536870912 += 536870912 1 536870912 536870912 * 2 -= 1073741824 1 1073741824 += 1073741824 1 1073741824 1073741824 * 2 = 2147483648 @@ -206,8 +219,23 @@ L1: addi $t0,$t0-1 L2: sw $t2,indext(t3) +Aufgabe 8 +--------- +Angenommen, A sei ein Array mit zehn Daten-Wörtern (im Hauptspeicher), die Basisadresse des +Arrays befinde sich in $s1. Laden Sie das letzte Wort von A mit genau einem Befehl in das +Register $s2: + +lw $s2, 36($s1) + +-> Das Wort wird aus $s1 geladen. Das Array + beginnt bei 0 =1 + + Das Wort 10 in im Array A[9] => 9 * 4 = 36($s1) + Das Wort wird in $s2 gespeicher mit lw. + + + Optionale Fragen ---------------- -Byte-Reihenfolge: - +Byte-Reihenfolge: LE diff --git a/serie2/mips.c b/serie2/mips.c index 535efc2..da60313 100644 --- a/serie2/mips.c +++ b/serie2/mips.c @@ -1,5 +1,4 @@ -/* TODO: Task (b) Please fill in the following lines, then remove this line. - * +/* * author(s): Thomas Rickenbach * Mathieu Simon * modified: 2011-04-04 @@ -20,7 +19,7 @@ word pc; int doRun; /* In case you want to watch the machine working */ -int verbose = TRUE; +int verbose = FALSE; /* Operation and function dispatcher */ Operation operations[OPERATION_COUNT]; @@ -80,10 +79,10 @@ void printInstruction(Instruction *i) { /* Store a word to memory */ void storeWord(word w, word location) { - memory[location] = (w >> (8*3)); - memory[location+1] = (w >> (8*2) && 0xFF); - memory[location+2] = (w >> (8*1) && 0xFF); - memory[location+3] = (w && 0xFF); + memory[location] = ( w >> (8*3)); + memory[location+1] = ( (w >> (8*2)) & 0xFF); + memory[location+2] = ( (w >> (8*1)) & 0xFF); + memory[location+3] = ( w & 0xFF); } /* Load a word from memory */ @@ -201,21 +200,27 @@ void stopOperation(Instruction *instruction) { /* ADD */ void mips_add(Instruction *instruction) { - /* TODO: Task (e) implement ADD here */ + InstructionTypeR r = instruction->r; + registers[r.rd] = (signed)registers[r.rs] + (signed)registers[r.rt]; } /* ADDI */ void mips_addi(Instruction *instruction) { - /* TODO: Task (e) implement ADDI here */ + InstructionTypeI i = instruction->i; + registers[i.rt] = (signed)registers[i.rs] + (signed)signExtend(i.immediate); } /* JAL */ void mips_jal(Instruction *instruction) { - /* TODO: Task (e) implement JAL here */} + InstructionTypeJ j = instruction->j; + RA = pc; + pc = (pc&0xf0000000)+(signed)4*j.address; +} /* LUI */ void mips_lui(Instruction *instruction) { - /* TODO: Task (e) implement LUI here */ + InstructionTypeI i = instruction->i; + registers[i.rt] = i.immediate << (2*8); } /* LW */ @@ -238,6 +243,6 @@ void mips_sub(Instruction *instruction) { /* SW */ void mips_sw(Instruction *instruction) { - /* TODO: Task (e) implement SW here */ + InstructionTypeI i = instruction->i; + storeWord(registers[i.rt], registers[i.rs] + (signed)signExtend(i.immediate)); } - diff --git a/serie2/muster/mips.c b/serie2/muster/mips.c index d93de8f..672e8cc 100644 --- a/serie2/muster/mips.c +++ b/serie2/muster/mips.c @@ -77,12 +77,11 @@ void printInstruction(Instruction *i) { /* Store a word to memory */ void storeWord(word w, word location) { - - memory[location] = (w >> (8*3)); + memory[location] = ( w >> (8*3)); memory[location+1] = ((w >> (8*2)) & 0xFF); memory[location+2] = ((w >> (8*1)) & 0xFF); - memory[location+3] = (w & 0xFF); - } + memory[location+3] = ( w & 0xFF); +} /* Load a word from memory */ word loadWordFrom(word location) { diff --git a/serie2/muster/mips.o b/serie2/muster/mips.o deleted file mode 100644 index 8b2ba24..0000000 Binary files a/serie2/muster/mips.o and /dev/null differ diff --git a/serie2/muster/test.c b/serie2/muster/test.c index 9390977..1176ee5 100644 --- a/serie2/muster/test.c +++ b/serie2/muster/test.c @@ -129,18 +129,18 @@ void test_ori() { void test_sub() { T2 = 1; T1 = 1; - test_execute(create_rtype_hex( FC_SUB, 0, I_T0, I_T1, I_T2, OC_SUB)); - assert(T0 == 0); + test_execute(create_rtype_hex( FC_SUB, 0, I_T0, I_T1, I_T2, OC_SUB)); + assert(T0 == 0); - T2 = 1; + T2 = 1; T1 = -1; - test_execute(create_rtype_hex( FC_SUB, 0, I_T0, I_T1, I_T2, OC_SUB)); - assert(T0 == 2); + test_execute(create_rtype_hex( FC_SUB, 0, I_T0, I_T1, I_T2, OC_SUB)); + assert(T0 == 2); - T2 = 1; - T1 = -1; - test_execute(create_rtype_hex( FC_SUB, 0, I_T0, I_T1, I_T2, OC_SUB)); - assert(T0 == 2); + T2 = 1; + T1 = -1; + test_execute(create_rtype_hex( FC_SUB, 0, I_T0, I_T1, I_T2, OC_SUB)); + assert(T0 == 2); } diff --git a/serie2/muster/test.o b/serie2/muster/test.o deleted file mode 100644 index 6347096..0000000 Binary files a/serie2/muster/test.o and /dev/null differ diff --git a/serie2/muster.patch b/serie2/skeleton/muster.patch similarity index 100% rename from serie2/muster.patch rename to serie2/skeleton/muster.patch diff --git a/serie2/skeleton/test.c b/serie2/skeleton/test.c index 38a1205..9e4b226 100644 --- a/serie2/skeleton/test.c +++ b/serie2/skeleton/test.c @@ -89,6 +89,7 @@ void test_jal() { pc += 4; operations[instruction->i.opcode].operation(instruction); assert(RA == pcSaved + 4); + printf(pc); assert(pc == 0xA0000004); } diff --git a/serie2/test.c b/serie2/test.c index ba62f76..07bc5e5 100644 --- a/serie2/test.c +++ b/serie2/test.c @@ -1,5 +1,4 @@ -/* TODO: Task (b) Please fill in the following lines, then remove this line. - * +/* * author(s): Thomas Rickenbach * Mathieu Simon * modified: 2011-04-04 @@ -89,7 +88,7 @@ void test_jal() { pc += 4; operations[instruction->i.opcode].operation(instruction); assert(RA == pcSaved + 4); - assert(pc == 0xA0000004); + assert(pc == 0xA0000004); } /* LUI */ @@ -103,17 +102,47 @@ void test_lui() { /* LW */ void test_lw() { - /* TODO: Task (d) add test for LW here */ -} + word location1 = 0x00001000; + + word w = 0xFFFFFFFF; + storeWord(w, location1); + T1 = location1; + test_execute(create_itype_hex(0x0000, I_T0, I_T1, OC_LW)); + assert(T0 == w); + + w =0x12345678; + storeWord(w, location1 + 0x0001); + T1 = location1; + test_execute(create_itype_hex(0x0001, I_T0, I_T1, OC_LW)); + assert(T0 == w); +} /* ORI */ void test_ori() { - /* TODO: Task (d) add test for ORI here */ + T2 = 0x0000A005; + test_execute(create_itype_hex(0xA099, I_T0, I_T2, OC_ORI)); + assert(T0 == (0x0000A005 | 0xA099)); + + test_execute(create_itype_hex(0xFFFF, I_T0, I_T2, OC_ORI)); + assert(T0 == 0x0000FFFF); } /* SUB */ void test_sub() { - /* TODO: Task (d) add test for SUB here */ + T1=2; + T2=8; + test_execute(create_rtype_hex(FC_SUB, 0x0000, I_T0, I_T1, I_T2, OC_SUB)); + assert(T0==6); + + T1=8; + T2=2; + test_execute(create_rtype_hex(FC_SUB, 0x0000, I_T0, I_T1, I_T2, OC_SUB)); + assert(T0==-6); + + T1=4; + T2=4; + test_execute(create_rtype_hex(FC_SUB, 0x0000, I_T0, I_T1, I_T2, OC_SUB)); + assert(T0==0); } /* SW */ @@ -143,13 +172,13 @@ void execute_test(void (*test)(void)) { /* executes all tests */ int main (int argc, const char * argv[]) { - execute_test(&test_sw); execute_test(&test_add); execute_test(&test_addi); - execute_test(&test_jal); + execute_test(&test_jal); execute_test(&test_lui); - execute_test(&test_lw); - execute_test(&test_ori); + execute_test(&test_lw); + execute_test(&test_sw); execute_test(&test_sub); + execute_test(&test_ori); return 0; }