Showing posts with label 8086 microprocessor. Show all posts
Showing posts with label 8086 microprocessor. Show all posts

Saturday, 11 January 2014

Binary search

        MOV SI,3006
repeat: MOV AX,@3000
        MOV BX,@3002
        CMP AX,BX
        JG terminate:
        MOV DX,0
       ADD AX,BX
       MOV BX,2
       DIV BX
       MOV BX,@3004
       MOV CX,AX
      DEC CX
here:       ADD SI,2
      LOOP here:
      CMP BX,[SI]
     JG incrmid:
     JL decrmid:
     MOV DX,1
     JMP end:
incrmid: INC AX
     MOV @3000,AX
     JMP repeat:
decrmid: DEC AX
     MOV @3002,AX
     JMP repeat:
terminate:MOV DX,0
end :     INT 03

Linear search

        .A  <start address>
        MOV DX,0
        MOV SI,3000
        MOV CX,[SI]
        ADD SI,2
        MOV AX,[SI]
compare:  ADD SI,2
        CMP AX,[SI]
        JE found:
        LOOP compare:
       JMP end:
found:      MOV DX,1
end:         INT 03

Sum and average of 'n' numbers

Logic:It contains an array of elements such that,
      1.location 3000 contains no. of elements
      2.From 3000 it contains values of array elements
      3.And the location contains the sum,Average will be stored in AX


     MOV SI,3000
     MOV AX,0
     MOV CX,[SI]
repeat:   ADD SI,2
    ADD AX,[SI]
    LOOP repeat:
    ADD SI,2
    MOV [SI],AX
    MOV CX,@3000
    DIV CX
   INT 03

Division without using DIV command

   .A <start address>
   MOV CX,0
   MOV AX,@3000
   MOV BX,@3002
repeat: SUB AX,BX
   ADD CX,1
   CMP AX,BX
   JGE repeat:
   INT 03

->Result will be stored in CX register

Tuesday, 7 January 2014

Addition of two numbers with carry(carry propagation)

Logic:If the addition of two numbers produces a carry then CX is set to '1'  else '0'.

code:

        .A  <start address>     (intialisation)
        MOV AX,@3000       (move content at 3000 to AX register)
        MOV BX,@3002       (move content at 3002 to BX register)
        MOV CX,0                (move 0 to CX register)  
        ADD AX,BX              (ADD BX with content of AX)
        JNB here:                    (if no-byte(no-carry) jump here:)
        MOV cx,1                 (if there is a carry move 1 to CX register)
here: INT 03                      (termination)

Division of two numbers

.A  <start address>        (intialisation)
MOV AX,@3000          (move content at 3000 to AX register)
MOV BX,@3002          (move content at 3002 to BX register)
DIV BX                         (divide the value at BX with AX register,result being stored in AX)
INT 03                          (termination)

Multiplication of two numbers

.A  <start address>        (intialisation)
MOV AX,@3000          (move content at 3000 to AX register)
MOV BX,@3002          (move content at 3002 to BX register)
MUL BX                       (multiply the value at BX with AX register,result being stored in AX)
INT 03                           (termination)

subtraction of two numbers

.A <start address>
MOV AX,@3000    (move value at 3000 to AX register)
MOV BX,@3002     (move value 3002 to BX register)
SUB AX,BX       (SUB value at BX with AX)
INT 03           (termination)       

Addition of two numbers(pre-defined values)

.A  <start address>
MOV AX,2  (move value 2 to AX register)
MOV BX,3  (move value 3 to BX register)
ADD AX,BX (ADD value at BX with AX)
INT 03    (termination)

Addition of two numbers(user's choice)

.A    <start address>
MOV AX,@3000  (moving content at 3000 to Ax register)
MOV BX,@3002  (moving content at 3002 to Bx register)
ADD AX,BX          (ADD value at BX with AX register)
INT 03                   (termination)