Machine code: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 467:
{{out}}
19
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
With the "Asm" directive, you can insert machine language directly into Delphi code. If you use the assembly language instructions, you don't have to know the opcode numbers. However, it you really want to insert raw binary values, you can use directives like "db" and "dw" to insert raw values.
 
<syntaxhighlight lang="Delphi">
 
function AddNumbers(Num1, Num2: integer): Integer;
{Add two numbers in assembly language}
asm
PUSH EBX
PUSH EDX
MOV ECX,Num1
MOV EDX,Num2
ADD ECX,EDX
MOV Result,ECX
POP EDX
POP EBX
end;
 
 
 
procedure TestAssembly(Memo: TMemo);
var I,J,K: integer;
begin
for I:=1 to 5 do
for J:=1 to 5 do
begin
K:=AddNumbers(I,J);
Memo.Lines.Add(IntToStr(I)+' + '+IntToStr(J)+' = '+IntToStr(K));
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 + 1 = 2
1 + 2 = 3
1 + 3 = 4
1 + 4 = 5
1 + 5 = 6
2 + 1 = 3
2 + 2 = 4
2 + 3 = 5
2 + 4 = 6
2 + 5 = 7
3 + 1 = 4
3 + 2 = 5
3 + 3 = 6
3 + 4 = 7
3 + 5 = 8
4 + 1 = 5
4 + 2 = 6
4 + 3 = 7
4 + 4 = 8
4 + 5 = 9
5 + 1 = 6
5 + 2 = 7
5 + 3 = 8
5 + 4 = 9
5 + 5 = 10
</pre>
 
 
=={{header|Draco}}==
465

edits