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.