.REPEAT Directive




The .REPEAT directive executes the loop body before testing the runtime condition following the .UNTIL directive.


 
 .REPEAT

 
    statements

 
 .UNTIL  condition


The code on the right finds the remainder of a division by using the forumla:

 
    i mod j

 
  = i - (i div j) × j
For example,

 
  10 mod  3 =  1

 
 -10 mod -3 = -1

 
 -10 mod  3 = -1

 
  10 mod -3 =  1
 i mod j = i - (i div j) × j 

 
 INCLUDE Irvine32.inc

 
 .data

 
 prompt1   BYTE   "Dividend  = ", 0

 
 prompt2   BYTE   "Divisor   = ", 0

 
 prompt3   BYTE   "Remainder = ", 0

 
 dividend  SWORD  ?

 
 divisor   SWORD  ?


 
 .code

 
 main PROC

 
     call  Clrscr

 
     mov   edx, OFFSET prompt1

 
     call  WriteString

 
     call  ReadInt

 
     mov   dividend, ax


 
     mov   edx, OFFSET prompt2

 
     call  WriteString

 
     call  ReadInt

 
     mov   divisor, ax


 
     ; Check 0 for either operand.

 
     .IF (dividend==0 || divisor==0)

 
       mov  dividend, 0

 
       jmp  L1

 
     .ENDIF


 
     .REPEAT

 
       mov  bx, divisor

 
       .IF (dividend>0 && divisor>0)
          
          


.ELSEIF (dividend<0 && divisor<0) sub dividend, bx neg bx mov ax, dividend neg ax .ELSEIF (dividend<0 && divisor>0) add dividend, bx mov ax, dividend neg ax .ELSE add dividend, bx neg bx mov ax, dividend .ENDIF .UNTIL (ax < bx) L1: mov edx, OFFSET prompt3 call WriteString movsx eax, dividend call WriteInt exit main ENDP END main


      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown