评论以反斜杠结尾后,NASM/Yasm放弃了致电 [英] NASM/Yasm drops CALL after comment ending with backslash

查看:136
本文介绍了评论以反斜杠结尾后,NASM/Yasm放弃了致电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试构建自己的引导加载程序,并发现一些奇怪的东西.

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

当下面的代码与NASM或Yasm一起汇编而没有标记的NOP命令时,二进制文件中将缺少以下CALL.带有NOP时,CALL会正确组装,但是二进制代码中不存在操作码0x90(NOP)(由于NOP的性质,后来可以理解).

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

推荐答案

反斜杠字符'\',作为行的最后一行,是Nasm的行延续字符".通过在注释中添加注释,注释继续到下一行-注释掉nop或call. (只是那样消失就不是nop的本性!).丢掉它,或在它后面放些东西.

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.

–弗兰克·科特勒

在NASM手册中, 3.1 NASM源代码行的布局:

NASM使用反斜杠(\)作为行继续符; 如果一行以反斜杠结尾,则下一行被视为反斜杠结尾的行的一部分.

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.

这篇关于评论以反斜杠结尾后,NASM/Yasm放弃了致电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆