alu
DESCRIPTION
que es, ejemplos.TRANSCRIPT
![Page 1: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/1.jpg)
ALUUnidad aritmético-lógica
![Page 2: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/2.jpg)
Universidad de Sonora Arquitectura de Computadoras 2
Definición La ALU (unidad aritmético-lógica) es el
dispositivo que se encarga de realizar:a) Operaciones aritméticas (suma, resta, etc.).b) Operaciones lógicas (and, or, xor, etc.).
![Page 3: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/3.jpg)
Universidad de Sonora Arquitectura de Computadoras 3
Circuitos combinatoriosSu salida depende exclusivamente de sus
entradas.
![Page 4: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/4.jpg)
Universidad de Sonora Arquitectura de Computadoras 4
Compuertas básicas
![Page 5: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/5.jpg)
Universidad de Sonora Arquitectura de Computadoras 5
Compuertas básicasAND
A B A · B
0 0 0
0 1 0
1 0 0
1 1 1
OR
A B A + B
0 0 0
0 1 1
1 0 1
1 1 1
NOT
A Ā
0 1
1 0
![Page 6: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/6.jpg)
Universidad de Sonora Arquitectura de Computadoras 6
Otras compuertasXOR (or exclusiv0).EQV (equivalence).NAND (not AND).NOR (not OR).
![Page 7: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/7.jpg)
Universidad de Sonora Arquitectura de Computadoras 7
MultiplexorEl multiplexor (mux) tiene 2n entradas de
datos, n bits de selección y una salida.Los bits de selección se usan para decidir
cuál entrada pasa a la salida.Mux 2 a 1
![Page 8: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/8.jpg)
Universidad de Sonora Arquitectura de Computadoras 8
MultiplexorMux 4 a 1
Mux 8 a 1
![Page 9: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/9.jpg)
Universidad de Sonora Arquitectura de Computadoras 9
Sumador completoSumador completo (full adder) de 1 bit:
Entradas: dos números de 1 bit y un bit de carry de entrada.
Salidas: la suma de 1 bit y un bit de carry de salida.
![Page 10: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/10.jpg)
Universidad de Sonora Arquitectura de Computadoras 10
Sumador completo
![Page 11: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/11.jpg)
Universidad de Sonora Arquitectura de Computadoras 11
Sumador completoSuma = a b CarryInCarryOut = (a · CarryIn) + (b · CarryIn) + (a ·
b) = (a + b) · CarryIn + (a · b)
![Page 12: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/12.jpg)
Universidad de Sonora Arquitectura de Computadoras 12
Sumador completoDiagrama a bloque.
![Page 13: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/13.jpg)
Universidad de Sonora Arquitectura de Computadoras 13
ALU de 1 bitDos operaciones: AND y OR.Un bit para seleccionar la operación.
Operación Salida
0 a · b
1 a + b
![Page 14: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/14.jpg)
Universidad de Sonora Arquitectura de Computadoras 14
Agregando operacionesEl siguiente paso es agregar la suma.Se agrega un sumador completo al diseño
anterior.
![Page 15: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/15.jpg)
Universidad de Sonora Arquitectura de Computadoras 15
ALU de 1 bit3 operaciones: AND, OR y suma.2 bits para seleccionar la operación.
Operación Resultado CarryOut
00 a · b X
01 a + b X
10 a b CarryIn
(a + b) · CarryIn + (a · b)
11 X X
![Page 16: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/16.jpg)
Universidad de Sonora Arquitectura de Computadoras 16
Agregando operacionesAgregar la resta a – b.a – b a + b si b está en complemento a 2.El complemento a dos de b se encuentra
sumando 1 al complemento a uno de b.El complemento a uno de b se encuentra
negando a b.a – b = a + (–b) = a + (¬b + 1) = a + ¬b + 1El 1 de la suma viene en CarryIn.
![Page 17: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/17.jpg)
Universidad de Sonora Arquitectura de Computadoras 17
ALU de 1 bit4 operaciones: AND, OR, suma y resta.2 bits para seleccionar la operación.Un bit extra para diferenciar entre la suma y
la resta.En la resta, CarryIn es 1.
![Page 18: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/18.jpg)
Universidad de Sonora Arquitectura de Computadoras 18
ALU de 1 bit
![Page 19: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/19.jpg)
Universidad de Sonora Arquitectura de Computadoras 19
ALU de 1 bitOperación Binvert CarryIn Resultado CarryOut
00 X X a · b X
01 0 X a + b X
10 0 X a b CarryIn (a + b) · CarryIn + (a · b)
10 1 0 X X
10 1 1 a b a + ¬b
11 X X X X
![Page 20: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/20.jpg)
Universidad de Sonora Arquitectura de Computadoras 20
Agregando operacionesAgregar la operación NOR:
¬(a + b)Ley de DeMorgan:
¬(a + b) = ¬a · ¬bLa ALU ya puede calcular a · b y ¬b.Hace falta poder calcular ¬a.
![Page 21: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/21.jpg)
Universidad de Sonora Arquitectura de Computadoras 21
ALU de 1 bit5 operaciones: AND, OR, NOR, suma y resta.2 bits para seleccionar la operación.Binvert diferencia entre la suma y la resta.En la resta, CarryIn es 1.Ainvert y Binvert diferencian entre AND y
NOR.
![Page 22: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/22.jpg)
Universidad de Sonora Arquitectura de Computadoras 22
ALU de 1 bit
![Page 23: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/23.jpg)
Universidad de Sonora Arquitectura de Computadoras 23
ALU de 1 bitOperación Ainvert Binvert CarryIn Resultado CarryOut
00 0 0 X a · b X
00 1 1 X ¬a · ¬b X
01 0 0 X a + b X
10 0 0 X a b CarryIn
(a + b) · CarryIn + (a · b)
10 0 1 0 X X
10 0 1 1 a b a + ¬b
11 X X X X X
![Page 24: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/24.jpg)
Universidad de Sonora Arquitectura de Computadoras 24
Agregando operacionesVariando Ainvert y Binvert permite generar:
8 operaciones lógicas.5 operaciones aritméticas.
![Page 25: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/25.jpg)
Universidad de Sonora Arquitectura de Computadoras 25
Agregando operacionesOperación Ainvert Binvert CarryIn Resultado CarryOut
00 0 0 X a · b X
00 0 1 X a · ¬b X
00 1 0 X ¬a · b X
00 1 1 X ¬a · ¬b X
01 0 0 X a + b X
01 0 1 X a + ¬b X
01 1 0 X ¬a + b X
01 1 1 X ¬a + ¬b X
![Page 26: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/26.jpg)
Universidad de Sonora Arquitectura de Computadoras 26
Agregando operacionesOperación Ainvert Binvert CarryIn Función
aritmética
10 0 0 0 a + b
10 0 0 1 a + b + 1
10 0 1 1 a - b
10 1 0 1 b - a
10 1 1 1 -a - b
![Page 27: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/27.jpg)
Universidad de Sonora Arquitectura de Computadoras 27
ALU de 32 bits¿Cómo se genera una ALU de 32 bits?Con 32 ALUs de 1 bit.CarryOut de la ALUi se conecta a CarryIn de
la ALUi+1.
En la resta CarryIn ALU0 se conecta a 1.
![Page 28: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/28.jpg)
Universidad de Sonora Arquitectura de Computadoras 28
ALU de 32 bits
![Page 29: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/29.jpg)
Universidad de Sonora Arquitectura de Computadoras 29
ALU para MIPSEl diseño de la ALU está incompleto.La mayoría de las instrucciones de MIPS
pueden ser realizadas con las operaciones AND, OR, suma y resta.
Se necesita soportar la instrucción slt (set on less than).
slt $x, $y, $z guarda 1 en $x si $y < $z y 0 en otro caso.
![Page 30: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/30.jpg)
Universidad de Sonora Arquitectura de Computadoras 30
Soportando sltslt $x, $y, $z pone a ceros los bits 1 a 31 de
$x.El bit 0 de $x tiene el resultado de la
comparación de $y y $z.
31 30 1 0
0 0 …
…
0 $y < $z$x
![Page 31: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/31.jpg)
Universidad de Sonora Arquitectura de Computadoras 31
Soportando sltSe calcula t = $y - $z.Si t es negativo $y < $z.Si t es positivo o cero $y $z.En MIPS los números negativos tienen 1 en el
bit 31.El bit 31 de t tiene el resultado de la
comparación.
![Page 32: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/32.jpg)
Universidad de Sonora Arquitectura de Computadoras 32
Soportando sltPara hacer una ALU de 32 bits se consideran
dos tipos de ALU distintos.Una para los bits del 0 al 30.
Parecida al diseño anterior, tiene una entrada extra llamada Less.
Otra para el bit 31.Además de la entrada Less, tiene una salida Set con el signo de la resta y un detector de overflow.
![Page 33: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/33.jpg)
Universidad de Sonora Arquitectura de Computadoras 33
ALU para los bits 0 al 30
![Page 34: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/34.jpg)
Universidad de Sonora Arquitectura de Computadoras 34
ALU para el bit 31
![Page 35: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/35.jpg)
Universidad de Sonora Arquitectura de Computadoras 35
ALU de 32 bitsSe conectan las 32 ALUs.CarryOut de la ALUi se conecta a CarryIn de
la ALUi+1.
Las entradas Less de la ALU1 a la ALU31 se ponen a 0.
La entrada Less de la ALU0 se conecta a la salida Set de la ALU31.
En la resta CarryIn de la ALU0 se conecta a 1.
![Page 36: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/36.jpg)
Universidad de Sonora Arquitectura de Computadoras 36
ALU de 32 bits
![Page 37: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/37.jpg)
Universidad de Sonora Arquitectura de Computadoras 37
ALU para MIPSFalta soportar los brincos condicionales.beq $x, $y, L – brinca a L si $x = $y.bne $x, $y, L – brinca a L si $x $y.Se calcula t = $x - $y.Si t es cero, $x = $y.Si t no es cero, $x $y.
![Page 38: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/38.jpg)
Universidad de Sonora Arquitectura de Computadoras 38
ALU para MIPSSe agrega una salida Zero que detecte
cuando todos los bits de resultado sean cero.Zero = ¬(Result31 + Result30 + … + Result1 +
Result0)
Se combinan la entradas Binvert y CarryIn de la ALU0 con el nombre Bnegate.Binvert = CarryIn = 1 cuando hay que restar.Binvert = CarryIn = 0 en la suma y
operaciones lógicas.
![Page 39: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/39.jpg)
Universidad de Sonora Arquitectura de Computadoras 39
ALU para MIPS
![Page 40: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/40.jpg)
Universidad de Sonora Arquitectura de Computadoras 40
Diagrama y tabla de la ALULíneas de
controlFunción
C3 C2 C1 C0
0 0 0 0 AND
0 0 0 1 OR
0 0 1 0 suma
0 1 1 0 resta
0 1 1 1 set on less than
1 1 0 0 NORC3 = Ainvert
C2 = Bnegate
![Page 41: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/41.jpg)
Universidad de Sonora Arquitectura de Computadoras 41
OverflowEl overflow ocurre cuando el resultado de
una operación no se puede representar en el hardware.
Con 4 bits, el rango de enteros con signo, usando complemento a dos para los negativos, es de -8 a +7.La suma 5 + 6 genera overflow.La resta -5 – 6 genera overflow.
![Page 42: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/42.jpg)
Universidad de Sonora Arquitectura de Computadoras 42
OverflowSumando 5 + 6 con 4 bits:
0101 (+5)
+ 0110 (+6)------------- 1011 (-5) ⇦ ¡error!
Restando -5 – 6 con 4 bits: 1011 (-5)
+ 1010 (-6) ------------ 0101 (+5) ⇦ ¡error!
![Page 43: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/43.jpg)
Universidad de Sonora Arquitectura de Computadoras 43
Detectando overflowEl overflow ocurre en la suma cuando:
Al sumar dos positivos el resultado es negativo.Al sumar dos negativos el resultado es positivo.
El overflow ocurre en la resta cuando:Al restar un negativo de un positivo el
resultado es negativo.Al restar un positivo de un negativo el
resultado es positivo.
![Page 44: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/44.jpg)
Universidad de Sonora Arquitectura de Computadoras 44
Detectando overflow
Operación A B Resultado indicando overflow
A + B 0 0 < 0
A + B < 0 < 0 0
A – B 0 < 0 < 0
A – B < 0 0 0
![Page 45: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/45.jpg)
Universidad de Sonora Arquitectura de Computadoras 45
Detectando overflowMétodo obvio: revisar los signos de los
operandos y del resultado.Si los operandos son positivos, revisar que el
resultado sea positivo.Los demás casos se hacen igual.
Método no (tan) obvio: si el carry de entrada es distinto al carry de salida en el bit mas significativo, se generó overflow.La demostración se queda de tarea.
![Page 46: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/46.jpg)
Universidad de Sonora Arquitectura de Computadoras 46
Overflow en MIPSLas operaciones con enteros con signo deben
reconocer el overflow.Con 4 bits, el rango es de -8 a +7.5 + 6 genera overflow.
Las operaciones con enteros sin signo ignoran el overflow.Con 4 bits, el rango es de 0 a 15.5 + 6 = 11.14 + 7 = 5 (se ignora el último carry).
![Page 47: ALU](https://reader030.vdocuments.co/reader030/viewer/2022032523/55cf9230550346f57b947945/html5/thumbnails/47.jpg)
Universidad de Sonora Arquitectura de Computadoras 47
Overflow en MIPS En MIPS hay dos clases de instrucciones
aritméticas:1. La suma (add), suma inmediata (addi) y
resta (sub), reconocen el overflow.2. La suma sin signo (addu), suma inmediata
sin signo (addiu) y resta sin signo (subu), ignoran el overflow.