How to correctly multiply or divide the values stored in registers?
Posted: Fri Nov 08, 2019 10:15 am
Hello Good People.
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:
This function subtracts the value by 1 everytime when used - so, I have for example 46 potions, when I used one potion - this function is used and it is subtracting the value (46) by 1 so I have = 46 - 1 = 45 potions left.
I can manipulate this function to make this function adding 1 potion when used by changing function like this:
If I want to add 5 potions at once, I must change the function like this:
If I want to add 50 potions at once, I must change the function like this:
So you can see by looking on these functions that all values are multiplying by 16.
When I want to add:
My examples of the scripts which I wrote:
1-st example using ebx, ecx registers and Global Alloc function:
Game is crashing in this example and no matter what you enter in global alloc (output), it doesn't change the value in the game, it just frees it at a value which is already in game.
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:
In this example, I don't know how to correctly write the function which will move the multiplied value to the register - when I multiplied xmm0 with xmm1 the result will be stored in xmm0, am I right or not?
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.
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.