flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Calculating the size of strings and program size? |
Author |
|
wht36 08 Nov 2008, 15:01
Hello everyone, sorry for asking, I am sure these questions have been answered before, I just can't quite find the right thread with my searches...
So how do I calculate the size of strings and program size? Bascially I am trying to write a byte coder for nwscript (http://web.archive.org/web/20041021071359/www.torlack.com/index.html?topics=nwndata_ncs) using FASM's macroinstructions. However this is the first time I am trying to write my own macros... For example Code: ; macro to code bytes macro CONSTS op1, op2, [string] ;Place Constant String Onto the Stack { db 4,5 ; byte code for CONSTS in nwscript dd .... ; <---- size of string goes here db string } ; header db "NCS V1.0B" dd .... ; <---- size of program goes here I think I need to use $ - . or sizeof.xxx , but I am not quite sure how to use them... Please help! |
|||
08 Nov 2008, 15:01 |
|
windwakr 08 Nov 2008, 15:26
for string size do something like
Code: string db 'Hello, World!',0 stringsize dd $-string-1 The minus one makes up for the extra zero at end. |
|||
08 Nov 2008, 15:26 |
|
wht36 08 Nov 2008, 15:37
Thanks! But the size of string needs to be assigned before the actual string is defined though (kind of like PASCAL style string).
|
|||
08 Nov 2008, 15:37 |
|
wht36 08 Nov 2008, 16:08
Thanks very much, I applied a similar thing to get the size of program, and tested out just now, worked very nicely (assembled and decompiled to same output). Thanks again!
One thing though, is it possible to make a macro for the header so that I can make the file into an include file? (instead of putting a label for the start and a constant to calculate the size at the end of each program) For example Code: macro header { db "NCS V1.0B" dd .... ; <---- size of program goes here } |
|||
08 Nov 2008, 16:08 |
|
baldr 08 Nov 2008, 16:17
wht36,
In short, no. How assembler supposed to know program size before it translates the source? |
|||
08 Nov 2008, 16:17 |
|
wht36 08 Nov 2008, 16:48
Sigh... I suppose not. I will probably have to make two macros, one to put at the start and the other at the end....
|
|||
08 Nov 2008, 16:48 |
|
baldr 08 Nov 2008, 17:05
wht36,
Beware of org, you may wish to redefine it too. |
|||
08 Nov 2008, 17:05 |
|
wht36 08 Nov 2008, 22:38
Thanks for your advice! I will keep it in mind and hope I don't need to redefine it.
For those who also play the game Neverwinter Nights, I've uploaded the bytecoder to http://nwvault.ign.com/View.php?view=Other.Detail&id=1357 |
|||
08 Nov 2008, 22:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.