本文介绍了学习汇编,对代码有疑问吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    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.

使用NASM编译时会出现三个错误(不使用任何参数,仅使用-o output.exe):

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

推荐答案

有关第14行的问题,请参见tanascius的答案.您需要在此处mov es, word [startaddr].

See tanascius' answer for the problem with line 14. You need mov es, word [startaddr] here.

第20和28行有一个常见问题. Nasm需要语法mov [es:di],al.不需要大小前缀-隐含在寄存器操作数中.

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.

这篇关于学习汇编,对代码有疑问吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 10:32