簡體   English   中英

main.asm:5:錯誤:解析器:預期指令

[英]main.asm:5: error: parser: instruction expected

我一直在嘗試運行它,但不斷得到 main.asm:5: error: parser: instruction expected - 我不知道為什么 org 沒有運行或者我做錯了什么,但它不會再運行了。 我使用 mycompiler.io 運行它和其他但沒有成功。 我對組裝很陌生,正在努力解決這樣的錯誤

bits 16
            org      0x100 ; start offset at memory position 100
            jmp     main ; jump to main program
    ;
    ; Data definitions
    ;
    mess1: db 'Input any number (0 - 9)', 0dh,0ah,'$'
    mess2: db 'The number is a multiple of 3',0dh,0ah,'$'
    mess3: db 'The number is not a multiple of 3',0dh,0ah,'$'
    errmess: db '**',0dh,0ah,'$'
    crlf: db 0dh,0ah, '$'
    ; ; Display a string on the screen
    ; DX contains the address of the string
    ;
    display:
        mov     ah,09 
        int     21h 
        ret
    ;
    ; Set the cursor position
    ;
    cursor:
        mov     ah,02
        mov     bh,0 ; screen number 
        mov     dh,0ah ; row
        mov     dl,0 ; column
        int     10h
    ret
    ;
    ; Display a user prompt
    ;
    prompt:
        mov     dx,mess1
        call    display
        ret
    ;
    ; Read one character from the keyboard
    ;
    input:
    
        mov     ah,01
        int     21h
        ret
    ;
    ; Clear screen and change screen colour
    ;
    screen:
        mov     ah,06 ; scroll up screen
        mov     al,0 ; lines to scroll where 0 clear entire screen
        mov     cx,0 ; starting row:column
        mov     dl,80 ; ending row;column
        mov     dh,80
        mov     bh,17h ; change background color to white on blue
        int     10h
        ret
    ;
    ; Carriage returnm and line feed
    ;
    newline:
        mov     dx,crlf
        call    display
        ret
    ;
    ; Main program
    ;
    main:
        call    screen
        call    cursor
    next:
        call    prompt
        call    input
        cmp     al,'0'  ; character < 0?
        jl      error   ; yes, error message
        cmp     al,'9'  ; character > 9?
        jg      error   ; yes, error message
        sub     al,30h  ; convert from ASCII to numeric
        xor     ah,ah   ; clear AH
        mov     bl,3
        idiv    bl      ; divide by 3
        cmp     ah,0    ; remainder = n0?
        je      isdiv   ; yes: divisible by 3
        call    newline
        mov     dx,mess3 ; not divisible by 3
        call    display
        jmp     fin
    isdiv:
        call    newline
        mov     dx,mess2
        call    display ; divisible by 3
    fin:int     20h     ; terminate program
    ;
    ; Display error message. Number out of range
    ;
    error:
        mov dx,errmess
        call display
        jmp next

mycompiler.io 上的 NASM IDE 似乎是用於 64 位匯編的。 您擁有的代碼是 16 位的(如果您將匯編作為一種愛好,我會堅持使用 16 位,它可以更加寬容,並且非常適合學習)。 不幸的是,16 位代碼不能為 64 位系統本地編譯。 如果你想運行這個和其他 16 位代碼,你需要 NASM 和運行 16 位代碼的東西,我推薦dosbox

要編譯和運行您的代碼:

nasm mycode.asm -fbin -o run.com
dosbox main.com

(如果您使用 dosbox 路線並且在 Windows 上,請確保將 dosbox.exe 添加到路徑,以便您可以從命令提示符執行此操作)

如果您正在尋找在線解決方案,您可以使用 repl.it 通過創建一個 bash 項目並使用nasm mycode.asm -fbin -o run.com構建來使用 nasm 進行編譯。 repl.it 上還有這個web 版本的 dosbox。 我沒有親自使用它,但它似乎工作正常。

祝您組裝之旅好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM