0

I have this assembly code for writing to video memory an pixel:

mov ax, 0x0013
int 0x10

x db 1
y db 1
videomem dd 0xa000

mov bx, y
mov ax, 0x0140 ;320
mul bx

add ax, x

mov cx, videomem
mov [cx:ax], 0x09;

jmp $
times 510-($-$$) db 0
dw 0xaa55

The problem is that NASM returns this error:

boot.asm:15: error: invalid segment override

What should I change in line 15 so that it would work? Also, I do not know what cx and ax are so that it would return this error, and so is there a compile time debugger in NASM?

Peter Cordes
  • 245,674
  • 35
  • 423
  • 606
  • 3
    You can only use `cs`, `ds`, `es`, and `ss` as segment registers. Try `mov es, videomem; mov [es:ax], 0x09`. – fuz Mar 02 '19 at 02:06
  • 1
    Not related to your question, but will definitely affect your results: you are defining x and y as bytes but reading them as words. – prl Mar 02 '19 at 02:11
  • 3
    You also can't use ax as a base register. Base registers must be bx, bp, si, or di. (@fuz) – prl Mar 02 '19 at 02:13
  • I fixed it so that it at least compiles, it doesn't show anything though, so I'm still debugging, thank you. – Murpha Schnee Mar 02 '19 at 02:27
  • 3
    On top of the other comments. You are placing data in the middle of code so data will be executed as code so you'd get strange things happen. Place all your data after `jmp $` and before the padding and disk signature. You also don't set your segment register DS to 0 to begin with. Since you didn't use an `org` it defaulted to zero so you'd have to set DS to 0x07c0 for a bootloader. In NASM if you do `mov bx, y` it moves the address of `y` to bx not the value at that memory location. You'd have to use `mov bx, [y]` . That applies to other similar instructions. – Michael Petch Mar 02 '19 at 04:12
  • I'd recommend using `org 0x7c00` at the top of the file and setting DS to 0. – Michael Petch Mar 02 '19 at 04:13
  • Here is a version that may work for you: http://www.capp-sysware.com/misc/stackoverflow/54954474.asm – Michael Petch Mar 02 '19 at 04:18
  • @MichaelPetch Wow, It actually worked! Thank you! – Murpha Schnee Mar 05 '19 at 04:32
  • 1
    I’m voting to close this question because there are too many different things wrong with it (data in the middle of code, address vs. value, type sizes, what segment regs are (CS not CX?), which regs are usable in a 16-bit addressing mode, etc.). Explaining them all in one place is unlikely to help any future readers. (For the OP, it was already answered by a link in comments which Michael Petch didn't feel was worth posting as an answer.) – Peter Cordes Feb 01 '21 at 06:48

0 Answers0