# HW2_S - 0306-250 Assembly Language Programming Fall 2009...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Fall 2009 Homework Two Solution 1. Write an assembly language code fragment to implement the following conditional expression, where A and B refer to the accumulator registers A and B. if (A <= 0) A = 0 else A = A + B ; Compare A to zero cmpa #0,D0 ; same result as tsta ; If greater than zero do not clear it bgt Else ; Clear A to zero clra bra EndIf Else: ; Calculate sum aba EndIf: 2. Write an assembly language code fragment to implement the following loop expression using a conditional branch instruction, (i.e., Bcond). Use an index register to hold the address of the array element being added to the sum. A and B refer to the accumulator registers A and B, and Array is an array of byte values. A = 0 for (B = 0; B < 100; B++) A = A + Array[B] ; Initialize Sum clra ; Initialize pointer to array ldx #Array ; Initialize loop control variable clrb ForLoop: ; Compute Sum adda 1,x+ ; Increment loop control variable incb ; Terminal count reached? cmpb #100 blt ForLoop Page 1 of 2 0306-250 20091 Homework Two Solution Page 2 of 2 3. Write an assembly language code fragment which implements the following loop expression using a decrement and branch instruction, (i.e., DBcond). Use an index register to hold the address of the array element being added to the sum. A and B refer to the accumulator registers A and B, and Array is an array of byte values. A = 0 for (B = 0; B < 100; B++) A = A + Array[B] ; Initialize Sum clra ; Initialize pointer to array ldx #Array ; Initialize loop control variable ldab #100 ForLoop: ; Compute Sum adda 1,x+ ; Update loop control variable ; and check terminal count dbne b,ForLoop ...
View Full Document

## This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online