You are on page 1of 7

September 28, 2012

Your Name:

CSCE 230, Fall 2012


Test #1 (Chapters 1&2)
Maximum Time: 50 Minutes,

Total Points: 100

Notes:
You may not consult any other material or use a calculator.
Answer in the space provided; if necessary use the backside of the sheet. Point
values for problems are as indicated within square brackets.
Problem 1 [10 Points]: Convert the following unsigned numbers
(a) 4210 (decimal)

101010

(b) A68C16 (hexadecimal)

42636

10

(decimal)

(c) 111110111002 (binary) =

2012

10

(decimal)

(d) 201210 (decimal)

7DC

16

(hex)

(e) 1111000000012 (binary)=

F01

16

(hex)

(binary)

Problem 2 [20 points]: This problem asks you to represent signed integers in
binary using each of the three representations discussed in the class. Assume there
are a total of 6 bits in the representation. Show how the three numbers shown in
the column headers will appear in the three representation systems:

Page 2 of 7

Page 3 of 7
Problem 3 [14 points]: For this problem, assume signed integers A and B are
represented in 2s complement, where A = +15 and B = -22 in decimal. You are
asked to carry out A+B and A B as follows
Be sure to verify your result, i.e., convert the binary result back to decimal and verify
the operation and indicate overflow, if any:
(a) Addition A + B:
A = +15:
B = -22:

Carries:

Result:
Verify
111001

Result:

= -7 15-22 = -7

Overflow?: No, the sum of a positive and a negative number does not r
(b) Subtraction A B = A + (-B)

A = +15:
B =+22:

Carries:

Result:

Verify Result:
100101 = -27
15+22 = 37
Overflow?: Yes, the sum of two positive numbers leads to a negative
number

Page 4 of 7
Problem 4 [20 Points] Use the register and memory values in the table below for
all parts of this question. Assume a 32-bit machine. Further, assume that each part
of the question starts from the table values; that is, DO NOT use value changes from
one question as propagating into future parts of the question.
Register

Value

R1
R2
R3
R4

4
16
24
16

Memory
Location
16
20
24
32

Value
3
5
8
13

(a) [2 Pts] Give the values of R2, and R3 after this instruction: move R3, R2.
Answer:
R2 = 16
R3 = 16

(b) [2 Pts] What values will be in R2 and R3 after this instruction: load R3, 4(R2) ?
Answer:
R2 = 16
R3 = 5

(c) [4 Pts]What values will be in R1, R2, and R3 after this instruction: or R3, R2, R1.
Answer:
R1 = 4
R2 = 16
R3 = 20
00100 OR 10000 = 10100 = 20

(d) [12 Pts] What would be value in R4 after the following set of instructions?
add R2, R2, R1
R2 = 20
load R4, 4(R2)
4(R2) refers to memory location 24, R4 = 8
mul R4, R4, R1
R4 = 8 * 4 = 32
load R4, 0(R4)
0(R4) refers to memory location 32, R4 = 13
Answer:
R4 = 13

Problem 5 [36 Points]:

Page 5 of 7
On the last page you will find the code for a program that calls a procedure MEMCPY
and the code for the procedure MEMCPY. Note that the line numbers shown in the
first column are not part of the code but included only for reference. Answer the
following questions for this code.
(a) [3Pts] Identify by line number the assembler directives in the program:
Answer:
1&2
(b) [3Pts] List all the labels that function as names for memory locations.
Answer:
Main, N, FROM, TO, MEMCPY, DOWN, UP, DONE
(c) [3Pts] Identify at least one instance of a pseudo-instruction in the code.
Answer:
movia
(d) [3Pts]Why does the program save the register r6 in Line 21 of the code?
Answer:
r6 is used within the subroutine MEMCPY. It is first saved
in the stack to preserve its previous value.

(e) [16 Pts] Assuming the initial value of SP=1000. Sketch the state of the stack and
indicate the value of SP after the execution of following lines:
(i)

[8 Pts] After line 10:


Answer:
SP:
992

992:
996:
1000:

FROM
N

Page 6 of 7

(ii)

[8 Pts] After line 25:


Answer:
SP:
964

964:
968:
972:
976:
980:
984:
988:
992:
996:
1000:

[R7]
[R6]
[R5]
[R4]
[R3]
[R2]
TO
FROM
N

(f) [8 Pts] Describe the MEMCPY procedure as follows


Answer:
(i)
[2 Pts] What are the input parameter(s) it expects and where should
they be stored before calling the procedure?
Addresses to N, FROM, and TO should be stored in stack

(ii)

[2 Pts] What are the output parameter(s) it produces and where are
they stored after the procedure execution?
The procedure does not provide any output parameters.

(iii)

[4 Pts] What functionalities does MEMCPY provide?


MEMCPY copies N bytes starting at address FROM to a memory
location starting at address TO
If the memory spaces overlap, MEMCPY starts to copy from the
last byte in an descending order.

Line No.

Code

Page 7 of 7
1
.text
2
.globl main
3
Main:
movia r2, N /* Load the length parameter
*/
ldw r2, (r2) /* into r2. */
4 5
subi
sp,
sp,
4 /* Save input parameters */
6
stw
r2,
(sp)
/* in stack */
7
movia
r2,
FROM /* Pointer to from list.
8
*/
subi sp, sp, 4 /* Save input
9
parameters */
stw r2, (sp)
/* in
10
stack */
movia r2, TO /* Pointer to to
11
list. */
subi sp, sp, 4 /* Save input
12
parameters */
stw r2, (sp)
/* in
13
stack */
call MEMCPY
next
14
instruction
15
16
MEMCPY: subi sp, sp, 24 /* Save registers.
*/
stw r2, 20(sp)
stw r3,
17
16(sp)
stw
r4,
12(sp)
stw
18
r5,
8(sp)
stw
r6,
4(sp)
stw
19
r7,
(sp)
20
ldw r2, 32(sp) /* Load input parameters
21
*/
ldw r3, 28(sp)
ldw r4, 24(sp)
22
add r5, r3, r2 /* Compute address of the last
23
*/
subi r5, r5, 1 /* entry in the from list.
24
*/
bgeu r4, r5, UP /* Scan downwards if to
25
list */
bleu r4, r3, UP /* begins inside from
26
list. */
add r6, r4, r2 /* Compute the
27
pointer for */
subi r6, r6, 1 /* scanning
downwards. */ DOWN:
ldb r7, (r5) /* Transfer a byte
28
and */
stb r7, (r6)
29
subi r5, r5, 1 /* adjust the pointers downwards.
30
*/
subi r6, r6, 1
bge r5, r3, DOWN
31
br
DONE
32
UP:
ldb r7, (r3) /* Transfer a byte and */
33
stb r7, (r4)
34
addi r3, r3, 1 /* adjust the pointers upwards.
35
*/
addi r4, r4, 1
bleu r3, r5, UP
36
DONE:
ldw r7, (sp) /* Restore registers.
37
*/
ldw r6, 4(sp)
ldw r5,
38
8(sp)
ldw r4, 12(sp)
ldw
39
r3, 16(sp)
ldw r2, 20(sp)
40
addi sp, sp, 24
ret
41
42
43
44
45
46
47
48
49
bgeu r4, r5, UP branch to UP if r4 r5

You might also like