define format db ; or display

macro put p&
  match =db, format
    db p
  else match =display, format
    display p
  end match
end macro

macro put_n n
  local x, z, v, c
  x=n
  z=0
  v=1000000000000000000
  while v>0
    c=x/v
    z=z+c
    if z | v=1
      put c+'0'
      x=x-c*v
    end if
    v=v/10
  end while
end macro

macro put_h n
  local c
  c=0
  repeat 8
    c=(n and ($F shl ((8-%)*4))) \
      shr ((8-%)*4)+'0'
    if c>'9'
      c=c+7
    end if
    put c
    if (%<>8 & ((%*4) and 31)=0)
      put ' '
    end if
  end repeat
end macro

macro put_b n
  repeat 32
    put '0'+((n shr (32-%)) and 1)
  end repeat
end macro

macro put_f p&
  match &=r, p
    put $D, $A
  else match `name, p
    put `name
  else match n&base, p
    match =d, base
      put_n n
    else match =h, base
      put_h n
    else match =b, base
      put_b n
    else
      err 'Invalid format'
    end match
  else
    if p eqtype ''
      put p
    else
      err 'Invalid format'
    end if
  end match
end macro

macro displayf p&
  irp x, p
    put_f x
  end irp
end macro