From 65381e63a5b4bd47308c7d055f9cbfd93f33928f Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Wed, 17 Sep 2008 00:45:25 +0000 Subject: [PATCH] Fixed problem of nasm defaulting all conditional branches to short which often generates an error. Now all jumps are near. --- source/Indy.IL2CPU.Assembler.X86/JumpBase.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/Indy.IL2CPU.Assembler.X86/JumpBase.cs b/source/Indy.IL2CPU.Assembler.X86/JumpBase.cs index b197593a2..37d298aad 100644 --- a/source/Indy.IL2CPU.Assembler.X86/JumpBase.cs +++ b/source/Indy.IL2CPU.Assembler.X86/JumpBase.cs @@ -8,13 +8,19 @@ namespace Indy.IL2CPU.Assembler.X86 { public readonly string Address; protected JumpBase(string aAddress) { - Address = aAddress; - if (Address.StartsWith(".")) { - //string xPrefix = (from item in Assembler.CurrentInstance.Instructions - // where !Label.GetLabel(item).StartsWith(".") - // select Label.GetLabel(item)).Last(); - string xPrefix = Label.LastFullLabel; - Address = xPrefix + "__DOT__" + Address.Substring(1); + if (aAddress.StartsWith(".")) { + aAddress = Label.LastFullLabel + "__DOT__" + aAddress.Substring(1); + } + // If it has a :, then its a far call so dont add near + if (aAddress.Contains(':')) { + Address = aAddress; + } else { + // Nasm by default issues conditional branches as short + // and we often exceed the distance + // For now we go for simplicity. Later when we optimize and have + // our own assembler, we should consider using short jumps + // if they are faster + Address = "near " + aAddress; } } }