Author Topic: Is there any one there?  (Read 3330 times)

Alfonso V

  • Guest
Is there any one there?
« on: December 03, 2004, 10:08:56 AM »
It seems everybody is on holidays?

My question is:
Is there any way to get the label offset into a constant?.

I have next code:

ORG 100h
section .text
[...]

section .data
Array:
DW 0
DW 4000
DW 2400
DW -100

%define L Array + 2 ; <- ERROR
%rep 3
DW L
%define L L + 2
%endrep


Nasm doesn't allow to use "Array" into "%define" directive, how can i do this?

Regards
alfonso

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2364
  • Country: us
Re: Is there any one there?
« Reply #1 on: December 08, 2004, 07:54:04 AM »
I can't get Nasm to error out on that exact line, but I don't think you'd want "%define" for this. "%assign" is for variable numbers, "%define" is a text define - the L = L + 2 isn't going to work. What's more, a label offset is a relocatable value, not really a "constant". But I *think* something like this will do what you want...

%assign %%L 2
%rep 3
DW Array + %%L
%assign %%L %%L + 2
%endrep

(I'm not sure why you start at 2... skipping the first (0) entry?) Anyway... give that a try and see if it works.

Best,
Frank

Alfonso V

  • Guest
Re: Is there any one there?
« Reply #2 on: December 13, 2004, 09:18:45 AM »
Hi Frank

Yes, it works, thank you. This short code I put here was from my memory... I used %assign in original code too. Anyway '%assign' seems not support label offset (others compilers does) but we can use it with 'DW', that's the way. I skeep firts two bytes because it should be a pointer to next data (if the first word is zero there's no data forward)

Cheers
alfonso

nasm64developer

  • Guest
Re: Is there any one there?
« Reply #3 on: December 13, 2004, 01:54:30 PM »
> '%assign' seems not support label offset

%ASSIGN merely requires that the second
argument be a critical expression.

Just treat a label relative to $$ of the
segment the label was defined in, and you
can do something like this:

1 00000000 90 nop
    2             l:
    3             %assign a l-$$
    4 00000001 01 db a