OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 5:26 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: what does [BITS 32] do in nasm?
PostPosted: Fri Feb 08, 2013 6:22 am 
Offline

Joined: Thu Feb 07, 2013 11:53 pm
Posts: 13
Hi :D
I'm new to os development, and now some small questions confused me.

According to the book I am reading, when you are writing codes in protected mode using NASM, you should add [BITS 32] in place, just as follows:
Code:
[SECTION .s32]
ALIGN   32
[BITS 32]

LABEL_PM_START:
   mov ax, SelectorVideo        ;GDT Selector pointed to the video descriptor
   mov gs, ax

   mov ah, 0Fh   
   mov al, 'P'
   mov [gs:((80 * 0 +39) * 2)], ax        ;display 'P'
   jmp $

I'm really confused with that [BITS 32], because I dont know what intheworld NASM does when I add it. I compiled the asm file and then disassembled it using ndisasm, founding the right codes generated as follows:
Code:
00090320  66B81B00          mov ax,0x1b
00090324  8EE8              mov gs,ax
00090326  B40F              mov ah,0xf
00090328  B050              mov al,0x50
0009032A  6566A34E000000    mov [gs:0x4e],ax
00090331  EBFE              jmp short 0x90331




Exactly same with what I write in asm file, but once I changed the [BITS 32] to [BITS 16], I found the disassembled codes is whole different:
Code:
00090320  66B81B008EE8      mov eax,0xe88e001b
00090326  B40F              mov ah,0xf
00090328  B050              mov al,0x50
0009032A  6566A34E00        mov [gs:0x4e],eax
0009032F  0000              add [bx+si],al
00090331  EBFE              jmp short 0x331


Why?


Last edited by MarkZar on Fri Feb 08, 2013 6:37 am, edited 5 times in total.

Top
 Profile  
 
 Post subject: Re: what does [BITS 32] do in nasm?
PostPosted: Fri Feb 08, 2013 6:28 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
MarkZar wrote:
I'm really confused with that [BITS 32], because I dont know what intheworld NASM does when I add it.


Let me google that for you
It's well documented on the manual. However if you are having problem on the bit concept for different architectures, it's a long story.

By the way I think this should go to General Programming section.


Top
 Profile  
 
 Post subject: Re: what does [BITS 32] do in nasm?
PostPosted: Fri Feb 08, 2013 6:33 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
[Bits 32] generates code that is suitable for a 32 bit code segment. Specifically, the default operand and address sizes are 32 bit and the meaning of 66h/67h prefixes are reversed.


Top
 Profile  
 
 Post subject: Re: what does [BITS 32] do in nasm?
PostPosted: Fri Feb 08, 2013 6:52 am 
Offline

Joined: Thu Feb 07, 2013 11:53 pm
Posts: 13
bluemoon wrote:
MarkZar wrote:
I'm really confused with that [BITS 32], because I dont know what intheworld NASM does when I add it.


Let me google that for you
It's well documented on the manual. However if you are having problem on the bit concept for different architectures, it's a long story.

By the way I think this should go to General Programming section.

Thank you, in fact I have looked through the manual, but still a little confused with it.Maybe practice is more than any words :D


Top
 Profile  
 
 Post subject: Re: what does [BITS 32] do in nasm?
PostPosted: Fri Feb 08, 2013 6:54 am 
Offline

Joined: Thu Feb 07, 2013 11:53 pm
Posts: 13
Gigasoft wrote:
[Bits 32] generates code that is suitable for a 32 bit code segment. Specifically, the default operand and address sizes are 32 bit and the meaning of 66h/67h prefixes are reversed.

Thank you :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], SemrushBot [Bot] and 150 guests


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