繁体   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