Bona Fide OS Development
http://forums.osdever.net/

Mixing 32 bit calculation in 16 bit program NASM
http://forums.osdever.net/viewtopic.php?f=15&t=865
Page 2 of 2

Author:  dumb_terminal [ Thu Dec 30, 2010 7:40 pm ]
Post subject:  Re: Mixing 32 bit calculation in 16 bit program NASM

Back to original topic. I got the kernel loaded (back to basics). But i have a little calculation concept confusion.

lets say
LBAStart = 63
DataAreaStart = 411
ClusterNo = 15142
BytesPerSector = 64
So LBA = 63 + 411 + (15142-2) * 64 = 969434

I was doing was this (assume AX holds ClusterNo and ClusterLBA dw 0, 0):
Code:
    MOV AX, [ES:DI+15]
    SUB AX, 2
    XOR DX, DX
    MOV BX, [SectorsPerCluster]
    MUL BX
    MOV [ClusterLBA], AX
    MOV [ClusterLBA + 2], DX
    ADD EAX, [LBAStart]
    MOV EAX, [ClusterLBA]
    ;;;;;;; upto this part i was right
    ADD EAX, [DataAreaStart]

now after adding DataAreaStart which is WORD in size i got
10011011100101011011010 = 5098202 incorrect !!
I even tried this :
Code:
    ADD EAX, DWORD [DataAreaStart]

All the same.
Then i thought back in pure 8086 DX:AX used to represent a DWORD
Then did this:
Code:
    MOV AX, [ES:DI+15]
    SUB AX, 2
    MOV BL, [SectorsPerCluster]
    MUL BX
    MOV [ClusterLBA], AX
    MOV [ClusterLBA + 2], DX
    MOV EAX, [LBAStart]
    ADD EAX, DWORD [ClusterLBA]
    ADD EAX, [DataAreaStart]
    MOV [ClusterLBA], AX
    MOV [ClusterLBA + 2], DX
    MOV EAX, DWORD[ClusterLBA]
    MOV [DAP + 8], EAX


It was correct. Now whats the catch here ?? why didn't EAX got the right value instead of DX:AX. I mean the operation ADD EAX, WORD[DataAreaStart] was directly on EAX. It should have got the expanded dword value.
Anybody with hints ??
Regards.

Author:  losethos [ Thu Dec 30, 2010 7:53 pm ]
Post subject:  Re: Mixing 32 bit calculation in 16 bit program NASM

Code:
 ADD EAX, [LBAStart]
    MOV EAX, [ClusterLBA]
    ;;;;;;; upto this part i was right
    ADD EAX, [DataAreaStart]



In your first example, you clobbered EAX by moving the wrong direction. MOV EAX,[CLUSTERLBA]


In you second example

Code:
ADD EAX, DWORD [ClusterLBA]
    ADD EAX, [DataAreaStart]
    MOV [ClusterLBA], AX
    MOV [ClusterLBA + 2], DX
   


You mistakenly assumed EAX was DX:AX.



You are using a machine later than a 386, right? Of course you wouldn't try 32-bit code on an earlier machine. Are you using an emulator for 8086?

On any machine since a 386, you can absolutely do 32-bit instructions in 16-bit code.

Author:  dumb_terminal [ Thu Dec 30, 2010 7:58 pm ]
Post subject:  Re: Mixing 32 bit calculation in 16 bit program NASM

Hmmm my bad. dumb and dumber i get each day. Thank u.
Regards.
edit: i am using Intel core 2 duo now what model is it ?? i have to google...... :oops:

Author:  dumb_terminal [ Thu Dec 30, 2010 8:04 pm ]
Post subject:  Re: Mixing 32 bit calculation in 16 bit program NASM

losethos wrote:
You are using a machine later than a 386, right? Of course you wouldn't try 32-bit code on an earlier machine. Are you using an emulator for 8086?

On any machine since a 386, you can absolutely do 32-bit instructions in 16-bit code.

Well i don't mean to be a know it all, i heard, unless instructions are pulled during POST, just after POST the processor is just as good as a 8086. But i could be wrong. and there is a big chance that i could be wrong. :D

Author:  losethos [ Thu Dec 30, 2010 8:05 pm ]
Post subject:  Re: Mixing 32 bit calculation in 16 bit program NASM

I don't like you. You are evil.

First, you're a God damn Indian, revealed by the "sorry" point.

Second, you're purposely spreading uncertainty.

Thirdly, you tried to make LBA sound harder than easier. You are evil.

Repeat after me so everyone knows, "There is no problem with 32-bit code in 16-bit segments." That's what you're mission is to confuse people on, isn't it?

Author:  dumb_terminal [ Thu Dec 30, 2010 9:55 pm ]
Post subject:  Re: Mixing 32 bit calculation in 16 bit program NASM

well most of the point u got right except for i am an indian and i am trying to spread confusion. well the sorry part... indians uses sorry a lot don't they. and let me make a point very clear I AM HERE TO LEARN BY ASKING.

Page 2 of 2 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/