OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:44 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: nasm invalid operand type
PostPosted: Mon May 11, 2020 2:42 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
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


Top
 Profile  
 
 Post subject: Re: nasm invalid operand type
PostPosted: Mon May 11, 2020 4:01 am 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
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


Top
 Profile  
 
 Post subject: Re: nasm invalid operand type
PostPosted: Mon May 11, 2020 8:22 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: nasm invalid operand type
PostPosted: Mon May 11, 2020 3:52 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
Thanks for the reply!!! you should change your profile to God_Of_assembly!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group