The University of Nottingham

advertisement
G51CSA-E1
The University of Nottingham
SCHOOL OF COMPUTER SCIENCE
A LEVEL 1 MODULE, SEMESTER 1 2010–2011
COMPUTER SYSTEMS ARCHITECTURE
(Course G51CSA)
Time allowed TWO hours
Candidates may complete the front cover of their answer book and sign
their desk card but must NOT write anything else until the start
of the examination period is announced
Answer QUESTION 1 and THREE others
Marks available for sections of questions are shown in brackets
in the right-hand margin
No calculators are permitted in this examination
Dictionaries are not allowed with one exception. Those whose first
language is not English may use a dictionary to translate between that
language and English provided that neither language is the subject of
this examination. No electronic devices capable of storing and retrieving
text may be used.
DO NOT turn examination paper over until instructed to do so
ADDITIONAL MATERIAL PROVIDED
ASCII codes, ARM Assembler Codes and ARM Instruction Layouts (10 pages)
The questions on this paper that relate to the ARM chip, refer to
the 32-bit ARM architecture running in the default ‘little endian’ mode,
as supported by the aasm assembler and the KoMoDo viewer.
G51CSA-E1
Turn Over
2
1
G51CSA-E1
Compulsory Question
This is a multiple choice question in five parts labelled (a)–(e). In each of these parts
there is at least one correct choice but there may be several. For each of the parts
list all the roman numerals that correspond to correct choices, but avoid listing any of
the incorrect ones.
The marking in each of the parts will be as follows:
no errors
1 error
2 errors
3 errors or more
(a)
(b)
(c)
5
3
1
0
points
points
point
points
Which of the following statements about 8-bit unsigned binary numbers are correct?
(i)
Multiplying by 2 corresponds to shifting the number one place to the left
(ii)
The most significant binary digit has a weight of 256
(iii)
The largest representable number is 255
(iv)
Shifting to the right by one place corresponds to integer division by 2
(v)
If the number is odd the right-most binary digit will be 0
(5)
Which of the following statements about 8-bit two’s complement are correct?
(i)
The largest positive number is 128 = 27
(ii)
The least negative number is −128 = − 27
(iii)
Adding 111111112 and 000000012 produces an overflow.
(iv)
Adding 011111112 and 000000012 produces an overflow.
(v)
The two’s complement of 11111111 is 00000000
(5)
Which of the following statements about the ARM chip are true?
(i)
It is a 64-bit processor
(ii)
It has facilities for ‘conditional execution’ on every instruction
(iii)
It is a CISC (Complex Instruction Set Computer) design
(iv)
The standard link register, for holding a return address, is R14
(v)
The status flags are set automatically by every executed instruction
(Question continued on the next page)
G51CSA-E1
(5)
3
(d)
G51CSA-E1
What does the following program fragment do?
num
DEFW
. . .
0xBB00FFAC
ADR R0, num
LDRB R1, [R0]
LDRB R2, [R0,#2]
LDR R3, [R0]
MOV R4, R3, LSR #24
(e)
2
(i)
Puts the integer 2 into R2
(ii)
Puts the byte AC16 into R1
(iii)
Puts the byte FF16 into R2
(iv)
Leaves R4 containing BB16
(v)
Leaves R4 containing AC16
(5)
Which of the following staments about IEEE754 (floating point standard) singleprecision floating-point numbers are correct?
(i)
The exponent is represented in excess 127 format
(ii)
The exponent is represented in two’s complement
(iii)
The word consisting of 32 zeros represents the number 0
(iv)
The word consisting of 32 zeros is a normalized number
(v)
The word consisting of 32 zeros is a denormalized number
(5)
Complete the following table i.e. calculate the 12 values labelled a–l
(a)
(b)
Decimal Binary
111 a
d 111
g h
j k
Hexa- decimal Octal b
e
111
l
c
f
i
111
(12)
With the aid of the instruction layout booklet, translate the following hex-codes
for single-word ARM instructions into the assembler mnemonics that would have
generated them.
(Question continued on the next page)
G51CSA-E1
Turn Over
4
(c)
3
(a)
(i)
EF000002
(ii)
E0821001
(iii)
B2822001
(iv)
E24F0018
G51CSA-E1
(8)
With the aid of the instruction layout booklet, translate the following mnemonics
for single-word ARM instructions into the hexadecimal representation of the 32-bit
binary coding for that instruction
(i)
CMP R5, #0xFF
(2)
(ii)
MLANE R1, R2, R3, R0
(3)
Consider the following fragment of an ARM program
;
out
input integers are in R1, R2, R3
MOV R0, R1
CMP R0, R2
MOVLT R0, R2
CMP R0, R3
MOVLT R0, R3
; result is in R0
Simulate the program for the values of R1, R2 and R3 shown in the table below. Write
down, in each case, what the value will be in register 0 when execution reaches the
label out, i.e. supply the correct values for a, b and c in the table below. All numbers
are in decimal.
R1 R2
1 2
-5 20
-2 -3
R3 R0
3 a
3 b
-1 c
Describe in one sentence what the program calculates
(b)
(8)
The following C program fragment calculates the sum of the positive integers
from 1 up to x.
y = 0;
for ( i = 1; i <= x; i++)
y = y + i;
Translate this program first to a C program using a while loop, then to a C program
using goto and finally to a program in ARM assembler which prints the integer answer
to the Komodo ‘Features’ window using a SWI 4 system call. You should preset a test
value for x with an EQU directive at the top of the program.
(12)
(Question continued on the next page)
G51CSA-E1
5
(c)
G51CSA-E1
A more efficient implementation for this problem would use Gauss’s formula
y = x * (x + 1) / 2
Implement this new solution in ARM assembler code. The chosen value of x
should be set up using EQU, and kept small enough that any multiply operations
do not cause overflow. Output your answer using SWI 4.
4
(a)
(5)
Calculate the representations of the following decimal numbers in 8-bit two’s
complement:
a = 11
b = −100
c = 123
Calculate in detail, using 8-bit two’s complement, the sums a + b, b + c, a + c.
In which case does an overflow occur?
(7)
(c)
Calculate in detail, using unsigned 8-bit arithmetic, the 16-bit result of c × a.
(5)
(d)
Calculate in detail, using unsigned 8-bit arithmetic, the 8-bit quotient and remainder of c ÷ a.
(7)
(b)
5
(6)
(a)
What are the representations of the following real numbers as single-precision
(32-bit) IEEE 754 floating-point numbers? Your answer should be a sequence of
32 bits, indicating clearly which bits are sign, exponent and mantissa.
a = 10, b = −0.5, c = 0.6875
(b)
(c)
(d)
6
(9)
Calculate in detail the value of a + b, showing all the detail of your working, and
present your result as a normalized IEEE 754 floating point number.
(5)
Calculate in detail a × b and present your result as a normalized IEEE 754 floating point number.
(6)
Summarize the rounding modes available in IEEE 754. Which of these is the default in C, C++ and Java?
(5)
Study the ARM coding, below, for a string function called strfunc. This function
expects to receive in R1, the start address of a string that has been pre-declared in
the main program. In R2 it expects to receive the ASCII code of some chosen character in that string. Once the analysis in strfunc is complete it returns to the main program with R0 containing either a positive integer, denoting success, or -1, denoting
failure.
(Question continued on the next page)
G51CSA-E1
Turn Over
6
B main
mesg1 DEFB
mesg2 DEFB
ALIGN
G51CSA-E1
"This is my message\0"
"Greetings Earthlings!\0"
strfunc
MOV R0, #-1
; initialise position index
MOV R4, #0
; initialise index counter
LDRB R3, [R1,R4]
CMP R3, R2
MOVEQ R0, R4
CMP R3, #0
ADDNE R4, R4, #1
BNE load
MOV PC, LR
load
; end of strfunc
main
; supply two lines of code to set up the start address of
; mesg1 in R1 and the desired test character in R2
BL strfunc
;
;
;
;
;
;
;
(a)
(b)
(c)
(d)
supply code that analyzes the integer return value
from strfunc and prints it to the Komodo Features window
followed by a SWI 2 to halt KoMoDo. The standard SWI integer
printout option can only cope with positive integers.
However, your code should ensure that if the returned value
from strfunc is -1 then the printout to the Features window
should look like -1.
In the section just before BL strfunc, supply the two required lines of code to
set up R1 with the start address of mesg1, and R2 with the ASCII code for the
character e.
(2)
For the case where R1 contains the start address of mesg1, and R2 contains the
ASCII character e, predict what the value returned by strfunc will be. Give reasons for your prediction.
(4)
Write coding to follow after the call of BL strfunc that will comply with the supplied program comment by coping gracefully with printing out either a positive integer result, in the case of success, or (using different SWI instructions) will actually print out -1 in the case of failure.
(5)
Write a detailed account of the overall intended effect of the strfunc function. Be
sure to state at the outset what the strategic objective of the function is and only
then supply further detail of how it achieves this objective via appropriate initializations, use of conditional execution and use of pre- or post-indexed address
pointers.
(6)
(Question continued on the next page)
G51CSA-E1
7
(e)
G51CSA-E1
Using the conventions of the ARM Procedure Calling Standard (APCS) answer the
following questions:
(i)
How are the arguments to the procedure passed?
(1)
(ii)
How is a simple integer result returned?
(1)
(iii) Which registers have to be preserved by caller and callee
(4)
(iv) Where can a procedure’s local variables be stored?
(2)
G51CSA-E1
End
Download