NASM/Yasm drops CALL after comment ending with backslash

穿精又带淫゛_ 提交于 2019-12-20 05:28:07

问题


I am currently trying to built my own boot loader and noticed something peculiar.

When below code is assembled with NASM or Yasm without the marked NOP command the following CALL is missing from the binary. With the NOP included the CALL is correctly assembled but the op code 0x90 (NOP) is not present in the binary (later is understandable due to the nature of NOP).

to_hex_ascii:
        add al, '0'
        cmp al, 0x3a
        jl .end
;           add al, 0x07
            add al, 0x27
    .end:
        ret

print_word_hex:
        push bp
        mov bp, sp

        mov dx, [bp + 4]
        push dx
        mov al, dh
        push ax             ;\
        nop                 ; | <- NOP in question
        call print_lsb_hex  ; print_lsb_hex(ax);
        add sp, 2           ;/
        pop dx
        jmp print_lsb_hex.continue
print_lsb_hex:
        push bp
        mov bp, sp

        mov dl, [bp + 4]
    .continue:
        mov ah, 0x0e
        ; 0xf0
        mov al, dl
        and al, 0xf0
        shr al, 4
        call to_hex_ascii
        int 0x10  ; BIOS print call
        ; 0x0f
        mov al, dl
        and al, 0x0f
        call to_hex_ascii
        int 0x10  ; BIOS print call

        pop bp
        ret

回答1:


The backslash character, '\', as the last thing on a line, is Nasm's "line continuation character". By putting it in a comment, the comment is continued to the next line - commenting out the nop or call. (it is not the nature of nop to just disappear like that!). Lose it, or put something after it.

– Frank Kotler


From the NASM manual, 3.1 Layout of a NASM Source Line:

NASM uses backslash (\) as the line continuation character; if a line ends with backslash, the next line is considered to be a part of the backslash-ended line.



来源:https://stackoverflow.com/questions/29951661/nasm-yasm-drops-call-after-comment-ending-with-backslash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!