Author Topic: extending TIMES  (Read 12277 times)

Offline ras

  • Jr. Member
  • *
  • Posts: 8
extending TIMES
« on: February 24, 2010, 07:28:31 AM »
anyways, been using nasm for a very very long time
have a couple bugs, a couple work-arounds [eg. using earlier releases in some instances]
but my current dilemna is with TIMES
here i was thinking this was a macro, opened nasm in HeD couldnt find the def
downloaded the source...
still couldn't find the def, now i realize that times is a special case
it is handled directly by the preprocessor[?] and not by/as the/a macro facilities.

prev:
times 4 db 0 <--- works
times $-prev db 0 <--- works

what i want is a method of accessing not scalar values on the first part
but scalar values after the db or w/e im using

times 4 db %offset
hence db 0, 1, 2, 3

i tried times 4 db $ ... but nasm doesnt like single-byte scalar output
times 4 dw/dd $ works, but there's no base override i can get working in -f bin [havent tried org ###]

what i am using currently for a blank xlat table is...

%macro   _xlat   0
   %assign   i   0
   %rep   256
      db   i
      %assign   i   i+1
   %endrep
%endmacro

_xlat

^ the above works, but i would really like to see TIMES able to access it's repetition count as a named parameter
thx ill drop some more slightly more fanatical macro requests on you soon maybe ';]

Offline ras

  • Jr. Member
  • *
  • Posts: 8
Re: extending TIMES
« Reply #1 on: February 24, 2010, 06:44:10 PM »
pimpin, got a suitable macro up. still would prefer TIMES being able to do this but...

%macro   _times   2+
   %assign   i   0
   %rep   %1
      %2
      %assign   i   i+1
   %endrep
%endmacro   

_times   4,   db   i*2

[not advanced really lol but still useful, i was having a blonde moment @ the end of %1, and start of %2... eg. the ,]

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: extending TIMES
« Reply #2 on: February 24, 2010, 06:57:07 PM »
Great! No guarantee that your requests will be fulfilled, however. :)

Your "_xlat" macro works when converted to take a "length" or "size" parameter. But a "non-scalar" value isn't going to work.

Nasm never documents (AFAIK) what a "scalar" value is. A "non-scalar" value - a label, or "$", for example - is one which is going to be changed by the linker and/or loader. Nasm doesn't know what this value is going to be at runtime, and can use it only in situations where this isn't going to be a problem - *not* where it's going to affect the size of the code! Nasm can cope with an unknown value, but not with an unknown size. So a non-scalar (relocatable) value is never going to work as an argument to "times"... and a few other places.

My first thought was that "times 4 db $" wasn't going to work, because "$" is going to change with each repetition, and "times" can't cope. That isn't it, though. "times 4 dd $" does work, but "$" is evaluated only once, and the value repeated 4 times. Probably not useful. I'm not sure why "dd" works, but "db" makes Nasm think you're doing a one-byte relocation.

Code: [Select]
%macro   _xlat   1
   %assign   i   0
   %rep   %1
      db   i
      %assign   i   i+1
   %endrep
%endmacro


org 100h

nop
nop
_xlat $ - $$
;_xlat $ ; no work!

times 4 dd $
; times 4 db $ ; no work!

times $ - $$ db 42

times 4 db $-$$

I don't know if that leaves you any better off...

FWIW, if you encounter a situation that requires you to revert to an earlier version, please let us know - it is generally intended *not* to break existing code, so it's probably a bug.

Best,
Frank


Offline Keith Kanios

  • Full Member
  • **
  • Posts: 383
  • Country: us
    • Personal Homepage
Re: extending TIMES
« Reply #3 on: February 24, 2010, 07:48:03 PM »
FWIW, if you encounter a situation that requires you to revert to an earlier version, please let us know - it is generally intended *not* to break existing code, so it's probably a bug.

Unless we find that the code inappropriately relies on a bug that was squashed :D