flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
wht36
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! |
|||
![]() |
|
windwakr
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. |
|||
![]() |
|
wht36
Thanks! But the size of string needs to be assigned before the actual string is defined though (kind of like PASCAL style string).
|
|||
![]() |
|
wht36
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 } |
|||
![]() |
|
baldr
wht36,
In short, no. How assembler supposed to know program size before it translates the source? |
|||
![]() |
|
wht36
Sigh... I suppose not. I will probably have to make two macros, one to put at the start and the other at the end....
|
|||
![]() |
|
baldr
wht36,
Beware of org, you may wish to redefine it too. |
|||
![]() |
|
wht36
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 |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.