• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Help Thread: ASM & Disassembly

Status
Not open for further replies.
I read some tutorials on ASM, but there are many things that I don't understand. So, I decided to do something with ASM, something very simple but to no avail. I wanted to do a routine that adds 2 numbers and then create a script using XSE and insert it to somebody.
Here's my ASM:
Spoiler:


I also don't know why, but sometimes this code couldn't compile. I had to change some lines(for example adding r2 register). Oh and is pushing and popping necessary here? FBI mentioned earlier that registers r0-r4 don't have to be pushed.

I inserted this routine at 0x8378D0.
And here's my XSE code:
Spoiler:


Unfortunately it doesn't work. When I talk with a person who I assigned the script to I get "Does it work? 1".
Could someone help, please?

I've sent you a vm
 
I read some tutorials on ASM, but there are many things that I don't understand. So, I decided to do something with ASM, something very simple but to no avail. I wanted to do a routine that adds 2 numbers and then create a script using XSE and insert it to somebody.
Here's my ASM:
Spoiler:


I also don't know why, but sometimes this code couldn't compile. I had to change some lines(for example adding r2 register). Oh and is pushing and popping necessary here? FBI mentioned earlier that registers r0-r4 don't have to be pushed.

I inserted this routine at 0x8378D0.
And here's my XSE code:
Spoiler:


Unfortunately it doesn't work. When I talk with a person who I assigned the script to I get "Does it work? 1".
Could someone help, please?

The way you're cleaning registers isn't efficient, and also register values can be negative so that "cleaning" method isn't very good. You've also pushed said registers :o

If you want to clean a register and assign it a value just use mov. Mov is like an assignment statement for values between 0x0-0xFF. Then, as someone stated, you haven't put the result in var 0x800D (Lastresult).

Here's a fixed up version:

Code:
.align 2
.thumb
.thumb_func

main: 
	push {r0-r1, lr}
	mov r1, #0xF @write 0xF to r1
	mov r0, #0xC @write 0xC to r0
	add r1, r1, r0 @add r1 +r0, and put result in r1
	ldr r0, =(0x20370D0) @lastresult's RAM location
	strb r1, [r0] @write value of r1 into 0x20370D0 (r0)
	pop {r0-r1, pc}

.align 2

Depending on where you call it, you don't even need the push/pop, but that's a different story for a different time :D
 
Last edited:
It's not a function. 0x20370D0 is a location in RAM, which just to happens to be where Lastresult is stored.
0x20370B8 is var 0x8000, which is my mistake. It should've been D0 not B8 :D

Sorry to quote your post up, I havent noticed that you stated that in your posted routine :v
anyways, thanks for that, I gradually understand the ASM concept
 
I know nothing else in ASM but to make an errored routine...
Yup I'm trying hard, and I really want to learn it although Its very hard

I made a routine, I want the Original ID of the pokemon set in Var 8000 be seen in a script..
example
setvar 0x8000 0x0
callasm 0x[myoffset+1]
then the Pokemon's OTID in first Party will be stored in bufferstring

Spoiler:
 
I know nothing else in ASM but to make an errored routine...
Yup I'm trying hard, and I really want to learn it although Its very hard

I made a routine, I want the Original ID of the pokemon set in Var 8000 be seen in a script..
example
setvar 0x8000 0x0
callasm 0x[myoffset+1]
then the Pokemon's OTID in first Party will be stored in bufferstring

Spoiler:

ALWAYS AND ONLY PUSH WHAT YOU POP
In other words, replace the r3 r2 (or even better, only push LR and pop PC because you don't need more for callasm)
Also you're missing a : after OTID
 
ALWAYS AND ONLY PUSH WHAT YOU POP
In other words, replace the r3 r2 (or even better, only push LR and pop PC because you don't need more for callasm)
Also you're missing a : after OTID

Oh, Yah, errors lol...
Will this work now if I replaced r3 to r2?
 
Done registering, what's next err?
I dont know how to reply, I'm using mobile anyway

Improved version of your routine with comments:
Code:
.thumb				@you only need this here

main:
	push {lr}		@when writing custom routines, you don't need to push/pop r0 to r3
	ldr r0, var		@address of the var is now in r0
	ldrh r1, [r0]		@value of the var is now loaded into r1 while the address stays in r0
	mov r2, #0x64		@r2 is #0x64
	mul r2, r1		@multiplying r2 by r1			
	ldr r1, pokedata	@loading the pokemon data base address into r1
	add r1, r2		@adding those two together finally gives us the address of the desired pokemon
	ldrh r1, [r1, #0x4]	@the OTID is a halfword four bytes into the structure, so we now load it into r1
	strh r1, [r0]		@r0 is still the address of the var, so we can store it there
	pop {pc}		@return from the routine
	
.align 2			@since you place 4-byte words here, they need to be aligned by 2
var:		.word 0x20270B8 + (0x8000 *2)
pokedata	.word 0x2024284

Come back when you have an internet connection that doesn't give you a ping of fifty seconds :/
 
Improved version of your routine with comments:
Code:
.thumb				@you only need this here

main:
	push {lr}		@when writing custom routines, you don't need to push/pop r0 to r3
	ldr r0, var		@address of the var is now in r0
	ldrh r1, [r0]		@value of the var is now loaded into r1 while the address stays in r0
	mov r2, #0x64		@r2 is #0x64
	mul r2, r1		@multiplying r2 by r1			
	ldr r1, pokedata	@loading the pokemon data base address into r1
	add r1, r2		@adding those two together finally gives us the address of the desired pokemon
	ldrh r1, [r1, #0x4]	@the OTID is a halfword four bytes into the structure, so we now load it into r1
	strh r1, [r0]		@r0 is still the address of the var, so we can store it there
	pop {pc}		@return from the routine
	
.align 2			@since you place 4-byte words here, they need to be aligned by 2
var:		.word 0x20270B8 + (0x8000 *2)
pokedata	.word 0x2024284

Come back when you have an internet connection that doesn't give you a ping of fifty seconds :/

I'm so sorry , anyways, thanks
I've sent you a VM
 
I would like to know, if it's possible, the offset of two routines :

- First, the one which creates an OW on the map when we come on this map ;
- And also, the one which check if there is an OW next to the player before walking.

Can someone help me ? Thanks ^^
 
@daniilS:

When creating custom routines, it is essential that you push/pop all used registers in this routine. Otherwise you overwrite important values which are used by the scripting engine. :-)
 
@daniilS:

When creating custom routines, it is essential that you push/pop all used registers in this routine. Otherwise you overwrite important values which are used by the scripting engine. :-)

Nope, it depends on where you call them from. Unless you place a hook in the middle of an existing routine, r0 to r3 can be overwritten.
 
I'm trying to make psystrike's effect, so to do this i want to swap the def with the spe def (and their changments in battle) of every pokemons in battle.
I'm on Emerald.

So i did this :
Spoiler:


It is to swap the def and the spe of my first pokemon.
But obviously it doesn't work. The game resets.
Why?
Thanks
 
You have to load the Defense and the Sp. Defense, not just their offset.

Code:
.text
.align 2
.thumb
.thumb_func
.global swap

main:
	push {r0-r3, lr}

	ldr r0, .DEF
	ldrh r1, [r0]
	
	ldr r2, .SPEDEF
	ldrh r3, [r2]
	
	strh r1, [r2]
	strh r3, [r0]
	
	pop {r0-r3, pc}
	
.align 2
.DEF:
	.word 0x02024548
.SPEDEF:
	.word 0x0202454E
 
Thank you for your reply, but the game is still reseting.
Maybe it is due to my script. In order to do my test, I call my asm in an signpost.
Spoiler:


There is nothing special, so it's a bit strange.
 
Thank you for your reply, but the game is still reseting.
Maybe it is due to my script. In order to do my test, I call my asm in an signpost.
Spoiler:


There is nothing special, so it's a bit strange.

Wait, you're trying to test Psystrike's battle effect in the OW with a signpost script? Really?

This should be put in a battlescript which is then attached to an attack. Then used in a battle. Wow.
 
Status
Not open for further replies.
Back
Top