学习汇编,代码有问题吗?
jmp start
;==============================
; Draws a horiz and vert line
;==============================
startaddr dw 0a000h ;start of video memory
colour db 1
;==============================
start:
mov ah,00
mov al,19
int 10h ;switch to 320x200 mode
;=============================
horiz:
mov es, startaddr ;put segment address in es ; <--- Error Line 14
mov di, 32000 ;row 101 (320 * 100)
add di, 75 ;column 76
mov al,colour ;cannot do mem-mem copy so use reg
mov cx, 160 ;loop counter
hplot:
mov es:[di],al ;set pixel to colour ; <--- Error
inc di ;move to next pixel
loop hplot
vert:
mov di, 16000 ;row 51 (320 * 50)
add di, 160 ;column 161
mov cx, 100 ;loop counter
vplot:
mov es:[di],al ; <--- Error
add di, 320 ;mov down a pixel
loop vplot
;=============================
keypress:
mov ah,00
int 16h ;await keypress
end:
mov ah,00
mov al,03
int 10h
mov ah,4ch
mov al,00 ;terminate program
int 21h
我完全从本教程复制了这段代码。
使用 NASM 编译时会出现三个错误(不使用参数,仅使用 -o output.exe
):
14: Error: Invalid combination of opcode and operands
20: Error: Invalid combination of opcode and operands
28: Error: Invalid combination of opcode and operands
jmp start
;==============================
; Draws a horiz and vert line
;==============================
startaddr dw 0a000h ;start of video memory
colour db 1
;==============================
start:
mov ah,00
mov al,19
int 10h ;switch to 320x200 mode
;=============================
horiz:
mov es, startaddr ;put segment address in es ; <--- Error Line 14
mov di, 32000 ;row 101 (320 * 100)
add di, 75 ;column 76
mov al,colour ;cannot do mem-mem copy so use reg
mov cx, 160 ;loop counter
hplot:
mov es:[di],al ;set pixel to colour ; <--- Error
inc di ;move to next pixel
loop hplot
vert:
mov di, 16000 ;row 51 (320 * 50)
add di, 160 ;column 161
mov cx, 100 ;loop counter
vplot:
mov es:[di],al ; <--- Error
add di, 320 ;mov down a pixel
loop vplot
;=============================
keypress:
mov ah,00
int 16h ;await keypress
end:
mov ah,00
mov al,03
int 10h
mov ah,4ch
mov al,00 ;terminate program
int 21h
I copied this code exactly from this tutorial.
It comes up with three errors when compiling with NASM (using no parameters, only -o output.exe
):
14: Error: Invalid combination of opcode and operands
20: Error: Invalid combination of opcode and operands
28: Error: Invalid combination of opcode and operands
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 tanascius 对第 14 行问题的回答。此处需要
mov es, word [startaddr]
。第 20 行和第 28 行有一个共同的问题。 Nasm 需要语法
mov [es:di],al
。不需要大小前缀——它隐含在寄存器操作数中。See tanascius' answer for the problem with line 14. You need
mov es, word [startaddr]
here.Lines 20 and 28, have a common issue. Nasm requires the syntax
mov [es:di],al
. No size prefix is required -- it's implicit in the register operand.根据此 yasm 参考(请参阅内存参考),您的 NASM 可能有问题在确定引用的内存大小时:
According to this yasm reference (see Memory references) your NASM could have a problem in determining the size of the memory referenced: