Home

Find the negative numbers in a block of data.

Statement: Find the number of negative elements (most significant bit 1) in a block of data. The length of the block is in memory location 2200H and the block itself begins in memory location 2201H. Store the number of negative elements in memory location 2300H

Sample problem 1:

(2200H) = 04H

(2201H) = 56H

(2202H) = A9H

(2203H) = 73H

(2204H) = 82H

Result = 02 since 2202H and 2204H contain numbers with a MSB of 1.

Source program :

  • LDA 2200H
  • MOV C, A : Initialize count
  • MVI B, 00 : Negative number = 0
  • LXI H, 2201H  : Initialize pointer
  • BACK: MOV A, M : Get the number
  • ANI 80H : Check for MSB
  • JZ SKIP : If MSB = 1
  • INR B : Increment negative number count
  • SKIP: INX H : Increment pointer
  • DCR C : Decrement count
  • JNZ BACK : If count   0 repeat
  • MOV A, B
  • STA 2300H : Store the result
  • HLT : Terminate program execution

 

Flowchart for program

19-Find the negative numbers in a block of data

Related Programs for Beginners: (Click down)

Finding Two's complement of a number

Calculate the sum of series of numbers

Multiply two 8-bit numbers

Divide a 16 bit number by a 8-bit number