Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

error: invalid operand type when mutiplying by register

I am trying to make a OS and am writing the print function in 32 bit protected mode nasm. Here is my code:

mov edx, 1
mov ebx, 0xb8000+160*edx
inc edx

However when I run this I get the following error:

kernel.asm:23: error: invalid operand type

Why is this error happening and how do I fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Thing is that your instruction is invalid, because the SIB byte of the instruction encoding on x86 ISA only allows scale factors of 2,4 and 8.

But with mov ebx, 0xb8000+160*edx you tried to scale EDX by 160. And this is not a valid scale factor. You have to calculate the value with other instructions like MUL and SHL or INC to get the resulting value you want.

For example, you can do the following calculation:

mov eax, 160    ; set decimal value 160
mul edx         ; EAX:EDX = eax*edx
add eax,0B8000h ; Add value to lower 32-bits of the result
mov ebx, eax    ; EBX = EAX
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading