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?
>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