flat assembler
Message board for the users of flat assembler.

Index > Main > idata error!

Author
Thread Post new topic Reply to topic
Kenny80



Joined: 08 May 2005
Posts: 22
Kenny80 09 Aug 2006, 10:32
Found this code on board here somewhere, can't find orginial post again!

Code:
;===============================================================================
;       integer to ASCII conversion procedure
;
;       input:
;       number - number to convert Smile
;       radix - base system like 10 for decimal, 16 for hexadecimal, etc.
;       result_buffer - pointer to memory where output will be saved
;       signed - bool value, if number is signed (-2147483646...2147483647)
;                or unsigned (0...4294967295)
;
;       output:
;       no immediate output
;
;       possible errors:
;       radix exceeds 16
;
;       coded by Reverend // HTB + RAG
;===============================================================================
proc    itoa                    number, radix, result_buffer, signed
locals
  temp_buffer                   rb 32+1
endl
        pushad
        mov     esi, [radix]
        lea     edi, [temp_buffer+32]
        mov     ebx, itoa.digits
        cmp     esi, 16
        ja      .error
        std
        xor     al, al
        stosb
        mov     eax, [number]
        cmp     [signed], TRUE
        jnz     @F
        test    eax, 80000000h
        jz      @F
        neg     eax
    @@:
        xor     edx, edx
        idiv    esi
        xchg    eax, edx
        xlatb
        stosb
        xchg    eax, edx
        test    eax, eax
        jnz     @B
        lea     esi, [edi+1]
        mov     edi, [result_buffer]
        cld
        cmp     [signed], TRUE
        jnz     @F
        test    [number], 80000000h
        jz      @F
        mov     al, '-'
        stosb
    @@:
        lodsb
        stosb
        test    al, al
        jnz     @B
        sub     edi, [result_buffer]
        lea     eax, [edi-1]
        stc
  .theend:
        cld
        popad
        ret
  .error:
        clc
        jmp     .theend
endp

idata
  itoa.digits                   db '0123456789ABCDEF', 0
endg    


problem i got is that fasm complain about the "idata" at end, my questions is how do i add a idata section to "outside" asm or inc files and on same time get fasm to understand that all idata sections shall be combined to one when program is created?

if i remove the idata section then it will end up in .code section which is wrong!

masm had this function of understanding this, but sure fasm has it also, i jsut haven't found it yet!
Post 09 Aug 2006, 10:32
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 09 Aug 2006, 10:38
it is about globals data macros: check fasmlib if there is such include - it seems it used there. (idata here - initialized data, udata - unitialized)
Post 09 Aug 2006, 10:38
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Aug 2006, 10:49
it's file fasmlib/fasmlib/data.inc. If you want just idata/udata macros, you have them here:
Code:
macro idata arg
{
  __IData equ __IData,   ;add one ',' to __IData, initial "__IData" before ','s will be used to call macro
  macro __IDataBlock     ;begin macro (or overload old one) which holds data inside "idata" block
  arg
}

macro udata arg
{
  __UData equ __UData,
  macro __UDataBlock
  arg
}

;include all "idata"-defined blocks
macro IncludeIData
{
  macro __IData dummy,[n]  ;create macro which will be invoked, [n] makes sure macro's forward will
  \{                       ;be preprocessed for each ',' added to __IData
    \forward
       __IDataBlock        ;use the macro with data
       purge __IDataBlock  ;and remove it so previous macro becomes avilable
  \}
  match I, __IData \{ I \} ;and now unroll __IData macro (just "__IData" wouldn't do, replaced equate isn't
                           ;preprocessed anymore and so it wouldn't beheave as macro usage)
  purge __IData            ;__Idata macro is not needed anymore
}


;include all "udata"-defined blocks
macro IncludeUData         ;... same as IncludeIData but it is whole in virtual to count size and define labels
{                          ;and then required space is reserved
  macro __UData dummy,[n]
  \{
    \common
       \local ..begin, ..size
       ..begin = $
       virtual at $
    \forward
       __UDataBlock
       purge __UDataBlock
    \common
       ..size = $ - ..begin
       end virtual
       rb ..size
   \}
  match U, __UData
  \{
    U
  \}
  purge __UData
}

;use both macros at least once
idata{}
udata{}    


if you don't want these macros at all, then just copy-pase itoa.digits db '0123456789ABCDEF', 0 line into you data section :]
Post 09 Aug 2006, 10:49
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Kenny80



Joined: 08 May 2005
Posts: 22
Kenny80 09 Aug 2006, 11:10
my mistake i read wrong, dosen't complain about idata it complains about line below idata the "digits db '0123456789ABCDEF',0" and error is "unexpected characters." , i haven't modified source more than changing inc files, removed a extra.inc since i don't have it and added fasmlib,inc instead, since same author who made source and fasmlib.inc!

sorry for being such pain in ass but really need to know how, make my life bit easier Very Happy
Post 09 Aug 2006, 11:10
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 09 Aug 2006, 11:18
you may just place this string li procedure body:
Code:
..
        mov     ebx, .digits 
..
        jmp     .theend 
.digits                   db '0123456789ABCDEF'
endp     

16 bytes in code section will not change weather and even could work faster Wink
Post 09 Aug 2006, 11:18
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Aug 2006, 12:10
Quote:
if i remove the idata section then it will end up in .code section which is wrong!

why? it probably won't be faster (there is different cache for code and for data i think), but it is commonly used...
Post 09 Aug 2006, 12:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 09 Aug 2006, 12:31
FlatAssembler ...


My apps usually have nothing but '.flat' section made by default if no sections specified |:


edit: uh, did re-read my post and point of it isnt clear I think.
I would include digits inside proc with jmp .over / .digits db '...',0 / .over:
Post 09 Aug 2006, 12:31
View user's profile Send private message MSN Messenger Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 09 Aug 2006, 12:48
btw, what a sense in termination zero here Wink
Post 09 Aug 2006, 12:48
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Aug 2006, 14:49
yeah, and what a waste of byte Wink

that 0 has uncountable advantages... for example when you loose your source andwant to get it back from binaries using IDA, you just have to push 'a' instead of complicated block manipaluation.

Not mentioning that ending string with 0 conforms so many standards, and it lessens chance of reading instruction as data...
Post 09 Aug 2006, 14:49
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Kenny80



Joined: 08 May 2005
Posts: 22
Kenny80 10 Aug 2006, 18:49
vid wrote:
Quote:
if i remove the idata section then it will end up in .code section which is wrong!

why? it probably won't be faster (there is different cache for code and for data i think), but it is commonly used...


write wrong was bit to strong word for what i meant, my point is that if i want change value then it won't work since it's in .code section, of course i can change .code section to allow it but i like to have all stuff in correct section hehe, ya i'm annoying but that's how i like it Wink

i don't want or need a lection in why just simple how Smile thank you!
Post 10 Aug 2006, 18:49
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Aug 2006, 06:25
well, then idata/udata macros are here just for you
Post 11 Aug 2006, 06:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Kenny80



Joined: 08 May 2005
Posts: 22
Kenny80 11 Aug 2006, 09:07
Lets try this last time shall we!

Code:
idata
  itoa.digits                   db '0123456789ABCDEF'
endg    


do anyone of u see anything wrong with above line, as i look at it i don't see any error with it, any typo error or missing char / to many char somewhere?

since fasm still complains about line that there is a "unexpected char", but where is it??

pure simple question, as all i want is a simple answer if there is a error, please type a working "this is how it should be" example then!

and not off topic answer about my ending zero or why your mom have big panties! Wink

(yes this is of topic sorta)
i give you exampl,e lets say you are late for work and you can't get your car to start, you call mechanic then you don't want 20 min long explanation why your car dosen't start, you only want the answer for the fix or if he can fix it!


ok now u know my position here haha, just simple answer and i deal with rest why it happend so on!

i noticed if you ask long question then u will get even longer answer, guess keep it short if you don't have all day reading! Cool
Post 11 Aug 2006, 09:07
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Aug 2006, 09:28
this is how it should be:
Code:
idata {
  itoa.digits                   db '0123456789ABCDEF'
}    


PS: all ideas here are worth of reading, and you should show little more thank for helping. You will be surprised, but you are not only one who has little time. And still we spend our time helping people like you, so waste some of precious time thinking about it Wink
Post 11 Aug 2006, 09:28
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Kenny80



Joined: 08 May 2005
Posts: 22
Kenny80 11 Aug 2006, 18:48
ya you right, just me who was bit pissed on problem, thx for all help, couldn't done it without you all!

cheers!
Post 11 Aug 2006, 18:48
View user's profile Send private message Reply with quote
0x4e71



Joined: 25 Feb 2004
Posts: 50
0x4e71 11 Aug 2006, 19:36
vid wrote:


that 0 has uncountable advantages... for example when you loose your source andwant to get it back from binaries using IDA, you just have to push 'a' instead of complicated block manipaluation.


Fully subscribe to that.
<rant>
Years ago I decided to reverse my favorite assembler in order to improve it and fix some of its horrible bugs. To my "delight" I discovered that instead of using "0", this program marked string termination by setting the 8th bit of the last character in the string (since the move instruction on that CPU affected the flags too, this technique allowed very "clever" and compact string manipulation code). This fact alone provided several hours of "fun" (not) plus the need to write a bunch of ad-hoc mini programs just to descramble all string data.... time you can better spend doing other stuff! Confused
</rant>
Post 11 Aug 2006, 19:36
View user's profile Send private message 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.