2008-06-03 Exam Solutions Datorarkitektur DA7009, DD221V, DD2377 page 1

Problem 1.
Description          |  Hex  |   m   |   E   |  Value
------------------------------------------------------------
-0                   |  800  |   0   |  -30  |  -0.0
------------------------------------------------------------
Smallest value > 1   |  3E1  | 33/32 |    0  |  33/32
------------------------------------------------------------
Largest Denormalized |  01F  | 31/32 |  -30  |  31 * 2^(-35)
------------------------------------------------------------
- infinity           |  FE0  |   0   |   32  |  - infinity
------------------------------------------------------------
                     |  AA0  |   1   |  -10  |  -1 * 2^(-10)
------------------------------------------------------------

Problem 2.
int array1[M][N] means that array1[i][j] = array1[i*N+j] = array1+4*(i*N+j)
int array2[N][M] means that array2[j][i] = array2[j*M+i] = array2+4*(j*M+i)

        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %edx		# i
        movl    %edx, %eax		# i
        sall    %eax  			# 2*i
        addl    %edx, %eax		# 3*i
        sall    $2, %eax		# 12*i
        addl    %edx, %eax		# 13*i
        movl    %eax, %ecx		# 13*i
        addl    12(%ebp), %ecx		# j+13*i
        movl    12(%ebp), %edx		# j
        movl    %edx, %eax		# j
        sall    $3, %eax		# 8*j
        addl    %edx, %eax		# 9*j
        addl    8(%ebp), %eax		# i+9*j
        movl    array2(,%eax,4), %eax	# array2+4*(i+9*j)  dvs M=9
        movl    %eax, array1(,%ecx,4)	# array1+4*(j+13*i) dvs N=13
        leave
        ret

Problem 3.

OldSensorData
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|code |  raw   |XXXXXXXX|   start   |         data          |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

NewSensorData
  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|code |start|sence|     raw      |XX| ext |XXXXX|        data           |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

newData->code   = 0x0x3ADC
newData->raw[0] = 0x00
newData->raw[2] = 0xEC
newData->raw[4] = 0x50
newData->sense  = 0x0076
2008-06-03 Exam Solutions Datorarkitektur DA7009, DD221V, DD2377 page 1

Problem 4.
looper:			# int looper(int n, int *a) {
  pushl %ebp
  movl %esp,%ebp
  pushl %esi		# save callee-save register
  pushl %ebx		# save callee-save register
  movl 8(%ebp),%ebx	# n
  movl 12(%ebp),%esi	# *a
  xorl %edx,%edx	# edx = 0 i.e. int x = 0;
  xorl %ecx,%ecx	# ecx = 0 i.e. i = 0;
  cmpl %ebx,%edx	# if (n <= 0)
  jge .L25		#   goto .L25
.L27:
  movl (%esi,%ecx,4),%eax	# eax = a[i]
  cmpl %edx,%eax		# if (a[i] > x)
  jle .L28
  movl %eax,%edx		#   x = a[i]
.L28:{\em\scriptsize }
  incl %edx			# x++
  incl %ecx			# i++
  cmpl %ebx,%ecx	   	# if (i < n)
  jl .L27			#   goto .L27
.L25:
  movl %edx,%eax	# return value edx so edx is variable x
  popl %ebx		# restore callee-save register
  popl %esi		# restore callee-save register
  movl %ebp,%esp	# So:  int looper(int n, int *a) {
  popl %ebp		#      	   int i;
  ret  			#	   int x = 0;
  			#	   for(i = 0; i < n; i++) {
			#	   	 if (a[i] > x)
      	 		#		    x = a[i]; }
			#	   x++; }

Problem 5.
xx(int *ap, int *bp)
        pushl   %ebp
        movl    %esp, %ebp
        subl    $4, %esp	# reserve an int var
        movl    12(%ebp), %eax	# bp
        movl    (%eax), %eax	# *bp
        movl    %eax, -4(%ebp)	# b = *bp
        movl    12(%ebp), %ecx	# bp
        movl    12(%ebp), %edx	# bp
        movl    8(%ebp), %eax	# ap
        movl    (%eax), %eax	# *ap
        addl    (%edx), %eax	# *bp + *ap
        movl    %eax, (%ecx)	# *bp = *bp + *ap  i.e. *bp += *ap
        movl    -4(%ebp), %eax	# return b
        leave
        ret			# This is fun5

Problem 6.
A. Yes, -4, Need to pass pointer to it to recursive call
B. No
C. The value of %ebx is saved here, because %ebx is a callee-save register.
D. Nothing is stored here.

Problem 7.
Del 1:
A. Total number of read and write accesses is 4*8*8 + 3*8*8 = 448 
B. Total number of read and write accesses that miss in the cache is
      1*8*8 + 1*8*8 = 128
C. Fraction of all accesses that miss in the cache is 2/7
Del 2:
A. Total number of read and write accesses is 8*8*6
B. Total number of read and write accesses that miss in the cache is 8*4
C. Fraction of all accesses that miss in the cache is 1/12
