flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Whats wrong with a ShowHex macro

Author
Thread Post new topic Reply to topic
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
Number display macros by the others i've found thus based on:
www.board.flatassembler.net/topic.php?t=86&start=0
www.board.flatassembler.net/topic.php?t=3979&start=0
www.board.flatassembler.net/topic.php?t=4906&start=0
www.kolibrios.org
www.fasmlib.x86asm.net/fasmlib-0.8.0-dev.zip

It would be cool to have a hex dumper in display window:
Code:
$xxxx'xxxx: 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,
$xxxx'xxxx: 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,
    

So the macro and its usage examples:
Code:
; val   = 0..2^64-1
; merge = 0<bytes<9 of value to show
; example: repeat 8
;            display 13,10
;            ShowHex $FEDCBA9876543210,%
;          end repeat
macro ShowHex val*, merge*{
  if merge > 0 & merge < 9
    local .a, .merge
    .merge = merge shl 1
    while .merge <> 0
      .a = (val) shr ((.merge - 1) * 4) and 1111b or 11'0000b
      if .a > 11'1001b
        .a = .a + 111b
      end if
      display .a
      .merge = .merge - 1
    end while
  end if
}
    

Making an expression remember operator priority:
www.flatassembler.net/docs.php?article=manual#_1.4
%fasm%\fasm.pdf, pg15
Here is a small example:
www.board.flatassembler.net/topic.php?t=9680


Last edited by edemko on 17 May 2010, 21:33; edited 1 time in total
Post 15 May 2010, 22:49
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
solved )+
watch a post over
ps. i've visited it about 20 times and this is thanks a desire and wireless modem disconnections
solved Smile#
Post 17 May 2010, 12:13
View user's profile Send private message Reply with quote
edemko



Joined: 18 Jul 2009
Posts: 549
edemko
edit
ShowFloat corrected a bit.
baldr, your macro amused me esp digit scrambling.


Code:
; val   = 0..2^64-1
; merge = 0<bytes<9 of value to show
; example: repeat 8
;            display 13,10
;            ShowHex $FEDCBA9876543210,%
;          end repeat
macro ShowHex val*, merge*{
  if merge > 0 & merge < 9
    local .a, .merge
    .merge = (merge) shl 1
    while .merge <> 0
      .a = (val) shr ((.merge - 1) * 4) and 1111b or 11'0000b
      if .a > 11'1001b
        .a = .a + 111b
      end if
      display .a
      .merge = .merge - 1
    end while
  end if
}




;display 13,10,'dd 0.1: '
;ShowFloat dd 0.1
;
;display 13,10,'dq 0.1: '
;ShowFloat dq 0.1
;
;display 13,10,'dt 0.1: '
;ShowFloat dt 0.1
;
;display 13,10,'3.1416: '
;ShowFloat dt 3.14159265358979323
macro ShowFloat command*{
  local .a
  virtual at 0
    command
    if $=4
      load .a dword from 0
      ShowHex .a,4
    else if $=8
      load .a qword from 0
      ShowHex .a,8
    else if $=10
      load .a word from 8
      ShowHex .a,2
      display "'"
      load .a qword from 0
      ShowHex .a,8
    end if
  end virtual
}




;display 13,10,13,10,'not colored, 4 bytes per address, no byte dump, yes ansi dump, width=1'
;dump _START,_END-_START,0,4,0,1,1
;display 13,10,13,10,'colored, 4 bytes per address, yes byte dump, no ansi dump, width=2'
;dump _START,_END-_START,1,4,1,0,2
;display 13,10,13,10,'colored, 8 bytes per address, yes byte dump, yes ansi dump, width=3'
;dump _START,_END-_START,1,8,1,1,3
;display 13,10,13,10,'not colored, 0 bytes per address, yes byte dump, no ansi dump, width=16'
;dump _START,_END-_START,0,0,1,0,16
;display 13,10,13,10,'not colored, 0 bytes per address, no byte dump, yes ansi dump, width=64'
;dump _START,_END-_START,0,0,0,1,64
;display 13,10,13,10,'not colored, 0 bytes per address, no byte dump, no ansi dump, width=0'
;dump _START,_END-_START,0,0,0,0,0
macro dump start*, count*, funky_colored?*, address*, show_dump?, show_text?*, width*{
  ;whether the weather is good ?
  if count<>0 & (address<>0 | show_dump?<>0 | show_text?<>0) & width<>0
     local .offset,.a
     .offset = 0
     ;dumper submacro
     macro dump _count\{
       if _count<>0
       ;new line
   display 13,10
       ;funky_colored?
     if funky_colored?<>0
    if .offset and 10000b = 0
             display "'"
    else
          display ';'
     end if
    end if
      ;address
    ShowHex start+.offset,address
       ;show_dump
  if show_dump?<>0
        display ';'
       repeat _count
         display ' '
       load .a byte from start+.offset
             .offset = .offset+1
         ShowHex .a,1
      end repeat
          times (width)*3-_count*3 display ' '
    end if
      ;show_text?
         if show_text?<>0
        display '; '
      if show_dump?<>0
        .offset = .offset-_count
          end if
      repeat _count
         load .a byte from start+.offset
             .offset = .offset+1
         if .a<32
           .a = '.'
        end if
      display .a
        end repeat
        end if
       end if
     \}
     ;whole lines
     repeat (count)/(width)
       dump width
     end repeat
     ;fractional line
     dump (count) mod (width)
     ;free macro
     purge dump
  end if
}

    


Last edited by edemko on 31 May 2010, 05:56; edited 1 time in total
Post 30 May 2010, 12:02
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
edemko,

Incomplete lines in dump can be handled inside main repeat:
Code:
db "Hello, world!", 13, 10, "I have a message for you."

macro display_digit [val] { display '0'+val+('A'-'0'-10)*(9-val) shr 63 }

repeat ($+15) and not 15
  if %-1<$; in range
    load b from %-1
    display_digit b shr 4 and 15, b and 15
  else; out of range
    display '  '
  end if
  if % and 15 = 0
    display ' |'
    line_start_offset = (%-1) and not 15
    repeat 16
      if line_start_offset+%-1<$; in range
        load b from line_start_offset+%-1
        display (b*(31-b) shr 63) or ('.'*(b-32) shr 63)
      else; out of range
        display ' '
      end if
    end repeat
    display '|', 13, 10
  else if (%-1) and 7 = 7; bells'n'whistles
    display '|'
  else if (%-1) and 3 = 3
    display "'"
  else
    display ' '
  end if
end repeat    
This way you can eliminate duplicating and submacro.
Post 30 May 2010, 14:32
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.