flat assembler
Message board for the users of flat assembler.
Index
> Windows > Problem with maths. |
Author |
|
vid 23 Feb 2006, 15:25
what kind of crash? Maybe you missed the fact that both "mul" and "div" modify EDX, and that caused crash
|
|||
23 Feb 2006, 15:25 |
|
Barf 23 Feb 2006, 16:13
It's a classic windows XP error window. In details there's in Exception Information: code: 0xc0000095, I think, that is that, what says, what was wrong If it's problem with EDX, what should I do?
What about FPU problems, anybody has any idea? |
|||
23 Feb 2006, 16:13 |
|
velox 23 Feb 2006, 16:18
yes, the problem with EDX can throw this exception, zero EDX!
|
|||
23 Feb 2006, 16:18 |
|
Barf 23 Feb 2006, 16:51
ok thanks, now div is working. But what with this FPU :/
|
|||
23 Feb 2006, 16:51 |
|
vid 23 Feb 2006, 16:54
are you sure that "svFontWidth" never contains zero?
|
|||
23 Feb 2006, 16:54 |
|
Barf 24 Feb 2006, 16:09
I am sure because when i do it with div function it works propertly
|
|||
24 Feb 2006, 16:09 |
|
Tomasz Grysztar 24 Feb 2006, 16:50
Maybe it should be FIDIV instead of FDIV? What type is "svFontWidth"?
|
|||
24 Feb 2006, 16:50 |
|
Hicel 24 Feb 2006, 20:22
I tried the code you provided here... could not figure out any problem even
when I assigned values to all used registers and vars. maybe your problem is that you do not quit the program properly with ExitProcess? Just a guess Code: format PE GUI include "C:\fasmw164\include\win32a.inc" ResX dd ? fBuff dd ? svFontWidth dd ? svCharInLine dd ? entry $ ; Even if all the rigsters and ; vars hold values it doesn't crash ; ; mov ecx,12345678h ; mov ebx,12345678h ; mov edx,12345678h ; mov eax,12345678h ; mov [ResX],12345678h ; mov [fBuff],12345678h ; mov [svFontWidth],12345678h ; mov [svCharInLine],12345678h finit shl eax, 1 mov ebx, [ResX] sub ebx, eax mov [fBuff], ebx fild [fBuff] fdiv [svFontWidth] fprem fist [svCharInLine] invoke ExitProcess,0 data import library kernel32,'KERNEL32.DLL' import kernel32,\ ExitProcess,'ExitProcess' end data If it is not the exit then it seems mor like it is another part of your code. I would also say try the "p" (Pop) variants of the instructions you used.. maybe you fill the stack. Some systems don't automatically clear the FPU Stack. (That's just what I noticed some time ago) like "fdivp", "faddp" and so on.. |
|||
24 Feb 2006, 20:22 |
|
Degski 25 Feb 2006, 14:37
Hi, I'm new to this board and new to assembler, but I had the same problem and figured it out, it's slightly more subtle than the above.
Of course you can zero the EDX and that might be what you want, In reality the EDX doesn't need to be zero, IT (EDX) JUST NEEDS TO BE SMALLER THAN THE DIVISOR, since div will divde the number as EDX:EAX / DIV and will put the Quotient in EAX and the Remainder in EDX. If EDX it larger than the divisor, the rsult of your little division will be larger than 32 bits and therefor will overflow (and crash). So one can divide a 64bit dividend by a 32bit divisor, provided the high part (EDX) is smaller than the dividend. This should remind you of primary school long division (EDX is the 'borrow'). If EDX is larger than the divisor, you should first divide EDX. see the code below (it's for YASM and AMD64, but you''ll get the idea) It divides a multidigit (base 2^64) number by a 64 bit number, puts the quotient in rcx and returns the remainder. ; ; rax function ( rcx, rdx, r8, r9 ); ; reaminder divrem ( *quotient, *dividend, *lengthofdividend (in limbs), ; dividend) ; %define dst rcx %define len r8 %define dvr r9 %define src r10 ; from rdx on input %define null r11 bits 64 global my_divrem_1 section .text my_divrem_1: movsxd len, r8d mov src, rdx cmp len, 1 mov null, 0 je .d2 ; limb by limb dec len cmp [src+len*8], dvr jl .d0 ; highest limb < dvr ; highest limb >= dvr mov rax,[src+len*8] xor rdx,rdx div dvr mov [dst+len*8],rax dec len jmp .d1 ; highest limb < dvr .d0: mov rdx,[src+len*8] xor [dst+len*8],null ; high dest limb set to 0 dec len .d1: mov rax,[src+len*8] div dvr mov [dst+len*8],rax dec len cmp len,0 jge .d1 ;loop .d1 mov rax,rdx ; output the remainder ret ret ; limb by limb .d2: cmp src,dvr ; is src < dvr mov rax,[src] jl .d3 xor rdx,rdx div dvr mov [dst],rax mov rax,rdx ; output the remainder ret ret .d3: xor [dst],null ret ret end ciao |
|||
25 Feb 2006, 14:37 |
|
Barf 25 Feb 2006, 16:19
Tomasz Grysztar wrote: Maybe it should be FIDIV instead of FDIV? What type is "svFontWidth"? I didn't know about instruction like fidiv :/ If fdiv doesn't work with integers We know, why it didn't work. Thanks. |
|||
25 Feb 2006, 16:19 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.