Thread: [Tutorial] GBA ASM Programming
View Single Post
  #32    
Old November 9th, 2010, 03:59 PM
Shiny Quagsire's Avatar
Shiny Quagsire
Unexpectedly Gone until Aug 13
 
Join Date: May 2009
Location: Hoenn Safari Zone
Age: 16
Gender: Male
Nature: Jolly
Quote:
Originally Posted by 0m3GA ARS3NAL View Post
I'm a little confused...

may I have an example?
Sure

OK, lets take our initial routine:
Code:
.align 2
.thumb
.global example1

main:
		push {r0-r1,lr}
		ldr r0, pokemon_data
		ldrb r0, [r0]
		lsl r0, r0, #0x5
		lsr r0, r0, #0x5
		ldr r1, var
		strh r0, [r1]
		pop {r0-r1,pc}

.align 2

pokemon_data:
		.word 0x02024284 + 0x50
var:
		.word 0x020270B6 + (0x800D * 2)
Now, we want to replace all of our checking and returning stuff with this:

Code:
lsr r0, r0, #0x3				@Shift over initial sleeping bits (If there)
lsl r0, r0, #0x3				@Set it back
add r0, #0xyoursleepturns		@Add our number of sleeping turns
ldr r1, pokemon_data			@Load our writing destination
strh r0, [r1]				@store r0 in the address contained in r1
Our final result:

Code:
.align 2
.thumb
.global example1

main:
		push {r0-r1,lr}
		ldr r0, pokemon_data
		ldrb r0, [r0]
		lsr r0, r0, #0x3 
		lsl r0, r0, #0x3
		add r0, #0xyoursleepturns
		ldr r1, pokemon_data 
		strh r0, [r1] 
		pop {r0-r1,pc}

.align 2

pokemon_data:
		.word 0x02024284 + 0x50
Since I didn't need the var, I removed it
__________________



Reply With Quote