Wednesday, 7 September 2016

Neighbor Prime Number Code in Assembly Language 8086

Neighbor Prime Code in Assembly Language 8086

[org 0x0100]

   mov dx , [input]    ;input in DX
   sub sp , 4
   push dx
   call neighborPrime
  
   mov ax , 0x4c00
   int 0x21


neighborPrime:

   mov bp , sp
   mov dx , [bp+2]
   mov ax , 1
   mov bx , 2
   mov cx , ax
   
   check:
      sub cx , bx
      cmp word cx , 0
      jz refresh
      jl true
      jg check

true:
   mov cx , ax
   inc bx
   cmp bx , ax
   jl check
   jnl place
  
place:
   cmp ax , dx
   jl lessPlace
   jg greatPlace
  
lessPlace:
   mov [bp+6] , ax
  
refresh:
   inc ax
   mov bx , 2
   mov cx , ax
   jmp check

greatPlace:
   mov [bp+4] , ax
   ret 2

input: dw 12


No comments

Post a Comment

Recent Posts