p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1...

12
255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria: 11111111.001 2. Scorrere la virgola: 11111111.001 1.1111111001 p =7 3. Bit di segno: Numero positivo 0. 4. Esponente: E = bias + p = 127 10 +7 10 = 134 10 E = 10000110 2 5. Mantissa: 1111111001 (ottenuta da (2)) s e m 0 10000110 11111110010000000000000 Adesso se risolvono le istruzioni assembly: $s0 0100 0011 0111 1111 0010 0000 0000 0000 $t0 0000 0000 0000 0000 0001 0000 0000 0000 addi $t0, $zero, 0x1000 $t0 1000 0000 0000 0000 0000 0000 0000 0000 sll $t0, $t0, 19 $s0 1100 0011 0111 1111 0010 0000 0000 0000 or $s0, $s0, $t0

Transcript of p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1...

Page 1: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

255 1 0.125 0127 1 0.25 063 1 0.5 131 115 17 13 1

1

1. Rappresentazione binaria: 11111111.001

2. Scorrere la virgola:

11111111.001→ 1.1111111001

⇓p = 7

3. Bit di segno: Numero positivo → 0.

4. Esponente:

E = bias + p

= 12710 + 710

= 13410

⇓E = 100001102

5. Mantissa: 1111111001 (ottenuta da (2))

s e m0 10000110 11111110010000000000000

Adesso se risolvono le istruzioni assembly:

$s0 → 0100 0011 0111 1111 0010 0000 0000 0000$t0 → 0000 0000 0000 0000 0001 0000 0000 0000 addi $t0, $zero, 0x1000

$t0 → 1000 0000 0000 0000 0000 0000 0000 0000 sll $t0, $t0, 19

$s0 → 1100 0011 0111 1111 0010 0000 0000 0000 or $s0, $s0, $t0

Page 2: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Finalmente, si trova il numero decimale corrispondente al contenuto del registro $s0

1. Bit di segno: 1→ Numero negativo.

2. Esponente: 10000110

100001102 = 1× 21 + 1× 22 + 1× 27

= 2 + 4 + 128

= 134

⇓E = 134− 127

= 7

3. Mantissa: 1111111001

1.1111111001→7 11111111.001

⇓11111111.0012 = 1× 20 + 1× 21 + 1× 22 + 1× 23 + 1× 24 + 1× 25 + 1× 26 + 1× 27 + 1× 2−3

= 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 0.125

= 255.125

Risposta: Lo stesso numero di prima, ma con segno negativo: −255.12510 → Opzione # 1.

Page 3: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

126 0 0.25 063 1 0.5 131 115 17 13 1

1

1. Rappresentazione binaria: 1111110.01

2. Scorrere la virgola:

1111110.01→ 1.11111001

⇓p = 6

3. Bit di segno: Numero positivo → 0.

4. Esponente:

E = bias + p

= 12710 + 610

= 13310

⇓E = 100001012

5. Mantissa: 11111001 (ottenuta da (2))

s e m0 10000101 11111001000000000000000

Adesso se risolvono le istruzioni assembly:

$s0 → 0100 0010 1111 1100 1000 0000 0000 0000$t0 → 0000 0000 1111 1111 0100 0010 0000 0000 li $t0, 0xFF4200

$t0 → 1111 1111 0100 0010 0000 0000 0000 0000 sll $t0, $t0, 8

$s0 → 0100 0010 0100 0000 0000 0000 0000 0000 and $s0, $s0, $t0

Page 4: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Finalmente, si trova il numero decimale corrispondente al contenuto del registro $s0

1. Bit di segno: 0→ Numero positivo.

2. Esponente: 10000100

100001002 = 1× 22 + 1× 27

= 4 + 128

= 132

⇓E = 132− 127

= 5

3. Mantissa: 1000000

1.1000000→5 110000.00

⇓110000.002 = 1× 24 + 1× 25

= 16 + 32

= 48

Risposta: 4810 → Opzione # 1.

Page 5: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

$s0 → 1100 0110 0000 0000 1111 0111 0011 1100$t0 → 0000 0011 0001 1000 0000 0011 1101 1100 srl $t0, $s0, 6

$s0 → 0000 0010 0000 0000 0000 0011 0001 1100 and $s0, $s0, $t0

Risposta: 000000100000000000000011000111002 → Opzione # 1.

Page 6: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

$s0 → 0000 0000 1100 1100 1111 1111 0011 0000$t0 → 0000 0000 0000 1100 1100 1111 1111 0011 srl $t0, $s0, 4

$s0 → 0011 0011 1111 1100 1100 0000 0000 0000 sll $s0, $s0, 10

$s0 → 0000 0000 0000 1100 1100 0000 0000 0000 and $s0, $s0, $t0

Risposta: 000000000000110011000000000000002 → Opzione # 1.

Page 7: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

$s0 → 0000 0000 0000 0000 0000 0000 0000 0000$t0 → 0001 0000 1111 1100 0110 0111 0011 1010$t1 → 0010 0010 0100 0101 1110 1000 1101 0000

0x559D → 0000 0000 0000 0000 0101 0101 1001 1101$s0 → 1100 0110 0111 0011 1010 0000 0000 0000 sll $s0, $t0, 12

$s0 → 1110 0110 0111 0111 1110 1000 1101 0000 or $s0, $s0, $t1

$t2 → 1111 0111 0111 0100 0101 0000 0000 1010 add $t2, $s0, $t0

$s0 → 0010 0010 0100 0110 0011 1110 0110 1101 addi $s0, $t1, 0x559D

$t2 → 0010 0010 0100 0100 0001 0000 0000 1000 and $t2, $t2, $s0

Risposta: 001000100100010000010000000010002 → Opzione # 1.

Page 8: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Risposta:

1 .data # Variable section

2 x: .space 48 # Declare 48 bytes of storage for an array

3 # of 12 integers

4 .text # Program section

5 main: la $t0, x # Load the base address of the array

6 li $t1, 25 # Set the initial value of b (b = 25)

7 li $t2, 10 # Set the initial value of c (c = 10)

8 li $t3, 40 # Set the initial value of x[11] (x[11] = 40)

9 sw $t3, 44($t0) # Store the eleventh element in x (x[11] = 40)

10 lw $t4, 44($t0) # Load the eleventh element of x (t4 = x[11])

11 addi $t5, $t1, 100 # First instruction (a = b + 100)

12 add $t6, $t4, $t2 # Second instruction (x[11] + c)

13 sw $t6, 40($t0) # Second instruction (x[10] = x[11] + c)

14 li $v0, 10 # End the program

15 syscall

Questa soluzione e stata sviluppata usando il simulatore QtSpim1, quindi alcune istruzionisono state usate per garantire il funzionamento del programa nel simulatore. In particolare, leistruzioni dalle 11 alle 13 implementano il codice indicato nella domanda.

1https://sourceforge.net/projects/spimsimulator/files/

Page 9: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Risposta:

1 main: li $s0, 5 # Assign the value to the "variable"

2 li $s1, 2 # Assign the value to the "variable"

3 slt $t0, $s1, $s0 # If $s1 < $s0, set $t0 = 1

4 beq $t0, $zero, else # If $s0 >= $s1, branch to the tag else

5 add $s0, $s0, $s1 # Otherwise, execute the sum

6 j done # Branch to the end

7 else: sub $s0, $s1, $s0 # Execute the subtraction

8 done: li $v0, 10 # End the program

9 syscall

Questa soluzione e stata sviluppata usando il simulatore QtSpim2, quindi alcune istruzionisono state usate per garantire il funzionamento del programa nel simulatore. In particolare, leistruzioni dalle 3 alle 7 implementano il codice indicato nella domanda.

2https://sourceforge.net/projects/spimsimulator/files/

Page 10: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Risposta:

1 main: li $s0, 2 # Assign the value to the "variable"

2 li $s1, 5 # Assign the value to the "variable"

3 slt $t0, $s0, $s1 # If $s0 < $s1, set $t0 = 1

4 bne $t0, $zero, else # If $s0 < $s1, branch to the tag else

5 addi $s0, $s0, 1 # Otherwise, execute the sum

6 j done # Branch to the end

7 else: addi $s1, $s1, -1 # Execute the subtraction

8 done: li $v0, 10 # End the program

9 syscall

Questa soluzione e stata sviluppata usando il simulatore QtSpim3, quindi alcune istruzionisono state usate per garantire il funzionamento del programa nel simulatore. In particolare, leistruzioni dalle 3 alle 7 implementano il codice indicato nella domanda.

3https://sourceforge.net/projects/spimsimulator/files/

Page 11: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Risposta:

1 main: li $a0, 5 # Set the number of iterations

2 li $a1, 4 # Set the base of the power

3 jal pot # Jump to the function

4 li $v0, 10 # End the program

5 syscall

6 pot: li $v1, 1 # Set the initial value of the power (ret = 1)

7 for: beq $a0, $zero, exit # If the counter is zero, branch to the tag exit

8 mul $v1, $v1, $a1 # Execute the power (ret = ret * b)

8 addi $a0, $a0, -1 # Decrease the counter

10 j for # Perform another iteration

11 exit: jr $ra # Return to the main function

Questa soluzione e stata sviluppata usando il simulatore QtSpim4, quindi alcune istruzionisono state usate per garantire il funzionamento del programa nel simulatore.

4https://sourceforge.net/projects/spimsimulator/files/

Page 12: p bias p - DISI, University of Trentodisi.unitn.it/~palopoli/courses/Calc/AssemblyMIPSSoluzi...255 1 0.125 0 127 1 0.25 0 63 1 0.5 1 31 1 15 1 7 1 3 1 1 1. Rappresentazione binaria:

Risposta:

1 main: li $a0, 6 # Set the number of iterations

2 li $a1, 3 # Set the base of the power

3 jal pot # Jump to the function

4 li $v0, 10 # End the program

5 syscall

6 pot: addi $sp, $sp, -12 # Reserve space in the stack for three objects

7 sw $ra, 8($sp) # Store the return address

8 sw $a0, 4($sp) # Store the first parameter (iteration)

9 sw $a1, 0($sp) # Store the second parameter (base)

10 slti $t0, $a0, 1 # If the counter is smaller than 1, set t0 = 1

11 beq $t0, $zero, else # Otherwise, branch to the tag else

12 li $v1, 1 # End of the procedure, set v1 = 1

13 j exit # Jump to the clean-up code

14 else: addi $a0, $a0, -1 # Decrease the counter

15 jal pot # Recursively call the function

16 mul $v1, $a1, $v1 # Perform the multiplication

17 exit: lw $a1, 0($sp) # Restore the second parameter (base)

18 lw $a0, 4($sp) # Restore the first parameter (iteration)

19 lw $ra, 8($sp) # Restore the return address

20 addi $sp, $sp, 12 # Clean-up the stack

21 jr $ra # Return to the main function

Questa soluzione e stata sviluppata usando il simulatore QtSpim5, quindi alcune istruzionisono state usate per garantire il funzionamento del programa nel simulatore.

5https://sourceforge.net/projects/spimsimulator/files/