Quiz 2
ECE 484/584 -- Fall 2003
Chapters 1 – 3.6
Name: ___________________________ Student Number: ______________________
1) Implement the following C code segment in MIPS assembly language using a test for equality. Assume the compiler associates register $s0 with variable f, $s1 with variable g, $s2 with variable h, $s3 with variable i, and $s4 with variable j. (6 points) if (i == j)
f = g + h; else
f = g – h; beq $s3, $s4, true sub $s0, $s1, $s2
J exit true: add $s0, $s1, $s2 exit:
2) Implement the following pseudo code in MIPS assembly language. Assume the compiler associates register $s1 with variable x, register $s2 with the base address of array a, and $s3 with variable y. (10 points) if (0 <= a[1] <= y)
x = x + y; else
x = x -y; lw slt bne slt bne add j
$t0, 4($s2)
$t1, $t0, $zero
$t1, $zero, false
$t1, $s3, $t0
$t1, $zero, false
$s1, $s1, $s3 exit false: sub $s1, $s1, $s3 exit:
3) Given the following design “issues” for the MIPS architecture and assembly language, state the design principle of which each is an example. (2 points each) a) The introduction of the I-format for data transfer instructions.
Good designs require good compromises. b) Limiting the size of the register set.
Smaller is faster. c) Requiring that all MIPS assembly instructions be 32 bits in length.
Simplicity favors regularity.
4) List three (3) advantages to using high-level programming languages over the use of lower-level programming languages. (6 points)
1.
Higher level of abstraction leads to more efficient programming
2.
Produces portable code
3.
High-level languages can be tailored for particular use
5) List the generations of computers by name and indicate the technology upon which each is based. (4 points)
Generation 1 – vacuum tubes
Generation 2 – transistors
Generation 3 – integrated circuit
Generation 4 – LSI & VLSI
6) Implement the following C code in MIPS assembly and MIPS machine code assuming that register $s1 contains the base address of array a in memory. (8 points) a[11] = a[10] + a [12]; lw lw add sw
$t0, 40($s1)
$t1, 48($s1)
$t0, $t0, $t1
$t0, 44($s1) op rs rt address
100 011 10001 01000 0000 0000 0010 1000 op rs rt address
100 011 10001 01001 0000 0000 0011 0000 op rs rt rd shamt funct
000 000 01000 01001 01000 00000 100 000 op rs rt address
101 011 10001 01000 0000 0000 0010 1100