Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: Hayleia on December 04, 2013, 02:40:13 pm

Title: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 04, 2013, 02:40:13 pm
Helloes

I am looking for some software that would (as the title says) convert a file with ASM mnemonics into HEX code.
For example, say that I have a file named "test.z80" with this inside:

   xor a
   ret

Then the software would return a file with AFC9 inside.

I don't really care if the program needs a header or not, or if it returns AF and C9 on separate lines, I'd just like a tool that converts, basically and I'll make adjustment myself if needed.

So does that exist ?
Note: I know RunerBot does that, but I'd like an offline solution (because I don't have any connexion when on the train).
Note2: Whatever OS you want it to be run with is ok, I have both Windows and Linux on my laptop.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: ben_g on December 04, 2013, 02:44:43 pm
I don't know if such a program exists, but you can always do it manually using a z80 instruction set. (http://clrhome.org/table/)
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 04, 2013, 02:49:39 pm
True, thanks for the table.

However, this can be painful for long programs :P
I also forgot to say which OS I wanted it to run on, because I don't care I have both Windows and Linux. I'll edit the first post.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: ben_g on December 04, 2013, 02:52:38 pm
have you considered using an on-calc editor, like mimas? (http://www.ticalc.org/archives/files/fileinfo/431/43140.html)
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: SpiroH on December 04, 2013, 02:53:30 pm
I am looking for some software that would (as the title says) convert a file with ASM mnemonics into HEX code.
Of course, that exists! It's called a z80 assembler!
Am i missing something?

Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: ben_g on December 04, 2013, 02:55:10 pm
I think (s)he whants a program to convert the assembly code to readable hexadecimal code, instead of into a binary program file.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: calc84maniac on December 04, 2013, 02:56:43 pm
With SPASM, you can use the -T command-line option to generate a code listing (as well as -O to not specify an output file). This won't give the hex by itself, though, it's a bit more verbose. Alternatively you can just output to a .bin file and use another tool to convert that to hex.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: SpiroH on December 04, 2013, 02:56:56 pm
A z80 assembler (almost any will do!) produces "both" a binary AND a list output with the hex codes beside the asm mnemonics!
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 04, 2013, 03:26:23 pm
I think (s)he whants a program to convert the assembly code to readable hexadecimal code, instead of into a binary program file.
Yeah, that's it.

With SPASM, you can use the -T command-line option to generate a code listing (as well as -O to not specify an output file). This won't give the hex by itself, though, it's a bit more verbose.
Thanks, I've used SPASM to compile for a little while without even knowing it had options lol. But yeah, there are a bit too much things.

A z80 assembler (almost any will do!) produces "both" a binary AND a list output with the hex codes beside the asm mnemonics!
Well TASM doesn't because it doesn't even run in Win8 (and don't tell me "install Win7", I tried and it missed so many drivers that even the mouse was not recognized), and SPASM does but I don't want the "beside the asm mnemonics" part :P
I want only hex, plus things at the beginning or the end if you like, but not things that are hard to remove for lazy people :P
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Xeda112358 on December 04, 2013, 03:30:03 pm
I know you said you wanted an offline solution, but maybe talk to Deep Thought about ORG (http://clrhome.org/asm/). It gives an option to output the hex.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: SpiroH on December 04, 2013, 03:32:59 pm
I want only hex, plus things at the beginning or the end if you like, but not things that are hard to remove for lazy people :P
Well, with all that laziness, may i ask what do you need the hex codes for? x.x
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 04, 2013, 03:35:49 pm
I know you said you wanted an offline solution, but maybe talk to Deep Thought about ORG (http://clrhome.org/asm/). It gives an option to output the hex.
Good idea, he might have something that can do it.

I want only hex, plus things at the beginning or the end if you like, but not things that are hard to remove for lazy people :P
Well, with all that laziness, may i ask what do you need the hex codes for? x.x
It's not "all that laziness", I'd like to see you remove half the line on every line of a file everytime you compiled it :P
And it's to include ASM code into Axe code (because it is a lot better to design GUIs with Axe but the core of the program I am writing needs to be in ASM).
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: SpiroH on December 04, 2013, 03:40:10 pm
It's not "all that laziness", I'd like to see you remove half the line on every line of a file everytime you compiled it :P
A very simple program can do it for you, you don't need to edit the file yourself... :P


Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 04, 2013, 03:57:24 pm
It's not "all that laziness", I'd like to see you remove half the line on every line of a file everytime you compiled it :P
A very simple program can do it for you, you don't need to edit the file yourself... :P
You just reminded me that NotePad++ supports column edition/selection, thanks :D

So yeah, using -T in SPASM then using NotePad++ to remove useless columns is a solution, but if anyone has better, I'll take it :)
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: chickendude on December 04, 2013, 04:16:03 pm
Why not just use a hex dumper to dump the .bin file? You could write a script or batch file to do it automatically.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 04, 2013, 04:41:05 pm
Why not just use a hex dumper to dump the .bin file? You could write a script or batch file to do it automatically.
I have a problem on each OS :P
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: SpiroH on December 04, 2013, 07:45:50 pm
Here's a very simple vbs script ('cut.vbs') that may help you to achieve what you need.
Please find inside the attached archive (vbs-cut.zip):
1. Files:
ReadMe.txt   - this file!
fire.lst    - a sample output list file created with an assembler (NASM in this case)
hexa_codes.txt  - the hexacodes stripped off from 'fire.lst'
2. How to use 'cut.vbs':
Execute it in a dos command prompt, like this:
"cscript cut.vbs > hexa_codes.txt
3. Test it with the provided sample first.
4. Adjust the parameters (which depend on your 'lst' output) inside the script (open it with Notepad)

Hope it helps to get you started. ;)

Caveat: Because this was generated with 'Windows Script Host' you still need to delete the first 2 lines of 'hexa_codes.txt' (not a big deal?)

Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 05, 2013, 01:57:32 am
Wow, thanks :D
I just have a little problem with your program: when I put fire.lst in C:\ it works, but when I put it in an other place like "E:\<full path>\fire.lst", then I change the line in your program where it's written "C:\fire.lst" to have the path I have instead, but it says (in French) "E:\<full path\cut.vbs(7, 1) Erreur d'exécution Microsoft UBScript: Chemin d'accès introuvable". Could this be because I have spaces in the path ?
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: SpiroH on December 05, 2013, 09:40:44 am
Quote from: Hayleia
... "Chemin d'accès introuvable". Could this be because I have spaces in the path ?
Well, that could well be the case, to be honnest, i dunno. But the 'Windows Script Host' is rather funky indeed. Take it as a 'proof of concept' only and learn to live with its shortcomings.
Of course, a much better utility can be written but that also requires some spare time, which atm i don't have. :)
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Xeda112358 on December 05, 2013, 10:26:06 am
It is likely due to spaces in the filepath name. Also, it seems that ClrHome is down, so I am thinking Deep Thought is too busy :/
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 05, 2013, 11:33:27 am
Quote from: Hayleia
... "Chemin d'accès introuvable". Could this be because I have spaces in the path ?
Well, that could well be the case, to be honnest, i dunno. But the 'Windows Script Host' is rather funky indeed. Take it as a 'proof of concept' only and learn to live with its shortcomings.
Of course, a much better utility can be written but that also requires some spare time, which atm i don't have. :)

Wow, something weird happened here, I remember editing my previous post twice but I don't see those edits anywhere O.O
I was saying that the problem doesn't come from spaces, I tried in another folder with spaces and it worked like a charm.
Anyway, it works in certain conditions, I'll just find a place where it works and where it doesn't bother me. Thanks for the utility :)

edit In fact I just messed things up and wrote my edits in the wrong post (http://ourl.ca/20259/369899) lol :P

Also, it seems that ClrHome is down, so I am thinking Deep Thought is too busy :/
Yeah, this is another reason why I wanted an offline solution. They always work (except when Microsoft makes stupid updates).
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Dapianokid on December 05, 2013, 05:58:11 pm
I wish I were here earlier to tell you to do what I used to do:
Output to .bin and use Notepad++ to view the hex of it and copy and paste that as your own file. :P BOOM. HeXsTrInGs
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Deep Toaster on December 05, 2013, 06:17:57 pm
As I said in a PM you might be able to use this: http://www.ticalc.org/archives/files/fileinfo/168/16869.html

I've never used it myself but it looks relevant enough. (It's an unsquisher so it'll extract and display the ASCII hex.)

EDIT: Yeah, ClrHome is down because my PayPal derped and I need to renew my domain :/ I'm trying to get it up now, sorry about that.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: AssemblyBandit on December 05, 2013, 06:25:20 pm
The hex listing function in asm studio 8x exports a text file of the program in hex. Your program would have to be called test.asm I think.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Dapianokid on December 05, 2013, 06:46:23 pm
The hex listing function in asm studio 8x exports a text file of the program in hex. Your program would have to be called test.asm I think.
I believe you can change the function to support different names. It might not accept arguments, but at least you can write something that will and use the function. Idk. I haven't used it in ages.
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: AssemblyBandit on December 05, 2013, 07:17:18 pm
Yeah, it works with .z80, when opening the file just select 'All files' from the drop down box. Then click on 'Assembly' and select 'Hex Listing'. It creates test.txt with the following text:

test.txt - Hex Listing
2 bytes total

AF C9
Title: Re: Convert ASM mnemonics to HEX (ASCII) ?
Post by: Hayleia on December 06, 2013, 12:34:10 am
OK, thanks all for the solutions, I'll try them all and see which one I like best ^^