flat assembler
Message board for the users of flat assembler.

Index > Main > Any way to refer to the most recent global label?

Author
Thread Post new topic Reply to topic
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 12 May 2010, 21:07
Any way to refer to the most recent global label? Like a local label, but without the dot. And the label.

Code:
p_string        db      'Some string',0
 .size=$-(something that points out p_string implicitly)    

_________________
This is a block of text that can be added to posts you make.
Post 12 May 2010, 21:07
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 May 2010, 23:31
Like this?
(From FASM manual, chapter 2.3.4)
Code:
struc db [data]
{
common
. db data
.size = $ - .
}    
Post 12 May 2010, 23:31
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 12 May 2010, 23:36
So the way to go is to put the data in a struc? I guess so..
Post 12 May 2010, 23:36
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 12 May 2010, 23:57
A

Code:
struc string [data]
{
   common
        . db data
        .size = $ - .
}    


and some

Code:
p_error         string  'Parse error at '
p_success       string  $0d,$0a,'Parse successful!'    


works nicely! Thanks!

_________________
This is a block of text that can be added to posts you make.
Post 12 May 2010, 23:57
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 13 May 2010, 00:05
Dont forget the NULL terminator (if required)
You could even modify the macro to insert it automatically...
Post 13 May 2010, 00:05
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 13 May 2010, 00:21
I print those strings with WriteConsole, so instead of an end of string marker, I need the char count.
Post 13 May 2010, 00:21
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 13 May 2010, 03:37
You should use Pascal style strings http://en.wikipedia.org/wiki/String_%28computer_science%29#Representations. Just pass pointer to string +1 instead, so as to skip the char count byte.
Post 13 May 2010, 03:37
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 13 May 2010, 11:37
Yes, wherever you need dynamic length information, saving the length of the string is a good idea. Reserve a 0 at the end of the string, and you can use it anywhere.

_________________
This is a block of text that can be added to posts you make.
Post 13 May 2010, 11:37
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 13 May 2010, 17:06
I use .size thisly:

Code:
macro output ptr
{
   common
        mov     esi,ptr
        mov     eax,ptr#.size
        call    printstr
}    

Code:
output  c_lvalue    

_________________
This is a block of text that can be added to posts you make.
Post 13 May 2010, 17:06
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 14 May 2010, 09:47
Is there a way to add the name of the most recent global then the most recent local(Is the "." recursive)?
Code:
global:
.local: ; I know how this works
.local.sublocal: ; Is there a way to eliminate the need for the .local at the begginning?
    

I use labels like this to organize my code in to globals, sections, and subsections based on where the (sub)section is called from. It gets irritating after the typing .local.sublocal for every subdivision past that level.
Post 14 May 2010, 09:47
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 14 May 2010, 10:11
Post 14 May 2010, 10:11
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 15 May 2010, 01:41
And I thought I was special for my little conditional mov macro, I can't even tell what you're doing in that one Smile. Thanks, that'll work.
Post 15 May 2010, 01:41
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 16 May 2010, 15:48
Tomasz, I don't mean to be annoying, I'm sure people are suggesting "improvements" for Fasm all the time. But if you decide to implement the function of your func/endf macro achieves as built-in, I think using multiple "."s would be the most intuitive way to indicate nesting level.

Example:
Code:
global:
.local:
..sublocal:
.local2:
    

Would result in:
Code:
global:
global.local:
global.local.sublocal:
global.local2:
    

Would this interfere with any existing functionality?
Post 16 May 2010, 15:48
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 16 May 2010, 20:47
Quote:
Would this interfere with any existing functionality?

Yep. Check the manual about meaning of double-dot prefix
Post 16 May 2010, 20:47
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 16 May 2010, 22:21
Does the "@" in front of a label mean anything? I'm not going to suggest replacing ".." with "@", but if it won't interfere, I'm thinking about making a patch doing just that, and replacing the current functionality of multiple dots with what I mentioned above.
Post 16 May 2010, 22:21
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 16 May 2010, 22:30
People may have used labels starting with "@" in their code - I have already seen this couple times in real-world code.
Post 16 May 2010, 22:30
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 16 May 2010, 22:47
I wrote:

I'm not going to suggest replacing ".." with "@", [...]

It'll be a personal patch, although (if I do it) I will release it, it'll be optional to use it. If someone uses labels like that, they won't have to use my patch.
Post 16 May 2010, 22:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 May 2010, 07:26
In such case... go on! Smile
Post 17 May 2010, 07:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.