Problem Solutions – Chapter 8
9
8-27.
Since the condition codes are not fully available to the programmer (only N and Z are used by instructions, not V and C), the approach
of problem 6-1, part c, for a signed comparison using the N and V bits is not possible. Instead the program must make the comparisons
based upon the signs of the current minimum value and the current array element.
// Assembly for the solution to problem 8-27
// Logic and Computer Design Fundamentals, 5th edition
//
// Using labels for locations to make the targets of branches and jumps more clear
LDI R0, 0 // Read in pointer to array and its length
LDI R1, 1
LD R0, R0
//is positive or zero
BRN no_new_min
new_min: MOV R3, R2
no_new_min: DEC R1, R1 // Update loop variable
BRZ R1, done
INC R0, R0 // Point to the next array element