flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > extended display

Author
Thread Post new topic Reply to topic
Joshua



Joined: 12 Jul 2003
Posts: 56
Location: Belgium
Joshua
[update]
new macro in next post
[/update]
Code:
macro display [param]
 { forward
    if <param> eq <>
    else if param eqtype 0
     local n,d1,d2,d3,d4,d5,d6,d7,d8
     virtual
      dd param
      load n dword from $-4
     end virtual
     d1 = (n and 0Fh) shr 0
     d2 = (n and 0FFh) shr 4
     d3 = (n and 0FFFh) shr 8
     d4 = (n and 0FFFFh) shr 12
     d5 = (n and 0FFFFFh) shr 16
     d6 = (n and 0FFFFFFh) shr 20
     d7 = (n and 0FFFFFFFh) shr 24
     d8 = (n and 0FFFFFFFFh) shr 28
     if d1 >= 0 & d1 <= 9
      d1 = d1 + 48
     else if d1 >= 10 & d1 <= 15
      d1 = d1 + 55
     else
      d1 = 0
     end if
     if d2 >= 0 & d2 <= 9
      d2 = d2 + 48
     else if d2 >= 10 & d2 <= 15
      d2 = d2 + 55
     else
      d2 = 0
     end if
     if d3 >= 0 & d3 <= 9
      d3 = d3 + 48
     else if d3 >= 10 & d3 <= 15
      d3 = d3 + 55
     else
      d3 = 0
     end if
     if d4 >= 0 & d4 <= 9
      d4 = d4 + 48
     else if d4 >= 10 & d4 <= 15
      d4 = d4 + 55
     else
      d4 = 0
     end if
     if d5 >= 0 & d5 <= 9
      d5 = d5 + 48
     else if d5 >= 10 & d5 <= 15
      d5 = d5 + 55
     else
      d5 = 0
     end if
     if d6 >= 0 & d6 <= 9
      d6 = d6 + 48
     else if d6 >= 10 & d6 <= 15
      d6 = d6 + 55
     else
      d6 = 0
     end if
     if d7 >= 0 & d7 <= 9
      d7 = d7 + 48
     else if d7 >= 10 & d7 <= 15
      d7 = d7 + 55
     else
      d7 = 0
     end if
     if d8 >= 0 & d8 <= 9
      d8 = d8 + 48
     else if d8 >= 10 & d8 <= 15
      d8 = d8 + 55
     else
      d8 = 0
     end if
     display d8,d7,d6,d5,d4,d3,d2,d1,"h"
    else if param eqtype ""
     display param
    end if
   common
    display 13,10
 }
    

usage
Code:
display SomeNumber, " + ", SomeNumber, " = ", AnotherNumber    


Last edited by Joshua on 08 Nov 2003, 10:26; edited 2 times in total
Post 13 Jul 2003, 07:05
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7417
Location: Kraków, Poland
Tomasz Grysztar
You can find other similar extension (with ability to display numbers with any base) here: http://board.flatassembler.net/topic.php?t=86.
Post 22 Jul 2003, 11:00
View user's profile Send private message Visit poster's website Reply with quote
Joshua



Joined: 12 Jul 2003
Posts: 56
Location: Belgium
Joshua
I updated my display macro:
[new update 08/11/2003]
added string functions:
- CHAR
- LSTR
- RSTR
allowed more than one number to be passed to a function
ex: display <HEX 1,2,3>
[/update]

Code:
macro display [param]
 { forward
    if <param> eq <>
    else if param eqtype 0
     TEMP_DISPLAY_INT param
    else if param eqtype ""
     display param
    else
     TEMP_DISPLAY_#param
    end if
   common
    display 13,10
 }

macro TEMP_DISPLAY_CHAR [number]
 { forward
    display number
 }

macro TEMP_DISPLAY_LSTR size,[string]
 { common
    local ..c,..size
    virtual at 0
     forward
      if ~<string> eq <>
       db string
      end if
     common
      ..size = $
      if size-..size > 0
       repeat size-..size
        db 32
       end repeat
      end if
      repeat size
       load ..c byte from %-1
       display ..c
      end repeat
    end virtual
 }

macro TEMP_DISPLAY_RSTR size,[string]
 { common
    local ..c,..size
    virtual at 0
     common
      repeat size
       db 32
      end repeat
     forward
      if ~<string> eq <>
       db string
      end if
     common
      ..size = $
      repeat size
       load ..c byte from ..size-size+%-1
       display ..c
      end repeat
    end virtual
 }

macro TEMP_DISPLAY_INT [number]
 { common
    local ..n,..d,..count,..mask,..shift,..zero
    ..count = 0
   forward
    ..count = ..count+1
    if ..count > 1
     display 32
    end if
    virtual
     dd number
     load ..n dword from $-4
    end virtual
    if ..n = 0
     display 48
    else
     if ..n and 80000000h
      display 45
      ..n = -..n and 0FFFFFFFFh
     end if
     ..mask = 10000000000
     ..shift = 1000000000
     ..zero = 1
     repeat 10
      ..d = (..n mod ..mask)/..shift
      if ..d = 0
       if ~..zero
        display 48
       end if
      else if ..d >= 1 & ..d <= 9
       ..zero = 0
       display ..d+48
      else
       display 63
      end if
      ..mask = ..mask/10
      ..shift = ..shift/10
     end repeat
    end if
 }

macro TEMP_DISPLAY_UINT [number]
 { common
    local ..n,..d,..count,..mask,..shift,..zero
    ..count = 0
   forward
    ..count = ..count+1
    if ..count > 1
     display 32
    end if
    virtual
     dd number
     load ..n dword from $-4
    end virtual
    if ..n = 0
     display 48
    else
     ..mask = 10000000000
     ..shift = 1000000000
     ..zero = 1
     repeat 10
      ..d = (..n mod ..mask)/..shift
      if ..d = 0
       if ~..zero
        display 48
       end if
      else if ..d >= 1 & ..d <= 9
       ..zero = 0
       display ..d+48
      else
       display 63
      end if
      ..mask = ..mask/10
      ..shift = ..shift/10
     end repeat
    end if
 }

macro TEMP_DISPLAY_HEX [number]
 { common
    local ..n,..d,..count,..mask,..shift
    ..count = 0
   forward
    ..count = ..count+1
    if ..count > 1
     display 32
    end if
    virtual
     dd number
     load ..n dword from $-4
    end virtual
    ..mask = 0FFFFFFFFh
    ..shift = 28
    repeat 8
     ..d = (..n and ..mask) shr ..shift
     if ..d >= 0 & ..d <= 9
      display ..d+48
     else if ..d >= 10 & ..d <= 15
      display ..d+55
     else
      display 63
     end if
     ..mask = ..mask shr 4
     ..shift = ..shift-4
    end repeat
    display 104
 }
    

usage:
Code:
display "-1 as int: ",-1,\
        ", -1 as unsigned int: ",UINT (-1),\
        ", -1 as hex: ",HEX (-1),\
        ", 65 as char: ",CHAR 65,\
        ", 'blah' left aligned by 10: '",<LSTR 10,'blah'>,"'",\
        ", 'blah' right aligned by 10: '",<RSTR 10,'blah'>,"'"
    

this should result in:
Code:
-1 as int: -1, -1 as unsigned int: 4294967295, -1 as hex: FFFFFFFFh, 65 as char: A, 'blah' left aligned by 10: 'blah      ', 'blah' right aligned by 10: '      blah'
    
Post 02 Nov 2003, 11:38
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-2019, Tomasz Grysztar.

Powered by rwasa.