0
votes

I'm start programming assembly for ARMv8 and I'm facing an error to compare a value to create a conditional code:

First approach:

#include <AsmMacroIoLibV8.h>

var1 .8byte 0xdedededef1f1f1f1

ASM_FUNC(CompareValues)
  ldr    x1,=var1

  cmp x1,#dedededef1f1f1f1
  b.ne  error
  mov   x0,#0             
  ret

error:
  mov x0,x1
  ret

But I got the message: "Error: Immediate out of Range" when I tray to compile the code.

I also change the code to remove the immediate from cmp instruction like this:

Second approach:

#include <AsmMacroIoLibV8.h>

var1 .8byte 0xdedededef1f1f1f1
var2 .8byte 0xdedededef1f1f1f1

ASM_FUNC(CompareValues)
  ldr    x1,=var1
  ldr    x2,=var2

  cmp x1,x2
  b.ne  error
  mov   x0,#0             
  ret

error:
  mov x0,x1
  ret

At this approach I could compile the code code but when I run the code I'm getting a value different of zero (0xF03730B4). This is my C code:

/** @file
 * EntryPoint.c
 * Poc ASM application  
 **/
#include <Uefi.h>
#include <Library/UefiLib.h>

UINT64 CompareValues();

/** Entry point for the application.
 *
 * @param[in] ImageHandle    The firmware allocated handle for the EFI image.
 * @param[in] SystemTable    A pointer to the EFI System Table.
 *
 * @retval EFI_SUCCESS       The entry point is executed successfully.
 * @retval other             Some error occurs when executing this entry point.
 **/
EFI_STATUS
EFIAPI
PocAsm_EntryPoint 
(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE* SystemTable
)
{
  UINT64 CmpVal = 0;

  CmpVal = CompareValues();
  Print(L"Result: %llx\n", CmpVal);
  return EFI_SUCCESS;
}

Finally, if I use a small immediate like #0xff in the first approach, everything works fine. Is there any way to make this comparison works? I don't if I'm missing something.

Thank you guys.

Note that ldr x2, =var2 loads the address of var2 and not its contents. To directly load the constant 0xdedededef1f1f1f1 into x2, use ldr x2, =0xdedededef1f1f1f1 or follow ldr x2, =var2 with ldr x2, [x2] to load from the address you just loaded. - fuz
Thank you very much! This solved my error. - Davy Souza