Forum
Is possible to do this? - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: Is possible to do this? (/showthread.php?tid=878)



Is possible to do this? - maeloterkim - 04-30-2019

Hi : ) I want to do something like this

iniSuperSub:
SUB mySuperSub()
....
...
....
END SUB
endSuperSub:

SUB otherSub()
ASM
defs 6144-(@endSuperSub - @iniSuperSub),0
END ASM
END SUB

The compiler says -> Error: illegal preprocessor character '@'

I want to do in assembler -> defs (6144 - size mySuperSub ), 0

There is some way to do something like this?

Thanks


Re: Is possible to do this? - boriel - 04-30-2019

Not sure why do you need that, but the compiler reallocates functions and subs at the end of the program, so @endSuperSub - @iniSuperSub = 0
You have to put the labels within the function body.

Within an ASM context, don't use @. Use just the label name, prefixing it with '_'.

So use:
Code:
SUB mySuperSub()
  REM this label goes *inside* the sub or it will not work as you expect
iniSuperSub:
...
...
...
  REM this label goes *inside* the sub or it will not work as you expect
endSuperSub:
END SUB

SUB otherSub()
  ASM
    defs 6144-(_endSuperSub - _iniSuperSub),0
  END ASM
END SUB

Also, not sure if defs will work here instead of db or dw...


Re: Is possible to do this? - maeloterkim - 04-30-2019

I'ts not working either with "_"

Well i try to figure out, how manage better, where to put things

I need space in at exactly number of memory and i don't know if there are directives like in assembler ORG

to control better, where are every thing Smile

I'm looking the generated memory map but is a little mess Smile

If i want per example, n bytes of space beginning on 43456

Can i do that with some directive?


Re: Is possible to do this? - boriel - 05-01-2019

When doing things like this, just compile with --asm flag to see the resulting asm file, and examine it.
I was wrong: you have to prefix ("mangle") you labels in ASM, with __LABEL__. So this should work:
Code:
SUB mySuperSub()
  REM this label goes *inside* the sub or it will not work as you expect
iniSuperSub:
...
...
...
  REM this label goes *inside* the sub or it will not work as you expect
endSuperSub:
END SUB

SUB otherSub()
  ASM
    defs 6144-(__LABEL__endSuperSub - __LABEL__iniSuperSub),0
  END ASM
END SUB



Re: Is possible to do this? - maeloterkim - 05-01-2019

Yes this __LABEL__ before works Smile

Thanks