Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bitRAKE
Created May 11, 2022 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitRAKE/76a8719eeb29c983a98302322a2815f9 to your computer and use it in GitHub Desktop.
Save bitRAKE/76a8719eeb29c983a98302322a2815f9 to your computer and use it in GitHub Desktop.
Create data statement from binary file.
; Make data statements from file (don't use this - just use FILE directive).
calminstruction hex_nibble digit*, command: display
compute digit, 0FFh and '0123456789ABCDEF' shr (digit*8)
arrange command, command digit
assemble command
end calminstruction
define _db
calminstruction data_dump bytes*, i:0, cmd:display
local awk, digit
jj: arrange awk, =load =_db:1 =from =DAT:i
assemble awk
arrange awk, cmd '0x'
assemble awk
compute digit, (_db shr 4) and 0Fh
call hex_nibble, digit, cmd
compute digit, _db and 0Fh
call hex_nibble, digit, cmd
compute i, i + 1
check i = bytes
jyes done
arrange awk, cmd ','
assemble awk
check i and 0Fh
jyes jj
arrange awk, cmd '\',13,10
assemble awk
jump jj
done: arrange awk, cmd 13,10
assemble awk
end calminstruction
if definite FILE
virtual at 0
DAT::
file FILE
BYTES := $
end virtual
db '; ',FILE,13,10
repeat 1,D:BYTES
db 'label dat:',`D,13,10
end repeat
db 'db \',13,10
data_dump BYTES,,db
else
display 'usage: fasmg -i "define FILE ''<filename>''" ',__FILE__,' <outfile>'
end if
@bitRAKE
Copy link
Author

bitRAKE commented May 11, 2022

Potential problems with code (ignoring its overall silliness):

  1. processing a zero length file.
  2. no buffering of large file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment