I have a problem with multiplying and dividing values stored in registers (registers for example: ebx, ecx.. etc. or xmm0, xmm1.. etc.)
I have a function in my game like this:
Code: Select all
add dword ptr [esi+04],-10
I can manipulate this function to make this function adding 1 potion when used by changing function like this:
Code: Select all
add dword ptr [esi+04],10
Code: Select all
add dword ptr [esi+04],50
Code: Select all
add dword ptr [esi+04],320
When I want to add:
- 1 potion - I must write 16 in Decimal or 10 in Hex
- 2 potions - I must write 32 in Decimal or 20 in Hex
- 50 potions - I must write 800 in Decimal or 320 in Hex
My examples of the scripts which I wrote:
1-st example using ebx, ecx registers and Global Alloc function:
Code: Select all
alloc(newmem,2048)
globalalloc(output,4)
label(returnhere)
label(originalcode)
label(exit)
newmem:
originalcode:
push ebx
push ecx
mov ebx,10
mov ecx,1
mul ecx
pop ebx
mov ecx,[output]
add dword ptr [esi+04],ecx
pop ecx
Also someone told me that : when using more than one register (like in this example: ebx, ecx) I must pop them in reverse order than I pushed them. Is it important? If yes why?
2-nd example using xmm registers:
Code: Select all
alloc(newmem,2048)
globalalloc(output,4)
globalalloc(multiplier,4)
label(returnhere)
label(originalcode)
label(exit)
newmem:
originalcode:
movss xmm0,[output]
movss xmm1,[multiplier]
mulss xmm0,xmm1
push ebx
mov(?)q xmm0,ebx ????? <---------- I don't know how to write it correctly to wrote multiplied value into ebx register
add dword ptr [esi+04],ebx
pop ebx
jmp exit
multiplier:
dd 10
Yesterday and two days ago I was trying to fix it for several hours but I failed and got angry.. Can someone help me fix my script and explain me what I did wrong?
Thank you for your help.
Marta.