uc3m_cs

Materials used for Computer Structure

Exercise 1

(statement) It is desired to develop a controller for a traffic light. The controller has a 32-bit CPU, separate I/O map and RISC-V 32 instruction set. Two I/O modules are connected to this CPU. The first is a timer and the second is the I/O module that controls the operation of the traffic light.

The chronometer module has the following three registers:

The I/O module that controls the traffic lights has four registers:

Se pide:
  1. Write the assembler program that controls the operation of this traffic light. The traffic light always starts its operation on red.
  2. What inefficiency is identified in the above program and how could it be resolved?

(solution)

  1. RED:
    	li 	t0, 100
    	OUT 	t0, 1012
    	IN 	t0, 1016
    	OUT 	t0, 1000
    	IN 	t0, 1
    	OUT 	t0, 1004
    WAIT4RED:
    	IN 	t0, 1008
    	li 	t1, 1
    	beq 	t0, t1, WAIT4RED
    YELLOW:
    	li 	t0, 010
    	OUT 	t0, 1012
    	IN 	t0, 1020
    	OUT 	t0, 1000
    	IN 	t0, 1
    	OUT 	t0, 1004
    WAIT4YELLOW:
    	IN 	t0, 1008
    	li 	t1, 1
    	beq 	t0, t1, ESPERA_AMARILO
    GREEN:
    	li 	t0, 010
    	OUT 	t0, 1012
    	IN 	t0, 1024
    	OUT 	t0, 1000
    	IN 	t0, 1
    	OUT 	t0, 1004
    WAIT4GREEN:
    	IN 	t0, 1008
    	li 	t1, 1
    	beq 	t0, t1, WAIT4GREEN
    	beq 	x0, x0, RED
    
    </li>
    
    
  2. The main cause of inefficiency is CPU consumption during counter timeout. The solution would be the use of I/O through interrupts.
  3. </ol> </html>