CS 341 - Fall 2017
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CS 341 - Fall 2017
In-Class, Open Book Examination II
1. (30 points) Short Questions:
a. (3 points) Why 2 instructions are needed to load the timer of the PIT?
f. (3 points) In Arduino lab #5, why is it recommended to hook up the circuit components before connecting the USB cable?
b. (6 points) What are the 2 approaches to simplify a
Boolean equation derived from a truth table
i)_________________________ and
ii)_________________________
g. (3 points)What is the difference between combinational logic and sequential logic?
c. (6 points) Name 2 functions of the Programmable Interrupt Controller (PIC)?
i) ___________________________________
______________________________________
______________________________________
ii) ___________________________________
h. (3 points) Why are there 2 separate L1 cache memories inside a modern CPU chip?
_____________________________________
______________________________________
d. (3 points) Given a certain truth table, there is an unique implementation of it using logic gates. TRUE: _____ FALSE: ______
e. (3 points) To select data coming from the 32-bit data bus of either an I/O device or a memory device, how many selector lines (S0, S1, S2,..) are needed?
_____________________
2. (20 points) Combinational Logic:
Draw the logic diagram of a 2-input exclusive or (XOR) device using AND, NOT and OR gates.
4. (30 points) I/O Programming:
Write an assembly language program xmit to output a buffer of data from the serial port using polling. The program will exit when it reaches the terminating character of the buffer. The C prototype for the xmit function is:
void xmit(int comport, char * buf)
where comport is the serial port address and buf is the address of the data buffer
3. (20 points) Timer function:
In mp4, the slowest interrupt rate that we can program
the PIT is 18 hz. Write a set_timer_count() function
with the correct count value that will generate
interrupts at 36hz.
Answers:
1. Short Questions
a. The 16-bit counter is made up of two 8-bit registers. You have to load it one at a time.
b. i) Factoring the Boolean equation ii)Karnaugh map
c. i) Mask off interrupt lines
ii) Provide the Interrupt vector (IV) to the CPU and the processor uses the IV as an index to the Interrupt Descriptor Table to access the ISR for the device.
d. FALSE because there are many different implementations
e. 1 selector line to select one of the two inputs(each input is 32 bits)
f. We don’t want to damage the electronic components due to faulty wiring.
Output of sequential logic is a function of its input and previous state.
h. Instructions and data are stored in different address spaces. Use one L1 cache for instructions and one L1 cache for data.
2. Combinational Logic
Truth Table for XOR:
A B Output
0 0 0
0 1 1
1 0 1
1 1 0
Boolean equation using sum of products: Output= A#B + AB#
3. Programming
To calculate the interrupt rate when the counter is loaded with 1, use the following :
There are 65536 downcounts in 1/18 hz= 55ms 1 downcount will take (55x10-3)/65535 sec The interrupt rate is
1/((55x10-3)/65535) = 1.192 x 106hz
/* Loading a 0 (or 65536) in the counter
results in 18 Hz interrupt rate .
Loading a 32768 in the counter
will interrupt at 36hz
*/
void set_timer_count(void)
{
int count = 32768;
outpt(TIMER_CNTRL_PORT,
TIMER0 |TIMER_SET_ALL |
TIMER_MODE_RATEGEN);
/* set LSB here */ outpt(TIMER0_COUNT_PORT,count&0xff); /* and MSB here */ outpt(TIMER0_COUNT_PORT,count>>8); smalldelay();
/* give the timer a moment to init*/ }
4. I/O Programming
# xmit.s: transmit characters until
# terminating character
# UART register and bit definitions
# needed (from serial.h)
UART_TX = 0
UART_LSR = 5
UART_LSR_THRE = 0x20
UART_LSR_DR = 0x01
.globl _xmit
.text
_xmit:
movl 8(%esp), %ecx # get the
# buffer addr
movl 4(%esp), %edx # get the com
# port address
loop0:
addl $UART_LSR, %edx # point to
#line status reg
loop1:
inb (%dx), %al # read register
andb $UART_LSR_THRE, %al
# if THRE =0, loop
jz loop1
subl $UART_LSR, %edx
# point to transmit data port
movb (%ecx), %al# get the char
outb %al, (%dx) #Output to TX reg
cmpb $0, %al # if char ==
# terminating char,
jz end # break, we are done
incl %ecx #increment pointer
jmp loop0 # and keep looping
end:
ret
.end
2022-05-16