flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 14 Dec 2008, 00:22
Why not simply:
Code: add ecx,0xfff and ecx,not 0xfff |
|||
![]() |
|
hopcode 14 Dec 2008, 00:32
revolution wrote:
It must be said that the not 0xffff will be parsed on preprocessing stage,right ? but it is really Cool your improvement!! ![]() Thanks |
|||
![]() |
|
LocoDelAssembly 14 Dec 2008, 00:33
hehe, I liked this way
![]() Here a slight modification Code: ; mov edx,1000h ; dec edx neg ecx ; or ecx,edx ; xor ecx,edx and ecx, -1 shl 12 ; not ecx ; inc ecx ; or simply [b]neg ecx[/b] for [not ecx/inc ecx] neg ecx But, the commonly used code for achieving what your code does is: Code: add ecx, $1000 - 1 and ecx, -1 shl 12 Also, note that VirtualAlloc already rounds up your parameter so you don't have to do it. MSDN wrote: dwSize [in] |
|||
![]() |
|
revolution 14 Dec 2008, 00:36
hopcode wrote: It must be said that the not 0xffff will be parsed on |
|||
![]() |
|
revolution 14 Dec 2008, 00:37
LocoDelAssembly wrote: But, the commonly used code for achieving what your code does is: |
|||
![]() |
|
LocoDelAssembly 14 Dec 2008, 00:43
revolution wrote:
Yep, but your post wasn't there when I was reading and after a couple of minutes of pure skepticism on hopcode's code, I started to compose my reply and later pressed "Submit". |
|||
![]() |
|
hopcode 14 Dec 2008, 00:45
LocoDelAssembly wrote:
Yes,right,well kwnown... Another excellent improvement... Thanks Loco |
|||
![]() |
|
hopcode 14 Dec 2008, 00:55
revolution wrote:
Also,should not be not 0xffff first "translated" by preprocessor to its equivalent value, and then assembled ? Please, could you gently explain me why it is processed during the assembly stage? Thanks in advance, for your attention |
|||
![]() |
|
revolution 14 Dec 2008, 01:01
IIRC, the preprocessor will do macro expansion and fix/equ translation.
The parser will convert not into a token and take no action other than that. This is the same for other things like mov, and etc. The assembler will decode the not token as an arithmetic operator and do the computation. |
|||
![]() |
|
hopcode 14 Dec 2008, 01:29
/to revolution/ .mmmhhh... I am not completely persuaded about... but, frankly, i cannot say a word on the separation of preprocessing/assembling stages. I like to imagine it in such a way, and for the reason that i have not read a single line in the Fasm's code till now. I like the "surprise effect"
![]() Quote:
I dont know. It seems to me that the not 0fffh has a "long living time" before the final computation. |
|||
![]() |
|
FrozenKnight 15 Dec 2008, 11:41
i think you should really use GetSystemInfo() to get the page size for this kind of thing. Even though most systems use the standard 1000h page size it's still possible that a system may be using a custom page size.
|
|||
![]() |
|
hopcode 15 Dec 2008, 23:56
FrozenKnight wrote:
for Granularity ok,AFAIK,it is depending on the system. But do you know cases/examples for such a custum pagesize possibility ? I dont... Let me know, if you have references on this possibility. But i partially agree with you. This is the reason why i have written the code in that assembly way, it is to say: Code: mov edx,1000h ;(1000h as to simplify/and mean, in that fragment the result from a ;SYSTEM_INFO.dwPageSize) The code then was improved by revolution and commented by LocoDelAssembly. BTW /to LocoDelAssembly/ LocoEtcEtc wrote:
on a so clear and dummy code,your pure skepticism has no reason.do you need to test it to see what happens ?. On the contrary, I am skeptic on your english so that, after more than 2600 posts, you have finally learned lots of programming tecniques, but surely not the meaning of the english words. Yes, starting from the Press-Submit, Technique is surely not your own problem !!! ![]() ... hopcode |
|||
![]() |
|
LocoDelAssembly 16 Dec 2008, 00:40
Quote:
Yes and in fact I have simulated it with the Windows Calculator and after I got a FAILED result then I had to run it to confirm that your code was wrong, but after running several test cases it was clear that your code was doing right. Then after looking at it more carefully it was clear what it was doing, so I have removed some superfluous operations (for example replacing the OR/XOR pair with an AND), and later I gave you the "canonical" solution which was the same thing revolution posted when all I've commenting above was happening. About English, it is not part of my elementary education, all I have learnt came from this forum, other Internet sites and some VERY basic concepts at ultra low-quality high school. FrozenKnight, he simply should do nothing at all since as stated in the documentation, the round up is automatic and unavoidable. |
|||
![]() |
|
bitRAKE 16 Dec 2008, 00:59
I'm a binary nut, so I like to code it this way 'cus it's easier for me to remember:
Code: add ecx,N-1 and ecx,0-N (assuming alignment is actually needed, and N is a power of two) |
|||
![]() |
|
revolution 16 Dec 2008, 01:04
Since this topic is now done to death I will try to throw a spanner into the works:
What if the OS page size is not a power of two? |
|||
![]() |
|
hopcode 16 Dec 2008, 01:50
![]() ![]() Quote:
|
|||
![]() |
|
bitRAKE 16 Dec 2008, 08:56
"What if the OS page size is not a power of two?"
A) Find a different OS to program on, lol. B) Make all data structures in program multiples of crazy page size. C) Split the problem if only a couple bits are set in page size. D) Use reciprocal multiply trick, rounding up - then multiply. E) Catch spanner... |
|||
![]() |
|
baldr 16 Dec 2008, 19:03
revolution,
Let's round 'em all: ![]() Code: ceil_mod: ;;; Rounds value up to multiple ;;; ;;; Expects: ;;; u32 value @ eax -- value to round up ;;; u32 divisor @ ecx -- round up to multiple of; divisor != 0 ;;; ;;; Returns: ;;; u32 ceil_value @ eax -- value, rounded up to multiple of divisor ;;; ;;; Modifies: ;;; edx lea edx, [ecx-1] ;;; fall through round_mod: ;;; Rounds value to multiple ;;; ;;; Expects: ;;; u32 value @ eax -- value to round down ;;; u32 divisor @ ecx -- round to multiple of; divisor != 0 ;;; u32 threshold @ edx -- specifies rounding threshold (0 <= threshold < divisor) ;;; -- round down when 0 <= (value % divisor) < (divisor - threshold); ;;; -- round up otherwise ;;; -- in other words: when distance to next multiple greater than threshold, round down ;;; Returns: ;;; u32 round_value @ eax -- value, rounded to multiple of divisor according to threshold ;;; ;;; Modifies: ;;; edx add eax, edx ; add threshold sbb edx, edx ; with carry neg edx ; to edx jmp @f ;;; may be some neutral xx 31 D2 opcode ;;; instead of jump over "xor edx, edx"??? floor_mod: ;;; Rounds value down to multiple ;;; ;;; Expects: ;;; u32 value @ eax -- value to round down ;;; u32 divisor @ ecx -- round down to multiple of; divisor != 0 ;;; ;;; Returns: ;;; u32 round_value @ eax -- value, rounded down to multiple of divisor ;;; ;;; Modifies: ;;; edx == 0 xor edx, edx @@: div ecx mul ecx ret _________________ "Don't belong. Never join. Think for yourself. Peace." – Victor Stone. |
|||
![]() |
|
revolution 17 Dec 2008, 01:11
baldr wrote: Let's round 'em all: |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.