Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. ; macro to mimic the HEX feature of asm6
  2.  
  3. .macro hex data
  4.  
  5. .local strlen
  6. .local nib
  7. .local hiNib
  8. .local hiNibReady
  9.  
  10. ; .strlen will error if user passed us something that is not a string. (good)
  11. strlen = .strlen( data )
  12. hiNibReady .set 0
  13.  
  14. ; check each character in the string and turn into bytes
  15. .repeat strlen, I
  16.  
  17. nib .set .strat(data, I)
  18. ; allow space or underscore or $, but ignore them.
  19. .if .not ( nib = ' ' .or nib = '_' .or nib = '$')
  20.  
  21. ; convert nib if in range for 0..9 or A..F or a..f
  22. .if nib >= 48 .and nib <= 57
  23. nib .set nib - 48
  24. .elseif nib >= 65 .and nib <= 70
  25. nib .set nib - 55
  26. .elseif nib >= 97 .and nib <= 102
  27. nib .set nib - 87
  28. .else
  29. .error "Invalid character in hex byte."
  30. .endif
  31.  
  32. ; create a byte if ready
  33.  
  34. .if hiNibReady
  35. .byte hiNib | nib
  36. hiNibReady .set 0
  37. .else
  38. ; if lone nybble at the end of the string, treat it as a byte
  39. .if I + 1 = strlen
  40. .warning "Incomplete hex byte at end of data."
  41. .byte nib
  42. .else
  43. hiNib .set nib << 4
  44. hiNibReady .set 1
  45. .endif
  46. .endif
  47. .endif
  48.  
  49. .endrepeat
  50.  
  51. .endmacro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement