简体   繁体   中英

“error: parser: instruction expected” when I use “org 0x0100” directive

I have this NASM code:

Note that this is the original code before correcting my first error (see edit below):

[org 0x0100]
       jmp start
Numbers: dw 10, 40, 20, 14, 19, 13, 50, 6, 60, 14
swap: db 0
start: mov bx, 0                                                          
       mov byte [swap], 0
loop1: mov ax, [Numbers+bx]                                                              
       cmp ax, [Numbers+bx+2]                                  
       jle noswap                                                            
       mov dx, [Numbers+bx+2]                                  
       mov [Numbers+bx+2], ax                                  
       mov [Numbers+bx], dx                                        
       mov byte [swap], 1                                              
noswap: add bx, 2                                                                
        cmp bx, 18                                                              
        jne loop1                                                                  
        mov ax, 0x4c00                                                        
        int 0x21

I am using this command to assemble:

nasm -f elf Max.asm

I get this error:

error: unrecognized directive org

Why am I getting this error, and how can I fix it?

EDIT: After removing the brackets around the org statement as suggested in the comments, I am now getting this error instead:

Max.asm:1: error: parser: instruction expected

The originate directive tells the assembler to initialise all offsets for data and code in the program from given value.

org 0x0100 is used when writing small(Normally .COM files) DOS programs to compensate for the PSP(Program Statement Prefix) .

If you are working on linux, there is no point in adding the orginate directive.

nasm -f bin max.asm

will work, but then it can be executed only in DOSBOX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM