flat assembler
Message board for the users of flat assembler.
Index
> Windows > Integer overflow - range checking |
Author |
|
bitRAKE 03 Apr 2021, 13:49
The conditional instructions operating on CF are unsigned. Whereas those that rely on SF & OF are signed branches. The ZF ones are both. I suggest writing a little test - especially for the bounds of your number format.
|
|||
03 Apr 2021, 13:49 |
|
FlierMate 03 Apr 2021, 14:47
bitRAKE wrote: The conditional instructions operating on CF are unsigned. Whereas those that rely on SF & OF are signed branches. The ZF ones are both. I suggest writing a little test - especially for the bounds of your number format. Thanks for the suggestion. Maybe I should add the numbers first then determine using flags like you said.[/i] |
|||
03 Apr 2021, 14:47 |
|
revolution 03 Apr 2021, 15:04
Code: add eax, ebx
jc unsigned_overflow
jo signed_overflow |
|||
03 Apr 2021, 15:04 |
|
FlierMate 03 Apr 2021, 15:09
revolution wrote:
Thank you. At first I thought can detect overflow before adding the numbers.... so your code and @bitRAKE explanation have clarified it in simple solution. |
|||
03 Apr 2021, 15:09 |
|
revolution 03 Apr 2021, 15:12
You can also use the carry flag to extend the addition to more precision.
Code: add eax, ebx ; first 32-bits adc ecx, edx ; next 32-bits |
|||
03 Apr 2021, 15:12 |
|
FlierMate 03 Apr 2021, 15:25
revolution wrote: You can also use the carry flag to extend the addition to more precision. Thumb up for this! BTW, as for the variables in higher programming language, can I define each of these variables as follows? Code: section '.code' code readable writable executable var0001 rb 256 ; string var0002 rb 32 ;32-bit integer .... .... I see the var0001 and var0002 has occupied 288 bytes at the beginning of the code section with null bytes. About the size of code section, can I adjust it to fit 512 bytes or multiple of 512 bytes (because the code section would be larger than usual if I store multiple variables in it) while the rest of the sections (data section & import table) remain at 512 bytes minimum? It would save me some hassle if you or anyone know this. |
|||
03 Apr 2021, 15:25 |
|
revolution 03 Apr 2021, 16:08
32-bit integers are only 4 bytes, or one dword.
Code: var0002 dd ? ;32-bit integer |
|||
03 Apr 2021, 16:08 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.