Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

EXAMINATION

Semester One Final Examinations, 2016

CSSE2010/CSSE7201 Introduction to Computer Systems

Question 1.

(a)  Consider the decimal number 237. Write down the octal representation of this number. (1 mark)

(b)  Consider the 9-bit binary number 101010011. Write down the decimal value of this

number if the number is considered to have each of the following representations. (1 mark each)

i)    9-bit twos complement

ii)   9-bit unsigned

iii)  9-bit signed magnitude

iv)  9-bit excess-256

(c)  Write down (in hexadecimal) both the IEEE single-precision and double-precision

floating-point representations of –91.75. Show your working.                                      (4 marks)

(d)  Consider the 8 bit twos complement binary numbers 11011011 and 10110110.

i)    What is the result (in 8 bit binary) of adding these two numbers? ( 1 mark)

ii)   What would be the values (0 or 1) of the V (overflow), C (carry), N(negative) and Z

(zero) flags after the addition operation in (i) above?

V: C: N: Z:

Question 2.

(a)  Consider the logic function X = A⨁B. C + (A . C)

i)    Draw a logic circuit which implements this function. (2 marks)

ii)   Complete the following truth table for X.

A

B

C

X

0

0

0

0

0

1

0

1

0

0

1

1

1

0

0

1

0

1

1

1

0

1

1

1

iii)  Write down a sum-of-products expression for X.

X =

(2 marks)

(b)  Consider the logic function Y = A  + B . (C  + B ).

i)    Draw a circuit which implements Y from inputs A, B and C using only two-input

gates.

ii)   Draw a circuit schematic which implements Y using only the IO Board and chips      from the 74 series logic chips used in the learning labs in this course. The inputs A and B should come from IO Board switches, input C should come from an IO Board push-button and the output (Y) should be shown on an IO Board LED. (4 marks)

Question 3.

(a)  Draw the logic diagram for a 3-bit synchronous counter which counts through the

sequence 000 à 100 à 101 à 110 à 011 à 001 à 111 à 000 à … .

Show all

your working. (4 marks)

(b)  Draw a state diagram which implements a sequence detector with three inputs (A,B,C) and two outputs (X,Y). The output X is 1 if and only if A=B=1 for two clock cycles in a row. The output Y is 1 if and only if A=B=C=1 for two clock cycles in a row.          (5 marks)

(c)  Consider a state machine with 2 inputs, 4 outputs and 8 states. What is the minimum number of flip-flops needed to implement this state machine?                                        (1 mark)

Question 4.

Consider the ALU bit slice shown below. [Note that for the output multiplexer on the right     hand side, F2 is the most significant of the select bits, so for example, if F2,F1,F0 =1,0,0 then input 4 of the multiplexer will be selected.]

Right1Shift1Out              Carry1In

Right1Shift1In           Carry1Out

(a)  Consider 16 of these ALU bit slices put together to form a 16-bit ALU (i.e. with 16-bit      data inputs A and B). Complete the following table to show the required control inputs for the ALU to perform the given functions. (Each control input will have value 0 or 1. The    “carry in” control input applies only to the least significant bit, the carry in” input of        other bit slices comes from the carry out” output of its neighbouring bit slice. The right shift in” control input applies only to the most significant bit; the right shift in” input of  other bit slices comes from the right shift out” output of its neighbouring bit slice.) If it   is not possible to generate the given function, make a comment to this effect below the      table. If there is more than one way to generate the given function, just show one way. (1.5 marks each)

Description of Function Output

ENA

ENB

INVB

Carry In

Right

Shift

In

F2

F1

F0

(i) Logical shift left of A

(ii) Logical shift left of B

(iii) Logical shift right of A

(iv) A . B (bitwise)

(b)  Consider a 16-bit binary number stored in AVR registers r15:r14 which the programmer  considers to be a two’s complement value. (r 15 holds the most significant byte, r14 holds the least significant.) Write down a sequence of AVR assembly language instructions       which perform each of the following operations on this quantity. The result should end up in r15:r14. Other registers can be used freely if required.

i)    Division by 2. (1 mark)

ii)   Twos complement negation. (2 marks)

iii)  Multiplication by 6. (2 marks)

iv)  Addition of the 16-bit unsigned number in r17:r16 to r15:r14 and the T bit in the      status register being 1 if overflow occurs (i.e. the result can’t be represented as a 16-

bit twos complement number) and 0 otherwise.                                                       (4 marks)

Question 5.

This question applies to the AVR ATmega324A microcontroller.

(a)  Write down the machine code corresponding to the AVR assembly language instruction

bst r13,5 (1 mark)

(b)  What will be the binary value in register r30 and the status register bits Z, N, and C after

the execution of each of the following independent blocks of instructions. Assume Z, N and C are all initially 0 before the execution of the first instruction in each block. (2 marks each)

i)    ldi r30, 0x7F inc r30

ii)   ldi r30, 054 swap r30    lsl r30

iii)  ldi r30, 0x73 ldi r16, 37  eor r30, r16

iv)  ldi r30, 0   ldi r31, 253 adiw ZH:ZL, 3

v)   ser r30 push r30

ldi r30, 127

push r30

andi r30, 0

push r30

pop r30

pop r30

Question 6.

(a)  What will be printed after the execution of each of the following C code fragments? (1 mark each)

i)    int16_t x = 0x73; int16_t y = 4;   x >>= y--;

printf("%d %d", x, y);

ii)   int8_t x = 99;

int8_t y = 22;

x = ~x |~y;

printf("%d", x);

iii)  int16_t i = 10;

int16_t b = 9;

while(b & i) {

i -= 2;

b--;

}

printf("%d %d", i, b);

(b)  Write a C declaration which declares var to be

i)    an array of sixteen 16-bit unsigned integers:

(1 mark each)

ii)   a function taking one argument (a string) and returning a character:

(c)  For each of the following C statements for the Atmel AVR ATmega324A, write down the assembly language equivalent. (You may assume that definitions in the m324Adef.inc file are available. Several instructions may be required.)

i)    DDRA |= 0x72;     (1 mark)

ii)   OSCCAL = 0x7F;            (1 mark)

iii)  TCNT1 = 258;          (1 mark)

iv)  uint8_t tmp = PINC;

PORTA = (tmp >> 4) | (tmp << 4); (1 mark)

v)   while( !(SPSR & (1 << SPIF0))) {

;

}

PORTA = SPDR;

(2 marks)

Question 7.

The following is an edited extracted from Section 22 of the ATmega324A datasheet. You will need to refer to this information when answering this question. Note that pins AIN0 and AIN1

are shared with port B, pins 2 and 3 respectively.

(a)  Write a C function int8_t configure_comparator_interrupts(int8_t mode) for the AVR ATmega324A microcontroller which takes one argument (mode) and            configures the analog comparator to generate (or turn-off) interrupts. The mode argument has the following valid values and corresponding meanings:

0       analog comparator interrupts should be disabled

1      the analog comparator should generate interrupts when the voltage on pin AIN0 becomes higher than that on AIN1 (i.e. ACO transitions from 0 to 1)

2      the analog comparator should generate interrupts when the voltage on pin AIN1 becomes higher than that on AIN0 (i.e. ACO transitions from 1 to 0)

3      the analog comparator should generate interrupts when the voltage on pin AIN0 becomes higher or lower than that on AIN1. (i.e. ACO toggles)

It can be assumed that global interrupts are already enabled and should remain enabled. You can make no assumptions about the previous state of the analog comparator. The   function must return - 1 if an invalid mode value is supplied and return 0 otherwise. (6 marks)

int8_t configure_comparator_interrupts(int8_t mode)

{

(b)  Write an AVR assembly language interrupt handler for the ATmega324A that will be     called when the analog comparator interrupt is triggered. The handler must read the          current value of timer/counter 1 and store that value in SRAM locations 0x300 and 0x301 (in little endian format). The interrupt handler must also disable further analog                   comparator interrupts. The interrupt handler must preserve the values of all general           purpose registers and the status register (i.e. these register values must be restored to their

original values if they are changed by the handler).                                                         (6 marks)

Question 8.

Consider the following AVR ATmega324A assembly language module and answer the questions on the following page.

.include m324Adef .inc

.equ NEWLINE = 10

.equ CARRIAGE_RETURN = 13

.equ TAB = 8

.equ OUTPUT_BUFFER_SIZE = __________________

.cseg

charconstants: .DB TAB, NEWLINE, CARRIAGE_RETURN

.dseg

bytes_in_output_buffer: .BYTE 1

out_buffer: .BYTE OUTPUT_BUFFER_SIZE

out_insert_pos: .BYTE 1

.cseg

uart_put_char:

mov r28, r24

cpi r24, NEWLINE

brne nocr

ldi r24, CARRIAGE_RETURN

rcall uart_put_char

nocr :

in r18, SREG

andi r18, 0x80

rjmp pchar

loop:

tst r18

breq return1

pchar :

lds r25, bytes_in_output_buffer

cpi r25, OUTPUT_BUFFER_SIZE

breq loop

cli

lds r24, out_insert_pos

<