Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Nasm Error: invalid combination of opcode and operands

Writer Matthew Harrington

In my quest to learn NASM, I am trying to create a really simple program that does a division and outputs the result.

By the books, everything should run fine. I'm dividing 15 by 3, and it should automatically be stored in the AX register which I then move over to the ecx for output.

However, when I try to compile, I am getting the error

nums.asm:6: error: invalid combination of opcode and operands
nums.asm:7: error: invalid combination of opcode and operands

Does anyone know what is wrong with lines 6 and 7?

This is my code:

segment .text global main
main: div 3, 15 mov ecx, ax mov ebx,1 ; arg1, where to write, screen mov eax,4 ; write sysout command to int 80 hex int 0x80 ; interrupt 80 hex, call kernel
exit: mov eax, 1 xor ebx, ebx int 0x80

1 Answer

I keep seeing this form often: div 3, 15 this is not any valid INTEL mneumonic!

To divide 15 by 3:

xor edx, edx
mov eax, 15
mov ecx, 3
div ecx

For the second error, you cannot move a 16 bit register into a 32 bit register like that. You need to use one of the following:

xor ecx, ecx
mov cx, ax

Or:

movzx ecx, ax
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.