Bona Fide OS Developer
View unanswered posts | View active topics It is currently Mon Dec 10, 2018 4:40 pm



Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
 Mixing 32 bit calculation in 16 bit program NASM 
Author Message

Joined: Tue Dec 28, 2010 2:17 pm
Posts: 11
Post 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.


Thu Dec 30, 2010 7:40 pm
Profile

Joined: Fri Aug 20, 2010 10:04 pm
Posts: 41
Post 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.


Thu Dec 30, 2010 7:53 pm
Profile

Joined: Tue Dec 28, 2010 2:17 pm
Posts: 11
Post 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:


Thu Dec 30, 2010 7:58 pm
Profile

Joined: Tue Dec 28, 2010 2:17 pm
Posts: 11
Post 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


Thu Dec 30, 2010 8:04 pm
Profile

Joined: Fri Aug 20, 2010 10:04 pm
Posts: 41
Post 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?


Thu Dec 30, 2010 8:05 pm
Profile

Joined: Tue Dec 28, 2010 2:17 pm
Posts: 11
Post 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.


Thu Dec 30, 2010 9:55 pm
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.