Search
Task assignment and description: EN: 03_seminar_assignment-en.pdf CZ: 03_cviceni_zadani.pdf
The second part of the seminar - Explanation of basic instructions of selected CPU and their use
Description of individual instructions:
if (i ==j) f = g + h; f = f – i;
// s0=f, s1=g, s2=h, s3=i, s4=j bne s3, s4, L1 // If i!=j, go to label L1 add s0, s1, s2 // if block: f=g+h L1: sub s0, s0, s3 // f = f-i
if (i ==j) f = g + h; else f = f – i;
// s0=f, s1=g, s2=h, s3=i, s4=j bne s3, s4, else // If i!=j, go to else label add s0, s1, s2 // if block: f=g+h j L2 // jump behind the else block to L2 else: sub s0, s0, s3 // else block: f = f-i L2:
int pow = 1; int x = 0; while(pow != 128) { pow = pow*2; x = x + 1; }
// s0=pow, s1=x addi s0, $0, 1 // pow = 1 addi s1, $0, 0 // x = 0 addi t0, $0, 128 // t0 = 128 pro porovnávání while: beq s0, t0, done // compare pow with value 128 in t0 (always have to compare two registers) sll s0, s0, 1 // pow = pow*2 addi s1, s1, 1 // x = x+1 j while done:
int sum = 0; for(int i=0; i!=10; i++) { sum = sum + i; }
// Is equivalent to following while cycle:: int sum = 0; int i = 0; while(i!=10){ sum = sum + i; i++; }
// // Just as an example... int a, *pa=0x80020040; int b, *pb=0x80020044; int c, *pc=0x00001234; a = *pa; b = *pb; c = *pc;
// s0=pa (Base address), s1=a, s2=b, s3=c lui s0, 0x8002 // pa = 0x80020000; lw s1, 0x40(s0) // a = *pa; lw s2, 0x44(s0) // b = *pb; addi s0, $0, 0x1234 // pc = 0x00001234; lw s3, 0x0(s0) // c = *pc;