flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > HEX.INC converted from fasmg to fasm 1 |
Author |
|
Tomasz Grysztar 09 Dec 2017, 20:43
This is a direct conversion of the set of macros that allow to generate Intel HEX output format:
Code: format binary as 'hex' virtual at 0 HEX.digits:: db '0123456789ABCDEF' end virtual macro HEX.byte value { HEX.checksum = (HEX.checksum + (value)) and 0FFh local digit load digit byte from HEX.digits:(value) shr 4 db digit load digit byte from HEX.digits:(value) and 0Fh db digit } macro HEX.line length,address,type,bytes_low,bytes_high { HEX.checksum = 0 db ':' HEX.byte length HEX.byte (address) shr 8 HEX.byte (address) and 0FFh HEX.byte type HEX.data = bytes_low repeat length HEX.byte HEX.data and 0FFh if % = 8 HEX.data = bytes_high else HEX.data = HEX.data shr 8 end if end repeat HEX.data = (-HEX.checksum) and 0FFh HEX.byte HEX.data db 13,10 } macro HEX.seg address:0 { virtual at address } macro HEX.endseg { local code,address,size,bytes_low,bytes_high,tmp code:: address = $$ size = $-$$ end virtual while size if size > 16 load bytes_low qword from code:address load bytes_high qword from code:address+8 HEX.line 10h,address,0,bytes_low,bytes_high address = address + 16 size = size - 16 else if size > 8 load bytes_low qword from code:address load bytes_high qword from code:address+size-8 bytes_high = bytes_high shr (8*(16-size)) else bytes_high = 0 if size = 0 bytes_low = 0 else if size = 1 load bytes_low byte from code:address else if size = 2 load bytes_low word from code:address else if size = 3 load bytes_low word from code:address load tmp byte from code:address+2 bytes_low = bytes_low + tmp shl 16 else if size = 8 load bytes_low qword from code:address else load bytes_low dword from code:address load tmp dword from code:address+size-4 bytes_low = bytes_low or tmp shl (8*(size-4)) end if end if HEX.line size,address,0,bytes_low,bytes_high break end if end while } macro org address { if $ <> address HEX.endseg HEX.seg address end if } HEX.seg postpone { HEX.endseg HEX.line 0,0,1,0 } |
|||
09 Dec 2017, 20:43 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.