Multiplication

Program ASM_Multiply shows you how to copy data in and out of registers using the MOV mnemonic and how to multiply integers using IMUL.

program ASM_Multiply;
  {$APPTYPE CONSOLE}
  {$ASMMODE INTEL}//Delete this line in Delphi
uses
  SysUtils;
var
  Int : integer = 10;
begin
  asm
    MOV EAX, Int //Copy the value in Int to the accumulator
    IMUL EAX, 5 //Integer multiplication
    MOV Int, EAX
  end;
  writeln('10 x 5 = ', Int);
  readln;
end.
  

Using AT&T syntax, we must use the % symbol to denote a register.

program ASM_MultiplyA;
  {$mode objfpc}{$H+}
  {$ASMMODE ATT}
uses
  SysUtils;
var
  Int : integer = 10;
begin
  asm
    MOV Int, %EAX  //Copy the value in Int to the accumulator
    IMUL $5, %EAX  //Integer multiplication
    MOV  %EAX, Int
  end;
  writeln('10 x 5 = ', Int);
  readln;
end.
  
Programming - a skill for life!

Getting started with in-line assembler