Part A. Short Answers. (18 marks)
1. What distinguishes von Neumann machines from the
computers, like
(2 marks) the ENIAC, which preceded them?
The fact that in von Neumann machines programs were
stored in the memory alongside the data and not hardwired as in the
previous generation of computers (ENIAC included).
2. Which of the following is the correct von Neumann execution
cycle.
(2 marks) Circle the correct answer, and
briefly state why.
a) Increment PC, Fetch and Decode, Execute, Repeat
b) Fetch and Decode, Increment PC, Execute, Repeat
c) Fetch and Decode, Execute, Increment PC, Repeat
b) is the right answer. The first case would ignore the very first
instruction of a program and the last case would create problems with
any kind of branch operation.
3. What is stored in the Instruction Register (IR) of the Pep/6
computer?
(2 marks) How long is IR?
IR contains the instruction to be executed fetched from the memory
based on the current address specified in PC. The length of this
register is 24 bits.
4. What is the 16-bit twos-complement hexadecimal representation
of
each of the following decimal numbers? Show your
calculations.
(2 marks) (a) 27
# mod 2 =
----------------
27 1
13 1
6 0
3 1
1 1
0000 0000 0001 1011 = 001B
(2 marks) (b) -43
# mod 2 =
----------------
43 1
21 1
10 0
5 1
2 0
1 1 so +43 = 0000 0000 0010 1011
to change into negative:
flip the bits and add 1
1111 1111 1101 0100
1
-----------------------------------
1111 1111 1101 0101 = FFD5
5. What is the signed decimal number represented by each of the
following
16 bit twos-complement hexadecimal representations? Show your
calculations.
(2 marks) (a) 005D
005D (hex) = 5*16 +13 = 93 (dec)
(2 marks) (a) FFE7
FFE7 is negative, so first convert to positive (flip bits and add
one)
1111 1111 1110 0111
0000 0000 0001 1000
1
0000 0000 0001 1001 = 0019 (hex) = 1*16+9 (dec) = 25 (dec)
so the answer is -25
6. Here are four bytes of Pep/6 machine language, represented as
(2 marks) hexadecimal numbers:
Which of the following fragments of assembly language program
would
generate these four bytes of machine language? (Circle the
letter of the
correct response.) There is a summary of the Pep/6 instructions
appended to this midterm paper.
a) LOADA h#FF3C,i
b) LOADX h#00FF,d
NOTX
c) LOADA h#00FF,d
NOTA
d) LOADA h#FF3C,d
e) LOADX h#00FF,i
NOTX
7. What is the difference between
(2 marks)
xx: .BYTE d#3
and
xx: .BLOCK d#3
The first line reserves 1 byte of memory and initializes it to
value 3
The second line reserves 3 bytes of memory and does not initialize
them
Part B. Assembly Language Programming. (12 marks)
Translate the following C program to Pep/6 assembly language.
A summary of Pep/6 instructions is appended to this midterm
paper.
If you are unsure how to translate some part of the program,
translate
the rest of it and insert comments indicating where the missing
part
would go. You may perform optimisations on the assmebly language
program if you wish.
int main () {
int i, n, value, evens, odds;
evens = 0;
odds = 0;
scanf ("%d", &n); /* input n */
for (i = 1; i <= n; i = i + 1) {
scanf ("%d", &value); /* input value */
if ((value/2)*2 == value)
evens = evens + 1;
else
odds = odds + 1;
}
printf ("%d%s%d", evens, " ", odds);
}
br main
n: .word d#0
value: .word d#0
i: .word d#0
evens: .word d#0
odds: .word d#0
;
main: deci n,d
;
loada d#1,i
storea i,d
;
loop: compa n,d
brgt endloop
;
deci value,d
;
loada value,d
asra
asla
compa value,d
brne noteq
eq: loada evens,d
adda d#1,i
storea evens,d
br forlast
noteq: loada odds,d
adda d#1,i
storea odds,d
forlast: loada i,d
adda d#1,i
storea i,d
br loop
endloop: deco evens,d
charo c#/ /,i
deco odds,d
stop
.end
CISC 221 Midterm Fall 1999 solutions Page # of # pages