0% found this document useful (0 votes)
200 views10 pages

Class 2 Computer Questions & Answers

Uploaded by

Adishree Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
200 views10 pages

Class 2 Computer Questions & Answers

Uploaded by

Adishree Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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 [Link]
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 [Link]
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)


[Link] 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

Common questions

Powered by AI

Assembler directives like ORIGIN and DATAWORD are crucial for initializing memory prior to program execution. ORIGIN sets the starting address for the program, while DATAWORD initializes specific memory locations with predefined values. These directives ensure that when the program loads, memory is precisely set up with the necessary values at the correct locations, such as placing the value 300 at location 1000 before execution begins .

In sign-and-magnitude representation, negative numbers are represented by setting the most significant bit (MSB) as 1, while the remaining bits represent the magnitude. This leads to two representations for zero (positive and negative zeros). In contrast, two's complement uniquely represents zero and negatives by inverting all bits and adding one to the magnitude, allowing for simpler arithmetic operations without needing to separately track sign, thereby resulting in efficiencies in computational logic .

The Base with Index Addressing mode facilitates efficient memory access by using a combination of a base register (R1) and an index register (R2) to access memory locations. In the context of student scores, R1 points to the starting score for student 1, and R2 is incremented by a calculated Stride value (4(j + 1)) for each subsequent student. This approach ensures that each student's scores are accessed using a single, compact instruction that adjusts dynamically with student count and memory structure .

The memory access pattern in such programs involves incrementing pointers and registers to systematically traverse through the test scores and store computed sums. Initially, base registers point to the first score, while an incremented index follows the stride pattern to access subsequent scores. Accumulated sums for each test are then stored sequentially, necessitating repeated increments and resets of pointers post storage, ensuring orderly and structured data handling in memory .

Two's complement is useful for subtraction in binary operations because it allows direct addition of negative numbers, simplifying the arithmetic process. By taking the two's complement of a number and adding it to the minuend, subtraction becomes an additive operation, removing the need for separate circuitry to handle subtraction and providing a unified approach for both positive and negative arithmetic .

Incrementing pointer registers by a stride value in memory access loops effectively manages data access within structured data patterns, such as matrices or student scores. This technique allows for predictable and efficient navigation across different data points separated by fixed distances in memory, optimizing cache usage and minimizing delay from unpredictable memory access patterns. It provides robustness in iterating over non-contiguously stored data by effectively calculating the exact memory location needed at each step .

Modifying the dot product program to accumulate the sum directly into the DOTPROD register reduces the need for a move instruction, thus simplifying the instruction sequence. However, it significantly increases memory read and write operations for DOTPROD on every loop iteration. This increased interaction with memory consequently impacts the program's execution speed due to higher memory access latency, which can offset the reduced computational instruction sequence benefits .

Overflow in binary addition using sign-and-magnitude representation occurs when the sum of two same-sign numbers results in a carry that changes the sign bit, leading to an incorrect sign in the result. For instance, when adding two positive numbers that exceed the maximum representable value, the result may appear as a negative number, making it critical to monitor carry into the leftmost bit to ensure accurate arithmetic results .

Clearing the high-order 4 bits of each byte to 0000 is essential to avoid unintended data interference in applications where only the lower bits are relevant for processing. This task ensures that operations remain confined to the lower-order nibbles, allowing predictable manipulation of data and preventing potential errors from overflow or data corruption due to extraneous higher-order bits .

The linked list version offers flexibility by allowing dynamic memory management and facilitating ease of insertion and deletion of elements as compared to traditional sequential arrays. It reduces memory constraints by allocating memory only as needed, optimizes traversal patterns, and potentially improves access times by linking data directly rather than depending on static data layouts, enabling efficient management of variable-length student score data .

You might also like