Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; macro to mimic the HEX feature of asm6
- .macro hex data
- .local strlen
- .local nib
- .local hiNib
- .local hiNibReady
- ; .strlen will error if user passed us something that is not a string. (good)
- strlen = .strlen( data )
- hiNibReady .set 0
- ; check each character in the string and turn into bytes
- .repeat strlen, I
- nib .set .strat(data, I)
- ; allow space or underscore or $, but ignore them.
- .if .not ( nib = ' ' .or nib = '_' .or nib = '$')
- ; convert nib if in range for 0..9 or A..F or a..f
- .if nib >= 48 .and nib <= 57
- nib .set nib - 48
- .elseif nib >= 65 .and nib <= 70
- nib .set nib - 55
- .elseif nib >= 97 .and nib <= 102
- nib .set nib - 87
- .else
- .error "Invalid character in hex byte."
- .endif
- ; create a byte if ready
- .if hiNibReady
- .byte hiNib | nib
- hiNibReady .set 0
- .else
- ; if lone nybble at the end of the string, treat it as a byte
- .if I + 1 = strlen
- .warning "Incomplete hex byte at end of data."
- .byte nib
- .else
- hiNib .set nib << 4
- hiNibReady .set 1
- .endif
- .endif
- .endif
- .endrepeat
- .endmacro
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement