Author Topic: How can I DB a call instruction?  (Read 4017 times)


  • Guest
How can I DB a call instruction?
« on: September 28, 2005, 06:56:10 PM »
I have a macro named 'call', and so I can't use 'call' in the macro as that would make it recursive.  So I'm trying to do this:

db 0xE8
dd %1 - %%label

This works if %1 is in the current file, but if it's an external symbol, I get this error:

malloc_test.nasm:30,2: error: operand 1: expression is not simple or relocatable

I've tried playing around with $ and $$, but I can't come up with something that both compiles and creates a relative offset.  There must be some way to make it relocatable, as the call instruction is able to do it, I just can't figure out what to type on the DD line to create the same thing that the call instruction creates.

(Of course I could name my macro something other than 'call', but that would be too easy.)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2473
  • Country: us
Re: How can I DB a call instruction?
« Reply #1 on: September 28, 2005, 07:41:29 PM »
Unless I'm mistaken, a call to an external symbol is resolved by the linker, not by Nasm. If you were intimately familiar with the linkable object format you're using, you could probably emulate this behavior, but it would mean creating the entire linkable object "by hand" with Nasm's binary output. There exist macros to do this with an executable (MZ, PE, and ELF), it ought to be possible to do it with a linkable object...

Nasm will treat two macros with different numbers of parameters as different symbols... perhaps you could add a "dummy" parameter to your macro to avoid recursion.

I'll refrain from telling you what a horrid, insane idea obscuring a perfectly good instruction in a misleading, cryptic, error-prone macro is! :)