OSDev.org
https://forum.osdev.org/

nasm invalid operand type
https://forum.osdev.org/viewtopic.php?f=1&t=36748
Page 1 of 1

Author:  ITchimp [ Mon May 11, 2020 2:42 am ]
Post subject:  nasm invalid operand type

was practising writing a boot loader,

in print, [sp+2] is causing the issue,
but move si, [bp+4] on the other hand is no problem..
what is wrong with [sp+2] expression?


Code:
print:

  mov ax, [sp+2]              ; si points to start of message
 

  ;mov si, [bp+4]      ; grab the pointer to the data
  mov bh, 0x00
  mov bl, 0x00
  mov ah, 0x0E

.loop:
  mov al, [si]
  inc si
  cmp al,0
  je return
  int 0x10
  jmp .loop


return: 

 


ret 2

Author:  PeterX [ Mon May 11, 2020 4:01 am ]
Post subject:  Re: nasm invalid operand type

ITchimp wrote:
what is wrong with [sp+2] expression?

SP is wrong.
If I remember correctly, BP, SI and DI can be used the way you do. But not SP.

Greetings
Peter

Author:  Octocontrabass [ Mon May 11, 2020 8:22 am ]
Post subject:  Re: nasm invalid operand type

ITchimp wrote:
what is wrong with [sp+2] expression?

32-bit memory operands are really convenient. They work like this:

[ base + (index * scale) + displacement ]

"Base" may be EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, or nothing.
"Index" may be EAX, ECX, EDX, EBX, EBP, ESI, EDI, or nothing (but it can't be ESP).
"Scale" may be 1, 2, 4, or 8.
"Displacement" may be any 32-bit integer, including zero.
Additionally, if "base" is ESP or EBP, the default segment is SS instead of DS.

16-bit memory operands are a lot less convenient. They work like this:

[ base + index + displacement ]

"Base" may be BX, BP, or nothing.
"Index" may be SI, DI, or nothing.
"Displacement" may be any 16-bit integer, including zero.
Additionally, if "base" is BP, the default segment is SS instead of DS.

Since SP is not allowed to be the base or index in a 16-bit memory operand, you have two choices: use a different register, or use a 32-bit memory operand.

I wouldn't recommend using a 32-bit memory operand. In real mode, an effective address that doesn't fit within 16 bits will cause an exception, so you need extra code to make a 32-bit memory operand work. Since you're writing a bootloader, you may not have space for that extra code.

Author:  ITchimp [ Mon May 11, 2020 3:52 pm ]
Post subject:  Re: nasm invalid operand type

Thanks for the reply!!! you should change your profile to God_Of_assembly!!!

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/