Vasanth
Vasanth

Reputation: 119

memory allocation in x86 Assembly language

I was learning about SIZEOF and TYPE operators yesterday. While doing that, I created an array,

Array QWORD 1h,2h,3h,4h,5h

and in .code section, I wrote,

MOV eax, SIZEOF Array

After assembling this, it's awkward that I got only 28 bytes allocated for array (using visual studio community 2015). I saw the values of registers in debugging session.

My question here is, each QWORD occupies 8 bytes of memory. Then, why didn't I get SIZEOF Array as 40?

Even worse. When I run this,

Array QWORD 1h

it gave me 8 bytes as expected

Array QWORD 1h,2h

Gives me 10..!! And,

Array QWORD 1h,2h,3h 

Gives me 18..!!
And so on...

Upvotes: 4

Views: 758

Answers (2)

Rohan
Rohan

Reputation: 1

It's hexadecimal, obviously. Counting the numbers between the total bytes after adding 1h and 2h, we get 8-9-A-B-C-D-E-F-10. If ye wanna convert decimal to hexadecimal to really get an edge in x86 programming, I would suggest dividing the decimal number by 16 repeatedly, and arranging the remainders in little-endian order to get the big-endian hex numeral (be sure to write A-F for results of 10-15!).

Upvotes: 0

zneak
zneak

Reputation: 138261

By default, Visual Studio's register window shows hexadecimal numbers. Could it be that you are confusing 28 with 0x28? 0x28 is the same as 40. (Similarly, 0x10 is 16, 0x18 is 24, and so on.)

Upvotes: 6

Related Questions