tags:

views:

73

answers:

3
    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
A: 

I'm not familiar with NASM, but the errors seem to be because you're targetting the wrong processor. The register ES didn't exist before 80386 (I think).

Perhaps NASM has a directive, something like .386, otherwise see if there is some other command line parameter that lets you target a platform.

deltreme
`ES` was available, even on the 8088. The `FS` and `GS` segment registers came later.
spong
Ah you're right... My bad, it's been too long since I've played with that stuff :/
deltreme
A: 

According to this yasm reference (see Memory references) your NASM could have a problem in determining the size of the memory referenced:

Usually the size of a memory reference can be deduced by which registers you're moving--for example, "mov [rax],ecx" is a 32-bit move, because ecx is 32 bits. YASM currently gives the non-obvious "invalid combination of opcode and operands" error if it can't figure out how much memory you're moving. The fix in this case is to add a memory size specifier: qword, dword, word, or byte.

Here's a 64-bit memory move, which sets 8 bytes starting at rax:
mov qword [rax], 1

Here's a 32-bit memory move, which sets 4 bytes:
mov dword [rax], 1

Here's a 16-bit memory move, which sets 2 bytes:
mov word [rax], 1

Here's an 8-bit memory move, which sets 1 byte:
mov byte [rax], 1

tanascius
+2  A: 

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.

spong