flat assembler
Message board for the users of flat assembler.

Index > MenuetOS > align?

Author
Thread Post new topic Reply to topic
thecf



Joined: 23 Dec 2006
Posts: 23
thecf 24 Feb 2008, 16:47
can anybody tell me what the align macro actually does in the menuet source code? im unsure...

why would you need to align the code? I've never seen it in other tutorials on os development.

macro align value { rb (value-1) - ($ + value-1) mod value }

not sure what the above does. i know it defines a macro with the name align. but dont really understand why you would need to do align 4 before some system functions..

any help will be great Rolling Eyes
Post 24 Feb 2008, 16:47
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4039
Location: vpcmpistri
bitRAKE 24 Feb 2008, 17:53
the macro reserves bytes (rb) to insure the current offset is divisible by value. If we look at the case of "align 4":
Code:
$  |  $-3   3-#
0  |   3    0
1  |   0    3
2  |   1    2
3  |   2    1    
All values are MOD 4, to show cases.

Alignment can result in a speed improvement. Here is a macro that does alignment plus an offset:
Code:
macro ALIGN val,off { rb (val+off-($ mod val))mod val }    
...like ALIGN 64,8 would ensure the address is 8 MOD 64.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 24 Feb 2008, 17:53
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4333
Location: Now
edfed 24 Feb 2008, 18:15
the align is cause of hardware
the memory is on 64 bits bus
so, to access a data, the need of aligned addresses on this bus is good.
if you want to access a dword at [5], you should read the first part, three bytes at [5,6,7], and the second part at [8]
so, it consumme one extra memory cycle to read unaligned values.
align is not exclusive to menuet and x86.

it is valid for real documents accesing.

a good example are the dragon ball episodes. to follow the story, you need to watch at least two consecutives episodes. as episodes are unaligned on the story sequence, it is boring...

that's why we try to make aligned DBZ episodes.
Post 24 Feb 2008, 18:15
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 can attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.