Sign in to follow this  

word size?

This topic is 2350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

when i write a program in assembly and i define a variable of "word" size.....is it truly the natural word size of my processor? for example on an i7 64bit processor will it be the size of 64bits.....or will it be defined as how microsoft defines the size of a words "A [b]WORD[/b] is a 16-bit unsigned integer" ?

Share this post


Link to post
Share on other sites
Depends on your CPU ( in your example a word is 64bit ), as word is determined by the default data size of the processor in question. [url="http://en.wikipedia.org/wiki/Word_(data_type)"]List of sizes by CPU type[/url]

That said, there are [url="http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx"]The Windows Datatypes[/url] as defined by Microsoft. In this case, WORD is #defined as you've described ([font="Courier New"]typedef unsigned short WORD;)[/font], 16bits, while a DWORD or DWORD32 = 32 and a DWORD64 is 64bit. Frankly, leaving this world behind was a pleasure! All of these sizes of course are only relevant to the Windows API's.



Then again, all this awkwardness can be blamed on C making data sizes dependant on the platform. Most other languages, especially more modern languages, are much more explicit about the data size of all in-built types.



EDIT: Why exactly, did someone vote this comment down? If you perceive something as factually incorrect, post it accordingly.

EDIT2: As to intel assembly instructions ( that above post was posted while I wrote this one ), in Intel assembly [url="http://www.cse.unl.edu/~goddard/Courses/CSCE351/IntelArchitecture/IntelDataType.pdf"]a word is defined as 2 bytes.[/url]

Share this post


Link to post
Share on other sites
[quote name='nuclear123' timestamp='1310405337' post='4833852']
intel syntax[/quote]

That's an assembly language syntax, not an assembler. Many assemblers use Intel syntax; many others do not.


What actual tool that converts assembly language to machine code are you using?

Share this post


Link to post
Share on other sites
Then there are no "variables" from the point of view of your assembly code. Inline assembly relies on the symbols defined in the containing scope to infer operand sizes, so what you define in your C/C++ code is what you get in your assembly language.

Share this post


Link to post
Share on other sites
[quote name='nuclear123' timestamp='1310402216' post='4833796']when i write a program in assembly and i define a variable of "word" size.....is it truly the natural word size of my processor? for example on an i7 64bit processor will it be the size of 64bits.....or will it be defined as how microsoft defines the size of a words "A [b]WORD[/b] is a 16-bit unsigned integer" ?[/quote]
I think you may be confused by how the size of primitive data-types according to their standards are defined in C/C++. In these languages an int, for example, is the size that is natural to the processor (it will be 32 bits on a 32-bit system, 64 bits on a 64-bit system etc.) However, since somewhere in 1960s (and thanks to the developers of the System/360 at IBM, as far as I know) a byte is defined as 8 bits, a word as two bytes (16 bits), a double word (dword) as 32 bits and so on. These terms also apply when you code in assembly:

[font="Courier New"]mov eax, [b]dword[/b] ptr [ebx][/font]

For the same reason assemblers will raise an error if the size of the destination register doesn't match the size of the value you are trying to load into it (unlike C/C++ compilers that automatically perform the necessary type-casting):

[font="Courier New"]mov [color="#FF0000"][b]ax[/b][/color], [color="#FF0000"][b]dword[/b][/color] ptr [ebx] // error C2443: operand size conflict[/font]

Share this post


Link to post
Share on other sites

This topic is 2350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this