Some silly Assembly question

If you are needing help, or have questions for the different assembly languages available.

Moderator: Moderators

Post Reply
Annie
Posts: 14
Joined: Thu Feb 12, 2009 9:11 pm

Some silly Assembly question

Post by Annie » Mon Apr 12, 2010 12:01 pm

Hi,

Can anyone explain to me why

org 0x10000 ; the file start at 1MB

why is 0x10000 = 1MB? 0x10000 = 65536 in decimal. isn't it be 1Kb

One more question is that
Its not variable declaration. so what this line means? it looks line a label but with value!
bpbBytesPerSector: DW 512


Thank you

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:

Re: Some silly Assembly question

Post by Andyhhp » Mon Apr 12, 2010 1:31 pm

why is 0x10000 = 1MB? 0x10000 = 65536 in decimal.


Yes. 1 MiB is 0x100000 which is 16 times more than 65536. Where is that line from? It is almost certainly a mistake.


Its not variable declaration. so what this line means? it looks line a label but with value!


Yes and no. It is a label declaration.

In ASM, there is no concept of a variable as such. There are only bytes in memory and registers, with operations between the two. The line declares a label called 'bpbBytesPerSector' which is ultimatly a memory address. The 'dw 512' means "declare a word (16 bits) of data which has the value 512".

As a result, you have the label which is the memory address of a word of data with the value 512. This is the closest thing you can get to variables in asm. Do be careful not to execute data!

You will also see other declare tokens
db for byte,
dd for dword(32bits),
dq for qword(64bits),
dt for tword (10 bytes, 80bits - used for FPU stuff)

Does this help?

~Andrew
Image

Annie
Posts: 14
Joined: Thu Feb 12, 2009 9:11 pm

Re: Some silly Assembly question

Post by Annie » Mon Apr 12, 2010 11:34 pm

Thanks for the reply,

the org 0x10000 is found in tutorial 11, the asm file of stage 3.

About bpbBytesPerSector,

why is there sometimes ":" for declaration, and sometime don't. (I know ":" is added at the end of a lablel)

ex:

Code: Select all

           someVaraible                    db       10
           msg                             db   "message here"
           bpbBytesPerSector:              db       512 


why dont we have ":" for the someVariable or msg?

Thanks

Andyhhp
Moderator
Posts: 387
Joined: Tue Oct 23, 2007 10:05 am
Location: 127.0.0.1
Contact:

Re: Some silly Assembly question

Post by Andyhhp » Mon Apr 12, 2010 11:40 pm

Strictly speaking, a colon is required to define a label.

However, NASM decides that if the text isnt an assembler instruction, it will treat it as a label and see what happens.

As a result, it doesnt actually matter whether you use a colon or not.

~Andrew
Image

Post Reply