NASM/Yasm 在评论以反斜杠结尾后删除 CALL
NASM/Yasm drops CALL after comment ending with backslash
我目前正在尝试构建自己的引导加载程序并发现了一些奇怪的东西。
当下面的代码用 NASM 或 Yasm 汇编时没有标记的 NOP 命令,二进制文件中缺少以下 CALL。包含 NOP 后,CALL 已正确组装,但二进制文件中不存在操作码 0x90 (NOP)(由于 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
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 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.
我目前正在尝试构建自己的引导加载程序并发现了一些奇怪的东西。
当下面的代码用 NASM 或 Yasm 汇编时没有标记的 NOP 命令,二进制文件中缺少以下 CALL。包含 NOP 后,CALL 已正确组装,但二进制文件中不存在操作码 0x90 (NOP)(由于 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
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 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.