Division

Integer division is carried out using the accumulator. The quotient and remainder are put into the AL and AH registers, respectively.

program ASM_Divide;
  {$APPTYPE CONSOLE}
  {$ASMMODE INTEL}//Delete this line in Delphi
uses
  SysUtils;
var
  Int : integer = 100;
  Divisor : byte = 21;
  Quotient, Remainder  : byte;
begin
  asm
    MOV EAX, Int
    IDIV Divisor //Integer division
    MOV Quotient, AL //AL is the rightmost byte of the EAX register
    MOV Remainder, AH //AL is the byte of EAX next to AH.
  end;
  writeln(Int,' DIV ', Divisor, ' = ', Quotient);
  writeln(Int,' MOD ', Divisor, ' = ', Remainder);
  readln;
end.

program ASM_DivideA;
  {$mode objfpc}{$H+}
  {$ASMMODE ATT}
uses
  SysUtils;
var
  Int : integer = 100;
  Divisor : byte = 21;
  Quotient, Remainder  : byte;
begin
  asm
    MOV Int, %EAX
    IDIV Divisor //Integer division
    MOV %AL, Quotient //AL is the rightmost byte of the EAX register
    MOV %AH, Remainder //AL is the byte of EAX next to AH.
  end;
  writeln(Int,' DIV ', Divisor, ' = ', Quotient);
  writeln(Int,' MOD ', Divisor, ' = ', Remainder);
  readln;
end.
Programming - a skill for life!

Getting started with in-line assembler