Skip to content

Commit

Permalink
Merge remote branch 'origin/HEAD'
Browse files Browse the repository at this point in the history
  • Loading branch information
matsimon committed Apr 7, 2011
2 parents 24c3016 + 4a7a717 commit dc683c2
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 57 deletions.
68 changes: 48 additions & 20 deletions serie2/Theorieteil.txt
Expand Up @@ -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 */



Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
31 changes: 18 additions & 13 deletions serie2/mips.c
@@ -1,5 +1,4 @@
/* TODO: Task (b) Please fill in the following lines, then remove this line.
*
/*
* author(s): Thomas Rickenbach <trb@students.unibe.ch>
* Mathieu Simon <mathieu.simon@students.unibe.ch>
* modified: 2011-04-04
Expand All @@ -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];
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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));
}

7 changes: 3 additions & 4 deletions serie2/muster/mips.c
Expand Up @@ -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) {
Expand Down
Binary file removed serie2/muster/mips.o
Binary file not shown.
18 changes: 9 additions & 9 deletions serie2/muster/test.c
Expand Up @@ -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);

}

Expand Down
Binary file removed serie2/muster/test.o
Binary file not shown.
File renamed without changes.
1 change: 1 addition & 0 deletions serie2/skeleton/test.c
Expand Up @@ -89,6 +89,7 @@ void test_jal() {
pc += 4;
operations[instruction->i.opcode].operation(instruction);
assert(RA == pcSaved + 4);
printf(pc);
assert(pc == 0xA0000004);
}

Expand Down
51 changes: 40 additions & 11 deletions serie2/test.c
@@ -1,5 +1,4 @@
/* TODO: Task (b) Please fill in the following lines, then remove this line.
*
/*
* author(s): Thomas Rickenbach <trb@students.unibe.ch>
* Mathieu Simon <mathieu.simon@students.unibe.ch>
* modified: 2011-04-04
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
}

0 comments on commit dc683c2

Please sign in to comment.