ch06_complete

ch06_complete - F.6 Chapter 6 Solutions 6.1 Yes for example...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
F.6 Chapter 6 Solutions 6.1 Yes, for example, an iterative block where the test condition remains true for each iteration. This procedure will never end and is therefore not Fnite and not an algorithm. The following is an example of a procedure that isn’t an algorithm: x3000 0101 000 000 1 00000 ( LOOP AND R0, R0, #0 ) x3001 0000 010 111111110 ( BRz LOOP ) This is not an algorithm because the branch instruction is always taken and the program loops indeFnitely. 6.2 Problem Statement: Subtract the value in R1 from the value in R2 and store the result in R0. The following is the systematic decomposition of the problem concluding with an LC-3 pro- gram solving the problem. (a) Start -> Subtract R1 from R2; place result in R0 -> End (b) Start -> Compute the complement of the value in R1 -> Add this result to R2 and store the result in R0 -> End (c) Start -> Negate R1 -> Add 1 to R1 -> Add R1 and R2; store result in R0 -> End (d) 1001 001 001 111111 ( NOT R1, R1 ) 0001 001 001 1 00001 ( ADD R1, R1, #1 ) 0001 000 001 0 00 010 ( ADD R0, R1, R2 ) 6.3 The following program uses DeMorgan’s Law to set the appropriate bits of the machine busy register. x3000 1010000000001110 ( LDI R0, S ) x3001 1010001000001110 ( LDI R1, I ) x3002 0101010010100000 ( AND R2, R2, #0 ) x3003 0001010010100001 ( ADD R2, R2, #1 ) x3004 0001001001111111 ( L ADD R1, R1, #-1 ) x3005 0000100000000010 ( BRn D ) x3006 0001010010000010 ( ADD R2, R2, R2 ) x3007 0000111111111100 ( BRnzp L ) x3008 0001001010100000 ( D ADD R1, R2, #0 ) x3009 1001000000111111 ( NOT R0, R0 ) x300a 1001001001111111 ( NOT R1, R1 ) x300b 0101000000000001 ( AND R0, R0, R1 ) x300c 1001000000111111 ( NOT R0, R0 ) x300d 1011000000000001 ( STI R0, S ) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 x300e 1111000000100101 ( TRAP x25 ) x300e 0100000000000001 ( S .FILL x4001 ) x300f 0100000000000000 ( I .FILL x4000 ) 6.4 x3000 0101000000100000 ( AND R0, R0, #0 ) x3001 1001011001111111 ( NOT R3, R1 ) x3002 0001011011100001 ( ADD R3, R3, #1 ) x3003 0001011011000010 ( ADD R3, R3, R2 ) x3004 0000010000000100 ( BRz done ) x3005 0000100000000010 ( BRn neg ) x3006 0001000000111111 ( ADD R0, R0, #-1) x3007 0000111000000001 ( BRnzp done ) x3008 0001000000100001 ( neg ADD R0, R0, #1 ) x3009 1111000000100101 (done halt ) 6.5 The three additions of 88 + 88 + 88 requires fewer steps to complete than the eighty eight additions of 3 + 3 + . .. + 3. Because 88 + 88 + 88 requires fewer instructions to complete, it is faster and therefore preferable. 6.6 Problem Statement: Multiply two numbers together using repeated addition. Make the pro- cedure efFcient by comparing the two numbers per the result of Problem 6.4. Start -> Multiply two numbers; put result in R3 -> End Start -> Compare two numbers -> Multiply two numbers by repeated addition; Put result in R3 -> End Start -> Compare two numbers -> Put smaller number in R2, larger number in R1 -> Add R1 to itself while decrementing R2 -> Store result of repeated addition to R0 -> End The program compares the numbers located in memory locations x3010 and x3011, places
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/07/2008 for the course ECE 495K taught by Professor Vijaykumar during the Spring '08 term at Purdue.

Page1 / 7

ch06_complete - F.6 Chapter 6 Solutions 6.1 Yes for example...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online