I just made a neat Python tool to help me and you code (while I doubt this will only be useful to me and Zeda):


Code:
def hexToDb(hex):
   """Takes a big endian hex string and turns it to little endian"""
   splitHex = [hex[x:x+2] for x in xrange(0,len(hex),2)]
   finalString = ".db"
   counter = 0
   for i in range(0,len(splitHex)):
      if counter==29:
         finalString+=" $"+splitHex[i]+"\n.db"
         counter = 0
      else:
         finalString+=" $"+splitHex[i]+","
      counter+=1
   return finalString[0:len(finalString)-1]
   
def main():
   print "Choose:\n1. Type hexadecimal code\n2. Open from file"
   option = input()
   if option==1:
      hexCode = raw_input("Type hexadecimal code: ")
      g = open('dbCode.txt','w')
      g.write(hexToDb(hexCode))
      g.close()
      
   else:
      fileName = raw_input("Enter name of ASCII file: ")
      f = open(fileName,'r')
      hexCode = f.read().replace(' ','').replace('\n','').replace('\r','')
      f.close()
      g = open('dbCode.txt','w')
      g.write(hexToDb(hexCode))
      g.close()
      
if __name__=='__main__':
   main()


You enter hex code like 2101000EF0745 and it returns:


Code:
.db $21, $01, $00, $EF, $07, $45


It is aware of the 31 arguments limit, so here's an example for bigger code:


Code:
.db $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77
.db $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9
.db $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D
.db $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00
.db $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40
.db $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F
.db $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48
.db $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF
.db $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00
.db $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45
.db $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72
.db $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65
.db $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A
.db $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD, $CB, $00, $AE, $21, $00, $00, $22
.db $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C, $64, $21, $00, $EF, $40, $45, $FD
.db $CB, $00, $AE, $21, $00, $00, $22, $4B, $84, $21, $AC, $9D, $EF, $0A, $45, $EF, $2E, $45, $C9, $48, $65, $6C, $6C, $6F, $20, $77, $6F, $72, $6C
.db $64, $21, $00


I also made code to turn it to .dw code and it will even make it big endian. However, it doesn't count 31 arguments (yet):


Code:
def bibEndianToLittleEndian(hex):
   """Takes a big endian hex string and turns it to little endian"""
   splitHex = [hex[x:x+4] for x in xrange(0,len(hex),4)]
   for i in range(0,len(splitHex)):
      splitHex[i] = splitHex[i][2]+splitHex[i][3]+splitHex[i][0]+splitHex[i][1]
   return "".join(splitHex)
   
def littleEndianToDw(hex):
   """Takes a little endian string as an argument and turns it to .dw blocks"""
   #.dw $CBFD,$AE00
   finalString = ".dw"
   splitHex = [hex[x:x+4] for x in xrange(0,len(hex),4)]
   for i in range(0,len(splitHex)):
      finalString+= " $"+splitHex[i]+","
   return finalString[0:len(finalString)-1]
   
def main():
   print "Choose:\n1. Type hexadecimal code\n2. Open from file"
   option = input()
   if option==1:
      hexCode = raw_input("Type hexadecimal code: ")
      g = open('dwCode.txt','w')
      g.write(littleEndianToDw(bibEndianToLittleEndian(hexCode)))
      g.close()
      
   else:
      fileName = raw_input("Enter name of ASCII file: ")
      f = open(fileName,'r')
      hexCode = f.read()
      f.close()
      g = open('dwCode.txt','w')
      g.write(littleEndianToDw(bibEndianToLittleEndian(hexCode)))
      g.close()
      
if __name__=='__main__':
   main()


What do you think?
Seems cool. What is the 31 argument limit?I've never heard of it before.
souvik1997 wrote:
Seems cool. What is the 31 argument limit?I've never heard of it before.


Zeda told me about a 31 arguments limit.
souvik1997 wrote:
Seems cool. What is the 31 argument limit?I've never heard of it before.
I've heard it's something related to TASM...
JosJuice wrote:
souvik1997 wrote:
Seems cool. What is the 31 argument limit?I've never heard of it before.
I've heard it's something related to TASM...


Eitherway, I'll leave it anyway, so we don't have GIANT lines.
Hopefully no one is using TASM at this point anymore. Smile I agree that giant lines are to be frowned upon, though. Nice tool.
KermMartian wrote:
Hopefully no one is using TASM at this point anymore. Smile I agree that giant lines are to be frowned upon, though. Nice tool.


Thanks.
ScoutDavid wrote:
KermMartian wrote:
Hopefully no one is using TASM at this point anymore. Smile I agree that giant lines are to be frowned upon, though. Nice tool.


Thanks.
You're welcome. Do you consider it complete, or are there still more things that you want to add to it?
This is pretty much complete, I just made a JavaScript version which is hosted in my website Very Happy

http://davidgom.co.cc/hexToDb.html
It makes errors:


Code:
CD 01 90 df

to

.db $CD, $01, $ 9, $0 , $df


Also, it's not a "Hexadecimal to Assembly Code" converter. Assembly code would be if my first three bytes turned into "call $9001".
Very weird spaces don't work, cos I do this:


Code:
inputText = inputText.replace('\n','').replace(' ','').replace('\r','');


Do you know if this is invalid javascript?
They work fine up until the part where I enter a byte that ends in zero.
KermMartian wrote:
They work fine up until the part where I enter a byte that ends in zero.


I tried it and there's a problem with spaces.
ScoutDavid wrote:
KermMartian wrote:
They work fine up until the part where I enter a byte that ends in zero.


I tried it and there's a problem with spaces.
Why not use regular expressions to strip out everything that isn't A-Fa-f0-9?
@Kerm: I never used regular expressions, hence I have no idea of how to that, I am, though removing spaces and lines breaks.
ScoutDavid wrote:
@Kerm: I never used regular expressions, hence I have no idea of how to that, I am, though removing spaces and lines breaks.
Just use:


Code:
newhex = oldhex.replace(/[^A-Fa-f0-9]+/g,'');
http://davidgom.co.cc/hexToDb.html

Fixed, thanks much Very Happy
ScoutDavid wrote:
You're most welcome. I just tested it out again, and my suggested fix seems to be operating very nicely.
KermMartian wrote:
ScoutDavid wrote:
You're most welcome. I just tested it out again, and my suggested fix seems to be operating very nicely.


Thanks x)
Glad you appreciate.

How can I change that regex you gave me to remove \n and line breaks too?


Code:
inputText = inputText.replace(/[^A-Fa-f0-9]+/g,'').replace(/(\r\n|\n|\r)/gm,"").toUpperCase();


Tried this but not working.
The regex I gave you should already remove line breaks, since it removes EVERYTHING except A-F, a-f, and 0-9 (including whitespace). Am I necroposting something that already got solved, though?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement