Bamqf
Bamqf

Reputation: 3542

Bracket usage in assembly language

This is a boot.s file from a guide to build the simplest operating system, which conforms with the GNU multiboot specification:

MBOOT_HEADER_MAGIC  equ     0x1BADB002  
MBOOT_PAGE_ALIGN    equ     1 << 0      
MBOOT_MEM_INFO      equ     1 << 1
MBOOT_HEADER_FLAGS  equ     MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM      equ     - (MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)


[BITS 32]   
section .text   


dd MBOOT_HEADER_MAGIC   
dd MBOOT_HEADER_FLAGS   
dd MBOOT_CHECKSUM       

[GLOBAL start]      
[GLOBAL glb_mboot_ptr]  
[EXTERN kern_entry]     

start:
    cli             

    mov esp, STACK_TOP      
    mov ebp, 0       
    and esp, 0FFFFFFF0H 
    mov [glb_mboot_ptr], ebx 
    call kern_entry      
stop:
    hlt              
    jmp stop         


section .bss             
stack:
    resb 32768      
glb_mboot_ptr:           
    resb 4

STACK_TOP equ $-stack-1     

I wonder what do those brackets mean in [BITS 32] or [GLOBAL start]? Is it declaration or the operation of getting address? I only know to declare variable like

GLOBAL start

or to get address like

mov [esi], eax

So I'm confused when they combine together.

Upvotes: 0

Views: 90

Answers (1)

PO&#39;ed MF
PO&#39;ed MF

Reputation: 36

The form without the brackets is a macro. The main difference is that the macro form will take multiple parameters.

extern scanf, printf, exit

is internally converted to:

[extern scanf]
[extern printf]
[extern exit]

See the Friendly Manual: http://www.nasm.us/xdoc/2.11.05/html/nasmdoc6.html

I used to think it "looked cool" to use brackets, but have decided it's better to save the brackets for memory references.

Upvotes: 2

Related Questions