Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: Programming in 8086

Sunday, September 29, 2013

Programming in 8086

  1. Write a program to find out the number of positive and negative numbers from a given array of 10 16-bit numbers


TITLE POSITIVE NEGATIVE
;TO COMPUTE THE NUMBER OF
;POSITIVE AND NEGATIVE NUMBERS
;----------------------------------------------------------------
     .MODEL SMALL
     .STACK 64
     .DATA
     VAR_POS DW 00
     VAR_NEG DW 00  
     ARRAY DW 2,-3,4,5,6,-7,8,9,-2,3 ; input to the program
;----------------------------------------------------------------
     .CODE
MAIN PROC FAR
     MOV AX,@DATA  ; SET ADDRESS OF DATA SEGMENT IN DS
     MOV DS,AX
     MOV CX,10d  ; LOOP COUNTER
     MOV SI,OFFSET ARRAY ; LOADING BX WITH OFFSET
     LOOP:      
         CLC
         XOR AX,AX
         MOV AX,[SI] ; MOVING THE POINTED DATA
         RCL AX,1    ; ROTATE TO CHECK FOR MSB
         JC NEGA
         INC VAR_POS ; IF CARRY FLAG IS RESET (0), INCREASE VAR_POS
         JMP NEXT
         NEGA:
             INC VAR_NEG ; IF CARRY FLAG IS SET (1), INCREASE VAR_NEG
         NEXT:
             INC SI   ;TO FETCH THE
             INC SI   ; NEXT WORD
             DEC CX   ; LOOP UNTIL DATA ARE PROCESSED
         JNZ LOOP                                                                    
     MOV AX,4C00H
     INT 21H
MAIN ENDP
     END MAIN  ;END MAIN PROCEDURE
    

No comments:

Post a Comment