Posted: Fri May 27, 2022 11:14 pm Post subject: Simple Division Question?
I'm creating a simple function that divides damage
The original line of code is:
Code:
mov [rbx+000003E8],eax
Replacing this line of code in the memory viewer removes all damage.
My idea is divide the damage by 2 for example (damage and health are integers)
But the game crashes whenever I try this simple division
Code:
DamageAI:
mov ax, [eax]
mov bx, 2
div bx //causes crash, skipping this line wouldn't cause a crash
mov [rbx+000003E8],eax
jmp return
Thank you. I hope someone helps me with this because most guides I've seen deal with xmm values and I already used divss before once. But I'm having difficulty dealing with integer divisions.
Why are you using 16-bit registers? The original code makes it look like a 32-bit value.
You're modifying rbx without backing it up. (bx is the lower 16 bits of rbx)
You need to back up rdx too. It needs to be set to 0 prior to the div, and the remainder of the div gets written to dx.
Anyway, if you're dividing by a power of 2, shift right:
Code:
newmem:
shr eax,1
mov [rbx+3E8],eax
jmp return
General integer division:
Code:
label(divisor)
newmem:
push rcx
push rdx
mov ecx,[divisor]
xor edx,edx
div ecx
pop rdx
pop rcx
mov [rbx+3E8],eax
jmp return
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum