flat assembler
Message board for the users of flat assembler.
  
       
      Index
      > Macroinstructions > [CALM] Error when stringify negative number | 
  
| Author | 
  | 
              
| 
                  
                   Tomasz Grysztar 05 May 2021, 22:29 
                  The error is given by ARRANGE, not STRINGIFY (and it is a documented limitation of ARRANGE). The routine that converts numeric value to a decimal token only works for non-negative values (this also affects the numeric parameters defined by REPEAT/REPT, for example). 
                  
                 | 
              |||
                  
  | 
              
| 
                  
                   Tomasz Grysztar 05 May 2021, 22:37 
                  I have this snippet laying around that I can show as a demonstration of how I've been doing it myself. It uses the inline macro package but replaces the definitions of inline macros with CALM implementations:     
                  
                Code: include 'inline.inc' inlinemacro dec?() end inlinemacro calminstruction (return) inlinemacro.dec? number* compute number,+number check number < 0 jyes negative arrange number,number jump ready negative: compute number,-number arrange number,-number ready: stringify number publish return,number end calminstruction inlinemacro hex?() end inlinemacro calminstruction (return) inlinemacro.hex? value* local buffer compute buffer, '' compute value, +value loop: compute buffer, string (buffer shl 8) + '0123456789ABCDEF' shr (value shl 3 and 1111000b) and 0FFh compute value, value shr 4 check value = 0 jyes done check value = -1 jno loop compute buffer, string (buffer shl 32) + 'F..F' done: publish return, buffer end calminstruction Value = 0xcafe display 'Dec: ',DEC(Value),10,'Hex: ',HEX(Value)  | 
              |||
                  
  | 
              
| 
                  
                   zhak 05 May 2021, 23:04 
                  Thank you for the tip. This helped a lot. 
                  
                 | 
              |||
                  
  | 
              
< Last Thread | Next Thread >  | 
    
Forum Rules: 
  | 
    
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.