0% found this document useful (0 votes)
21 views

Chapter 2 Exercise Problems

Uploaded by

Adishree Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Chapter 2 Exercise Problems

Uploaded by

Adishree Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Chapter 2(2.1,2.2,2.5,2.8,2.13,2.

9(HW))
Machine Instructions and Programs

2.1. The three binary representations are given as:

Decimal Sign-and-magnitude 1’s-complement 2’s-complement


values representation representation representation

5 0000101 0000101 0000101


−2 1000010 1111101 1111110
14 0001110 0001110 0001110
−10 1001010 1110101 1110110
26 0011010 0011010 0011010
−19 1010011 1101100 1101101
51 0110011 0110011 0110011
−43 1101011 1010100 1010101
2.2. (a)

(a) 00101 (b) 00111 (c) 10010


+ 01010 + 01101 + 01011
——— ——— ———
01111 10100 11101
no overflow overflow no overflow

(d) 11011 (e) 11101 (f) 10110


+ 00111 + 11000 + 10011
——— ——— ———
00010 10101 01001
no overflow no overflow overflow

(b) To subtract the second number, form its 2’s-complement and add it to
the first number.
(a) 00101 (b) 00111 (c) 10010
+ 10110 + 10011 + 10101
——— ——— ———
11011 11010 00111
no overflow no overflow overflow

(d) 11011 (e) 11101 (f) 10110


+ 11001 + 01000 + 01101
——— ——— ———
10100 00101 00011
no overflow no overflow no overflow

2.3. No; any binary pattern can be interpreted as a number or as an instruction.

2.4. The number 44 and the ASCII punctuation character “comma”.


2.5. Byte contents in hex, starting at location 1000, will be 4A, 6F, 68, 6E, 73, 6F,
6E. The two words at 1000 and 1004 will be 4A6F686E and 736F6EXX.Byte
1007 (shown as XX) is unchanged. (See Section 2.6.3 for hex notation.)

2.6 Byte contents in hex, starting at location 1000, will be 4A, 6F, 68, 6E, 73, 6F,
6E. The two words at 1000 and 1004 will be 6E686F4A and XX6E6F73.Byte
1007 (shown as XX) is unchanged. (See section 2.6.3 for hex notation.)
2.7 Clear the high-order 4 bits of each byte to 0000.

2.8 A program for the expression is:

Load A
Multiply B
Store RESULT
Load C
Multiply D
Add RESULT
Store RESULT
2.9 Memory word location J contains the number of tests, j, and memory word
location N contains the number of students, n. The list of student marks
begins at memory word location LIST in the format shown in Figure 2.14. The
parameter Stride = 4(j + 1) is the distance in bytes between scores on a
particular test for adjacent students in the list.
The Base with index addressing mode (R1,R2) is used to access the scores
on a particular test. Register R1 points to the test score for student 1, and
R2 is incremented by Stride in the inner loop to access scores on the same
test by successive students in the list.

Move J,R4 Compute and place Stride = 4(j + 1)


Increment R4 into register R4.
Multiply #4,R4
Move #LIST,R1 Initialize base register R1 to the
Add #4,R1 location of the test 1 score for student 1.
Move #SUM,R3 Initialize register R3 to the location
of the sum for test 1.
Move J,R10 Initialize outer loop counter R10 to j.
OUTER Move N,R11 Initialize inner loop counter R11 to n.
Clear R2 Clear index register R2 to zero.
Clear R0 Clear sum register R0 to zero.
INNER Add (R1,R2),R0 Accumulate the sum of test scores in R0.
Add R4,R2 Increment index register R2 by Stride value.
Decrement R11 Check if all student scores on current
Branch>0 INNER test have been accumulated.
Move R0,(R3) Store sum of current test scores and
Add #4,R3 increment sum location pointer.
Add #4,R1 Increment base register to next test
score for student 1.
Decrement R10 Check if the sums for all tests have
Branch>0 OUTER been computed.
2.10. (a)

Memory
accesses
————

Move #AVEC,R1 1
Move #BVEC,R2 1
Load N,R3 2
Clear R0 1
LOOP Load (R1)+,R4 2
Load (R2)+,R5 2
Multiply R4,R5 1
Add R5,R0 1
Decrement R3 1
Branch>0 LOOP 1
Store R0,DOTPROD 2

(b) k1 = 1 + 1 + 2 + 1 + 2 = 7; and k2 = 2 + 2 + 1 + 1 + 1 + 1 = 8

2.11. (a) The original program in Figure 2.33 is efficient on this task.
(b) k1 = 7; and k2 = 7
This is only better than the program in Problem 2.10(a) by a small
amount.
2.12. The dot product program in Figure 2.33 uses five registers. Instead of using
R0 to accumulate the sum, the sum can be accumulated directly into
DOTPROD. This means that the last Move instruction in the program can be
removed, but DOTPROD is read and written on each pass through the loop,
significantly increasing memory accesses. The four registers R1, R2, R3, and
R4, are still needed to make this program efficient, and they areall used
in the loop. Suppose that R1 and R2 are retained as pointers tothe A and B
vectors. Counter register R3 and temporary storage register R4 could be
replaced by memory locations in a 2-register machine; but the number of
memory accesses would increase significantly.

2.13. 1220, part of the instruction, 5830, 4599, 1200.


c-1200+4600+30=5830

d. Effective Address=R2−1=4600−1=4599 (pre decrement)


e.Effective Address=R1=1200 (post increment)
2.14. Linked list version of the student test scores program:

Move #1000,R0
Clear R1
Clear R2
Clear R3
LOOP Add 8(R0),R1
Add 12(R0),R2
Add 16(R0),R3
Move 4(R0),R0
Branch>0 LOOP
Move R1,SUM1
Move R2,SUM2
Move R3,SUM3
2.15. Assume that the subroutine can change the contents of any register used
to pass parameters.

Subroutine

Move R5, − (SP) Save R5 on stack.


Multiply #4,R4 Use R4 to contain distance in
bytes (Stride) between successive
elements in a column.
Multiply #4,R1 Byte distances from A(0,0)
Multiply #4,R2 to A(0,x) and A(0,y)
placed in R1 and R2.
LOOP Move (R0,R1),R5 Add corresponding
Add R5,(R0,R2) column elements.
Add R4,R1 Increment column element
Add R4,R2 pointers by Stride value.
Decrement R3 Repeat until all
Branch>0 LOOP elements are added.
Move (SP)+,R5 Restore R5.
Return Return to calling program.
2.16. The assembler directives ORIGIN and DATAWORD cause the object pro-
gram memory image constructed by the assembler to indicate that 300 is to
be placed at memory word location 1000 at the time the program is loaded
into memory prior to execution.
The Move instruction places 300 into memory word location 1000 when the
instruction is executed as part of a program.

2.17. (a)

Move (R5)+,R0
Add (R5)+,R0
Move R0,−(R5)

(b)

Move 16(R5),R3

(c) Add #40,R5

You might also like