The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Fan Games > Binary ROM Hacking
Reload this Page Help Thread ASM & Disassembly

Notices
For all updates, view the main page.

Binary ROM Hacking Need a helping hand or just want to talk about binary ROM hacks? Get comments and answers to any ROM Hacking-related problems, questions or thoughts you have here.

Ad Content
Closed Thread
 
Thread Tools
  #151   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (7:14 PM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by FBI agent View Post
Basically, from this whole thing, all you need to take away is that, "labels can only be accessed by OP codes which are about 254~ lines above the label" - according to JPAN. His use of this in the document, actually contradicts what he implies, because he does this even though he's writing a very small snipplet of code. As far as my knowledge goes, is unneeded. I'm also not a very big fan of his style of coding, I find it highly inefficient on top of being unneedingly complicated. You might want to wait to here daniilS opinion on this, as he is more technically intune with ASM instruction via his study at GBATEK. I for one can't be bothered to read all of that :P

Not to insult JPAN, he's been a very positive contribution to the ROM hacking community.

All you should know is that ldr loads into a register 4 bytes of data. If it's loading data from a pointer, that pointer must be word aligned (i.e divisible by 4) to be read properly.
That is to say there's no need to add any ".hword 0x0000" in any code?
Another question: Could you tell me more about the .align? At first I think it align the code to be 2-byte long, but why should we add another before defining the labels?

Thank you very much for your patient reply!
  #152   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (7:26 PM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Quote:
Originally Posted by jiangzhengwenjzw View Post
That is to say there's no need to add any ".hword 0x0000" in any code?
Another question: Could you tell me more about the .align? At first I think it align the code to be 2-byte long, but why should we add another before defining the labels?

Thank you very much for your patient reply!
I suggest always just leaving it in there, because during compile time the assembler will ignore it if it isn't needed. In the end it doesn't really impact your code in an unhealthy way, so I just leave it in for everything. You might here someone like daniilS come in and say stuff about not using it unneedingly , but it ultimately causes no harm while causing good in some cases. So just have it there all the time.

.align 2, iirc, just tells the assembler to start working on an address which is divisible by 2^n, in this case it's 2^2, i.e 4. It becomes important depending on context. You don't particularly need it in many cases, but in some cases you do. So like I said, just keep it there all the time.
__________________
...
  #153   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (7:35 PM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by FBI agent View Post
I suggest always just leaving it in there, because during compile time the assembler will ignore it if it isn't needed. In the end it doesn't really impact your code in an unhealthy way, so I just leave it in for everything. You might here someone like daniilS come in and say stuff about not using it unneedingly , but it ultimately causes no harm while causing good in some cases. So just have it there all the time.

.align 2, iirc, just tells the assembler to start working on an address which is divisible by 2^n, in this case it's 2^2, i.e 4. It becomes important depending on context. You don't particularly need it in many cases, but in some cases you do. So like I said, just keep it there all the time.
OK, I will add ".hword 0x0000" in my code. :)
For the ".align num" issue:
2^2? For a word(always in the end of a routine) occupies 4 bytes, it's good. Why should we add ".align 2" instead of ".align 1" at the beginning of a routine as a thumb instruction occupies only 2 bytes? Also, some people write ".align" instead of ".align 2" before the lables in the end of their routines, could you tell me the reason?

Thank you.:)
  #154   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (7:39 PM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Quote:
Originally Posted by jiangzhengwenjzw View Post
OK, I will add ".hword 0x0000" in my code. :)
For the ".align num" issue:
2^2? For a word(always in the end of a routine) occupies 4 bytes, it's good. Why should we add ".align 2" instead of ".align 1" at the beginning of a routine as a thumb instruction occupies only 2 bytes? Also, some people write ".align" instead of ".align 2" before the lables in the end of their routines, could you tell me the reason?

Thank you.:)
.align without a number does nothing I believe (it's the same as aligning for 1 byte?). The .align2 before labels is because sometimes you have an ldr which requires word alignment. I'm not to familiar with the topic because adding .align 2 makes it unneeded to be explored.
__________________
...
  #155   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (7:46 PM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by FBI agent View Post
.align without a number does nothing I believe (it's the same as aligning for 1 byte?). The .align2 before labels is because sometimes you have an ldr which requires word alignment. I'm not to familiar with the topic because adding .align 2 makes it unneeded to be explored.
So I can just simply add two .align 2, one at the beginning of the routine and another before the labels in the end?
  #156   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (8:16 PM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Quote:
Originally Posted by jiangzhengwenjzw View Post
So I can just simply add two .align 2, one at the beginning of the routine and another before the labels in the end?
Indeed you can. It covers all cases, as the other cases as subsets of this one. It's also ignored by the compiler if it's unneeded. The perfect thing to use without knowing anything about it lol.
__________________
...
  #157   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (8:22 PM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by FBI agent View Post
Indeed you can. It covers all cases, as the other cases as subsets of this one. It's also ignored by the compiler if it's unneeded. The perfect thing to use without knowing anything about it lol.
OK,I will just use that method. Thank you very much though I still know nothing about it, at least I have a feasible way to do it XD
  #158   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (10:27 PM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Summary:
The only thing you actually need at the beginning is .thumb, .align 2 can be used but there is no reason to do so, it's just if you like typing too much.
Put .align 2 before the words at the end and you will never need to worry about .hword 0x0, which could take up space or even misalign.
__________________
  #159   Link to this post, but load the entire thread.  
Old February 23rd, 2015 (10:54 PM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
Summary:
The only thing you actually need at the beginning is .thumb, .align 2 can be used but there is no reason to do so, it's just if you like typing too much.
Put .align 2 before the words at the end and you will never need to worry about .hword 0x0, which could take up space or even misalign.
I use Hackmew's thumb assembler, so what should I do?
Most people do that:
.text
.align 2
.thumb
.thumb_func
....(functions)
.align 2
....(words)

Did you mean:
.thumb
....(functions)
.align 2
....(words)
  #160   Link to this post, but load the entire thread.  
Old February 24th, 2015 (1:38 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Quote:
Originally Posted by jiangzhengwenjzw View Post
.thumb
....(functions)
.align 2
....(words)
That's all you need yes. The other things do no harm (apart from the .hword 0x0), but they can cause errors in the case of a typo, bring confusion, and I just find it a hassle putting them there every time.
__________________
  #161   Link to this post, but load the entire thread.  
Old February 24th, 2015 (1:55 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
That's all you need yes. The other things do no harm (apart from the .hword 0x0), but they can cause errors in the case of a typo, bring confusion, and I just find it a hassle putting them there every time.
That's really very strange. Hackmew is the developer of his assembler, but he also wrote the ".text", ".thumb_func" in his routine. JPAN used some .hword 0x0 in his routine in his tutorial and he layed emphasis on this issue, believing that the code won't work without them.
Thank you greatly, otherwise I will be misled by these two really awesome people. :)
  #162   Link to this post, but load the entire thread.  
Old February 24th, 2015 (4:05 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Quote:
Originally Posted by jiangzhengwenjzw View Post
That's really very strange. Hackmew is the developer of his assembler, but he also wrote the ".text", ".thumb_func" in his routine. JPAN used some .hword 0x0 in his routine in his tutorial and he layed emphasis on this issue, believing that the code won't work without them.
Thank you greatly, otherwise I will be misled by these two really awesome people. :)
Hackmew didn't develop the assembler, just the .bat file that makes assembling easier. The core itself comes from a really old DevkitARM.
As for JPAN: he's a great hacker, but lacked understanding of some things (of course, he was a pioneer in the area) and his routines should never be used as quality examples for they're often really unoptimized and use too many things (example: he wrote a custom pokemon enc/decryptor while there is one ready in the ROM.)
__________________
  #163   Link to this post, but load the entire thread.  
Old February 24th, 2015 (4:23 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
Hackmew didn't develop the assembler, just the .bat file that makes assembling easier. The core itself comes from a really old DevkitARM.
As for JPAN: he's a great hacker, but lacked understanding of some things (of course, he was a pioneer in the area) and his routines should never be used as quality examples for they're often really unoptimized and use too many things (example: he wrote a custom pokemon enc/decryptor while there is one ready in the ROM.)
Really? Then that's really a mistake to read JPAN's document first for me.;-; I thought it was more detailed when I started learning assembly so I read it first...
Another question if you have time to answer: How can you get the address of the encryptor/decryptor through diassembly? (I use no$gba instead of vba-sdl-h, for vba-sdl-h cannot work properly on my computer and I often get error. ;-;)
  #164   Link to this post, but load the entire thread.  
Old February 24th, 2015 (4:31 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Quote:
Originally Posted by jiangzhengwenjzw View Post
Really? Then that's really a mistake to read JPAN's document first for me.;-; I thought it was more detailed when I started learning assembly so I read it first...
Another question if you have time to answer: How can you get the address of the encryptor/decryptor through diassembly? (I use no$gba instead of vba-sdl-h, for vba-sdl-h cannot work properly on my computer and I often get error. ;-;)
Nah, his document is okay, that's the one I used myself to get into ASM. As for the enc/decryptor: www.romhack.me/database/23/fire-red-commonly-used-asm-rom-offsets/
__________________
  #165   Link to this post, but load the entire thread.  
Old February 24th, 2015 (4:39 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
Nah, his document is okay, that's the one I used myself to get into ASM. As for the enc/decryptor: www.romhack.me/database/23/fire-red-commonly-used-asm-rom-offsets/
This thread seems really useful! Thank you for giving me the link.
But it's still a problem how to get those address. I do not have an idea of how to get them through disassembly.
  #166   Link to this post, but load the entire thread.  
Old February 24th, 2015 (4:49 AM).
Edwearth's Avatar
Edwearth Edwearth is offline
 
Join Date: May 2014
Location: Paris
Gender: Male
Posts: 40
Is it possible to create a random number ?
  #167   Link to this post, but load the entire thread.  
Old February 24th, 2015 (5:00 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Quote:
Originally Posted by jiangzhengwenjzw View Post
This thread seems really useful! Thank you for giving me the link.
But it's still a problem how to get those address. I do not have an idea of how to get them through disassembly.
You'd probably set a break on reading the Pokémon data then trace back from there.
Quote:
Originally Posted by Edwearth View Post
Is it possible to create a random number ?
Look at the link I just sent.
__________________
  #168   Link to this post, but load the entire thread.  
Old February 24th, 2015 (5:22 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
You'd probably set a break on reading the Pokémon data then trace back from there.


Look at the link I just sent.
Okay, I will just try. For VBA-SDL-H2, I don't know why the game returns to the very beginning unexpectedly sometimes. Maybe I have made some mistakes? I use VBA-SDL-H2, for the original VBA-SDL-H crashes as soon as it loaded the game. TAT
  #169   Link to this post, but load the entire thread.  
Old February 24th, 2015 (5:26 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Quote:
Originally Posted by jiangzhengwenjzw View Post
Okay, I will just try. For VBA-SDL-H2, I don't know why the game returns to the very beginning unexpectedly sometimes. Maybe I have made some mistakes? I use VBA-SDL-H2, for the original VBA-SDL-H crashes as soon as it loaded the game. TAT
Why do you want to find the offset yourself though?
__________________
  #170   Link to this post, but load the entire thread.  
Old February 24th, 2015 (5:36 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
Why do you want to find the offset yourself though?
Because that's a kind of experience in my opinion. Perhaps it may help me learn disassembly...
But the debugger is a huge problem as almost all ASM tutorials use VBA-SDL-H, from Hackmew several years ago to FBI's tutorial last week..... Maybe the error was caused by my misuse. :(
  #171   Link to this post, but load the entire thread.  
Old February 24th, 2015 (6:00 AM).
daniilS's Avatar
daniilS daniilS is offline
busy trying to do stuff not done yet
 
Join Date: Aug 2013
Age: 23
Gender: Male
Posts: 409
Quote:
Originally Posted by jiangzhengwenjzw View Post
Because that's a kind of experience in my opinion. Perhaps it may help me learn disassembly...
But the debugger is a huge problem as almost all ASM tutorials use VBA-SDL-H, from Hackmew several years ago to FBI's tutorial last week..... Maybe the error was caused by my misuse. :(
Nocash is better than vba-sdl-h.
__________________
  #172   Link to this post, but load the entire thread.  
Old February 24th, 2015 (6:07 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by daniilS View Post
Nocash is better than vba-sdl-h.
Really? Would you mind giving me a link so I can learn how to use it? I could only use very limited functions, but most tutorials use vba-sdl-h as you know.
  #173   Link to this post, but load the entire thread.  
Old February 24th, 2015 (6:30 AM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Ehh, I don't like the syntax on no$GBA, nor do I agree it's better. It's good if you're doing conditional breaks, otherwise VBA-SDL-H is my preferred choice because you can:
1) Speed the emulation speed over 100% (no$ you cannot go much faster)
2) Save states from VBA-SDL-H is supported by VBA emulators
3) Register states are more clearly visible, and it shows the important info we care about
4) A command help that's actually understandable and useful

I wouldn't really say no$GBA's debugger is better. It has more features, but most of those features can be replaced by good debugging skills. An example would be when I tried to track changes in a dynamic address which was being read every frame in the game. I used VBA-SDL-H and instead I broke at the END of the memory randomizing function and was able to track it every time from there. In no$GBA this would've been the same process. So complicated debugging isn't even better, it's just conditional breaking (which is rare in itself).
__________________
...
  #174   Link to this post, but load the entire thread.  
Old February 24th, 2015 (6:46 AM).
jiangzhengwenjzw's Avatar
jiangzhengwenjzw jiangzhengwenjzw is offline
now working on katam
 
Join Date: Sep 2012
Gender: Male
Posts: 175
Quote:
Originally Posted by FBI agent View Post
Ehh, I don't like the syntax on no$GBA, nor do I agree it's better. It's good if you're doing conditional breaks, otherwise VBA-SDL-H is my preferred choice because you can:
1) Speed the emulation speed over 100% (no$ you cannot go much faster)
2) Save states from VBA-SDL-H is supported by VBA emulators
3) Register states are more clearly visible, and it shows the important info we care about
4) A command help that's actually understandable and useful

I wouldn't really say no$GBA's debugger is better. It has more features, but most of those features can be replaced by good debugging skills. An example would be when I tried to track changes in a dynamic address which was being read every frame in the game. I used VBA-SDL-H and instead I broke at the END of the memory randomizing function and was able to track it every time from there. In no$GBA this would've been the same process. So complicated debugging isn't even better, it's just conditional breaking (which is rare in itself).
I have vba-sdl-h,but it often crashes and vba-sdl-h2 have a problem that sometimes the game returns to the very beginning unexpectedly... Do you know the reason?
  #175   Link to this post, but load the entire thread.  
Old February 24th, 2015 (6:53 AM).
Blah's Avatar
Blah Blah is offline
Free supporter
 
Join Date: Jan 2013
Location: Unknown Island
Gender: Male
Posts: 1,924
Quote:
Originally Posted by jiangzhengwenjzw View Post
I have vba-sdl-h,but it often crashes and vba-sdl-h2 have a problem that sometimes the game returns to the very beginning unexpectedly... Do you know the reason?
Nope. I have no such problems. Remember you can't keep playing the game once a breakpoint is reached, or when you've hit F11. You need to hit "c" to get back.
__________________
...
Closed Thread

Quick Reply

Join the conversation!

Create an account to post a reply in this thread, participate in other discussions, and more!

Create a PokéCommunity Account
Ad Content

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 9:23 AM.