flat assembler
Message board for the users of flat assembler.

Index > Main > x86 Display difference between two offsets during assembly

Author
Thread Post new topic Reply to topic
Riemann



Joined: 04 Jul 2021
Posts: 1
Riemann 04 Jul 2021, 20:55
Greetings and salutations.

Can't for the life of me figure out how to use the "display" command in fasm. Need to display the difference between two offsets in my code (in the Compile Display after assembly).

I have found the $-operator in the docs, but seems to need some formatting;

Example:

Code:

_cpybuf:
        push edi
        push esi
        push ecx                        ;Contains src buffer adr

        display "unsigned long sniplet12=(unsigned long)(reserved_mem_adr)+49200+(%$-_cpybuf+1);"
        mov edi, _beggadst          ;Offset: , Need do set this to reserved_mem_adr
        mov esi, ecx  

    



Where (%$-_cpybuf+1) is expanded into 4, ie I want the folllowing string to appear in the compile messages window:

Code:
unsigned long sniplet12=(unsigned long)(reserved_mem_adr)+49200+4;    


I'm in format PE if that makes any difference.

The 4 is 3xpush + first byte of mov edi
Any thoughts or help appreciated!
Post 04 Jul 2021, 20:55
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 04 Jul 2021, 21:25
display is only capable of display a sequence of characters with given codes. To achieve the behaviour you wish it should be redeclared as a macro.

To make the macro parse its string parameter you might want to do something like
Code:
macro display Message*
{
  local ..StringData, c
  …
  virtual
    ..StringData::
      db Message
    ..StringData.Length = $ - ..StringData
  end virtual
  …
  repeat ..StringData.Length
    load c byte from StringData:% - 1
    ; Finite state machine logic to parse the string goes here
  end repeat
  …
}    


A complete specification of what placeholders might occur in the string should better be written.

Another solution (which, I guess, is more efficient) is to make a macro that accepts arbitrary number of parameters, outputs string ones as is, but whenever a parameter is prepended with special symbol (say, “:”) it gets converted to its string representation this way or another. Hexadecimal and decimal are the two representations that are needed most of the time.
Post 04 Jul 2021, 21:25
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20571
Location: In your JS exploiting you and your system
revolution 04 Jul 2021, 21:32
You can do the computation of the value first and then call a decimal conversion macro.
Code:
macro my_decimal_display value {
  ;... some loop to convert to decimal and display the digits
}

sniplet12 = (reserved_mem_adr)+49200+($-_cpybuf+1)

display "The value of sniplet12 is "
my_decimal_display sniplet12
display 13,10    
Post 04 Jul 2021, 21:32
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20571
Location: In your JS exploiting you and your system
revolution 05 Jul 2021, 20:41
I found some old code with this macro:
Code:
macro display_decimal value {
    local leading_zero,digit,divisor,number
    number=value
    if number=1 shl 63
        display '-9223372036854775808'
    else
        if number<0
            number=-number
            display '-'
        end if
        leading_zero=0
        divisor=1000000000000000000
        while divisor>0
            digit=number/divisor
            leading_zero=leading_zero+digit
            if leading_zero | (divisor=1)
                display digit+'0'
                number=number-digit*divisor
            end if
            divisor=divisor/10
        end while
    end if
}    
I haven't tested it. I might even work. Razz
Post 05 Jul 2021, 20:41
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.