• Welcome to Final Fantasy Hacktics. Please login or sign up.
 
March 28, 2024, 12:49:50 pm

News:

Please use .png instead of .bmp when uploading unfinished sprites to the forum!


(App) MassHexASM: Encode directly to little endian (v13 Update: 1/11/2017)

Started by Glain, May 08, 2011, 12:41:12 am

RandMuadDib

i'm sorry every time i see 'armips' it always looks like 'armpits' to me o.O
I will show you the power of SARDIIIIINES!!!!

Pickle Girl Fanboy

I don't care one way or another, but I felt obligated to give you Gemini's opinion on this, because he has years of experience with this.

formerdeathcorps

November 02, 2011, 02:27:41 am #22 Last Edit: November 02, 2011, 03:14:11 am by formerdeathcorps
Two problems I'm noticing.

sllv/jalr/srav does not convert from hex to ASM and vice-versa.
jr r31 sometimes is translated as jr r1 if you also require a non-zero amount of padding on the generated hex.  I'm not sure if this is just me typing jr 31, though.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Glain

I simply missed srav and jalr, so I'll have to add those in. As for sllv, not sure what I'm missing; I see the program producing output for that command, at least if it's got three registers, e.g. sllv r2,r3,r4. That command would shift r3 left r4 bits and store the result in r2?

jr 31 does seem to produce jr r1 if decoded, so it might just be that typo; I'll be on the lookout to see if jr r31 produces the wrong hex in certain situations.
  • Modding version: Other/Unknown

formerdeathcorps

November 28, 2011, 12:46:40 am #24 Last Edit: November 28, 2011, 12:47:24 am by formerdeathcorps
sllv is right, I found no more errors there.

Labels still don't work though.  If I try

bne r3, r0, PLACE
....
PLACE:

it will sometimes fail.  If PLACE is separated at least 5 commands from the branch command, it is almost always an undercount.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Glain

I made a few attempts to reproduce that, and couldn't; can you give some input that will result in incorrect hex? From my understanding, the number encoded in the beq/bne instruction is the number of commands to jump over, thus:

bne r3,r0,PLACE
nop
nop
nop
nop
nop
nop
PLACE: nop

would result in the bne being encoded as (little endian) 06006014 (jump over 6 commands).

(I suppose the first command after the beq/bne is actually the branch delay slot so it actually isn't "jumped over" at all, but it's still 6 commands between the bne and the label, exclusive.)
  • Modding version: Other/Unknown

formerdeathcorps

November 28, 2011, 02:18:16 am #26 Last Edit: November 28, 2011, 02:19:10 am by formerdeathcorps
No, 06 is correct.

The problem is this.  If you do:

bne r3, r0, PLACE
nop
nop
nop
SPOT: nop
nop
nop
nop
nop
PLACE: nop

you'll get 7 instead of 8 because you skip the command with SPOT:
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Glain

Ah, nice find. It was getting the label address wrong, because it wasn't incrementing the address of the current line if it ran into a label, without regard to the fact that a command could be on the same line as the label, and it would need to increment the address in that case.

I fixed that problem and added in support for the missing commands you mentioned as well as a few others. I've attached a new version (v7) and added a changelog entry in the original post of this thread. Let me know if you find any more bugs or what have you.
  • Modding version: Other/Unknown

formerdeathcorps

January 15, 2012, 08:48:11 pm #28 Last Edit: January 15, 2012, 11:57:10 pm by formerdeathcorps
Another small issue.

ori / andi are never signed commands because they are logical bitwise commands.  It's actually quite odd to read
lui r1, 0x8005
ori r1, r0, 0xF874 (just as a random example)

as

lui r1, 0x8005
ori r1, r0, -0x078C

since what I care to find is the address (5F874), not a meaningless (or in this case, wrong) arithmetic/logical operation.

Also, a feature request.  It's annoying in a long routine to find the address of a command buried deep in the routine.  Would it be possible to use the "Comment" box to display the starting and ending address of a highlighted section?
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Glain

I never even noticed that it was displaying signed numbers for and/or operations. We'll definitely want the unsigned numbers there... I'm adding in some code to differentiate some of those commands. How about this?

Unsigned: andi, ori, xori, sltiu
Signed: addi, addiu, slti
(I'm pretty sure sltiu actually treats the immediate as unsigned, unlike addiu).

You have a good idea there about displaying the addresses of the commands, but I don't like using the Messages box to do it. I was thinking of displaying them to the left of the assembly textbox, but I'm not sure how I'd make that work with scrolling. Maybe I could display

[address] command
[address] command

in the textbox itself, and just ignore everything between brackets when encoding, and have a flag to decide whether you want to see the addresses when decoding. Something like that.
  • Modding version: Other/Unknown

FFMaster

I would like that a lot. It would help me, at least.
  • Modding version: Other/Unknown
☢ CAUTION CAUTION ☢ CAUTION CAUTION ☢

Glain

Here's what I've got now. Does this look about right? I'm just ignoring anything between brackets.


  • Modding version: Other/Unknown

FFMaster

Yeah, that looks good.

If I had say, these 3 lines of code:

lui r2,0x8019
addiu r2,r2,0x0001
nop

and copy/pasted it into the left box, would the addresses automatically be added in with Show Addresses on?
  • Modding version: Other/Unknown
☢ CAUTION CAUTION ☢ CAUTION CAUTION ☢

Glain

I don't think I can add the addresses unless I'm going through an encode/decode process... I have to differentiate blank lines, comments, labels, etc, from ASM commands; only the commands get addresses. Plus I don't want to trap the paste action, or typing; it can get a bit messy. I can make Encode show the addresses on the left though.
  • Modding version: Other/Unknown

Glain

All right, I've released a new version and updated the original post. It should be decoding immediates correctly for all the commands we mentioned, should be able to show addresses on encode/decode and I made a few other changes.
  • Modding version: Other/Unknown

Choto

February 09, 2012, 08:29:14 am #35 Last Edit: February 09, 2012, 09:04:11 am by Choto
Hey Glain, I'm getting a problem with beq commands, not sure if its me or MHA

I tried encoding:

beq r4, r0, 0x0018ea80

and get

A9638010

I then press decode to check if its correct, and it turns into

beq r4,r0,0x00018ea8

The other address I'm trying goes from

beq r4,r0,0x0018ea24 to
beq r4,r0,0x00018ea4,

which is a little different because it doesn't just shift everything over 1 bit(?) like the previous example.

I wasn't sure if this was the same problem as you guys described before. There were 2 cases of it, one when jumping from 0x0018ea14 to 0x0018ea24 and when jumping from 0x0018ea20 to 0x0018ea80

whachu tink?

P.S. I'm using MasshexASM 8.0

Glain

February 09, 2012, 09:51:44 am #36 Last Edit: February 09, 2012, 10:23:14 am by Glain
I can test this later, but one thing about the beq/bne instructions is that they're actually encoded as branches over a certain number of statements, as opposed to branching to an address... so the address it displays is very dependent on the "starting address" box and the position in the code it's in. If I have:

0x0018ea6c: beq r4,r0,0x0018ea80
0x0018ea70: (branch delay slot)
0x0018ea74: ...
0x0018ea78: ...
0x0018ea7c: ...
0x0018ea80: (branch target)

The final instruction is basically just "if (r4 == r0), jump over 4 lines (but still run the one in the branch delay slot first)". In other words, the target address isn't in the encoded instruction at all, so if you encode it in different places in the ASM or use different starting addresses, you'll actually get different results. If I decode that example command with MHA and don't specify a starting address, it'll assume a starting address of 0 and it'll come out as:

beq r4,r0,0x00000014

Something to keep in mind with those statements.

EDIT: Oh, and there's also a limit to how far you can branch with the conditional branches (beq,bne,et.al.). You can only go so far (I think 65535 statements?). If you need to go further, use a shorter conditional branch to another place in your code, then use a j statement to get there (which actually encodes an address). In other words, instead of doing this...

beq r4,r0,(really far away address)        # Too far for beq to go... this won't work and can't encode properly.
nop

Use this pattern:

beq r4,r0,(JUMP)
nop
j (PAST_JUMP)
nop
(JUMP):
j (really far away address)                  # j is awesome and can go anywhere (as long as it's a valid code address, i.e. a multiple of 4).
nop
(PAST_JUMP):
(rest of routine)
  • Modding version: Other/Unknown

Choto

Ah ha, I see. I specified the starting address and it worked like a charm, thanks for the explanation!

Pickle Girl Fanboy

Testing Java version on Linux Mint 10, 32-bit, Gnome dot dot dot

Fails to load.  I will update my Java and try again tomorrow.

Glain

If you're getting the "Unsupported major.minor version" error, then it is indeed because you need to update Java. I compiled with Java 1.7, which, in retrospect, seems to be pretty recent, and it seems you need Java 1.7 to run it. Basically if "java -version" gives you anything before 1.7, then you need to update.

I just tried this on a Linux (Ubuntu) laptop and got it to work after finally managing to install Java 1.7 (I was getting the "Unsupported major.minor version" error before then). For some reason, apt-get didn't work for me, so I had to follow these instructions (top answer). I downloaded the JDK, but I imagine the same instructions would work for the JRE.
  • Modding version: Other/Unknown