4 Replies - 510 Views - Last Post: 25 October 2013 - 10:44 PM

#1 ValenL  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 26
  • Joined: 26-March 13

Invalid combination of opcode and operands

Posted 24 October 2013 - 07:56 PM

The goal of this is to get input from a text file and in the text file there are 8 numbers set up as such
1 2 4 8
17 11 5 3

I have input the file then get the output showing Area/Points/Probability and Expected Outcome
I have the math all done on an excel sheet.

but between Area and Expected Outcome I'm getting the invalid combination of opcode and operands error. So far I have been good with assignments but this one just messing me up.

Any help would be greatly appreciated.


%include "asm_io.inc"
;
segment .data
display dd "Area: %d | Points: %d | Probability: %d", 10, 0
display2 dd "Expected Outsome: %d", 0
radiusone dd "Enter number ", 0
radiustwo dd "Enter number ", 0
radiusthree dd "Enter number ", 0
radiusfour dd "Enter number ", 0
pointsone dd "Enter number ", 0
pointstwo dd "Enter number ", 0
pointsthree dd "Enter number ", 0
pointsfour dd "Enter number ", 0
;
segment .bss
;
r1 resd 1 ;Radius
r2 resd 1
r3 resd 1
r4 resd 1
p1 resd 1 ;Points
p2 resd 1
p3 resd 1
p4 resd 1
ca1 resd 1 ;Computed Area
ca2 resd 1
ca3 resd 1
ca4 resd 1
pi1 resd 1 ;radius*radius
pi2 resd 1
pi3 resd 1
pi4 resd 1
pb1 resd 1 ;Probability
pb2 resd 1
pb3 resd 1
pb4 resd 1
o1 resd 1 ;Outcome
o2 resd 1
o3 resd 1
o4 resd 1
eo resd 1 ; Expected Outcome
;
; code is put in the .text segment
;
segment .text
        global  asm_main
	extern printf
asm_main:
        enter   0,0               ; setup routine
        pusha
		
		mov eax, radiusone
		call print_string
		call read_int
		mov [r1], eax
		
		mov eax, radiustwo
		call print_string
		call read_int
		mov [r2], eax
		
		mov eax, radiusthree
		call print_string
		call read_int
		mov [r3], eax
		
		mov eax, radiusfour
		call print_string
		call read_int
		mov [r4], eax
		;****************Radius End****************
		mov eax, pointsone
		call print_string
		call read_int
		mov [p1], eax
		
		mov eax, pointstwo
		call print_string
		call read_int
		mov [p2], eax
		
		mov eax, pointsthree
		call print_string
		call read_int
		mov [p3], eax
		
		mov eax, pointsfour
		call print_string
		call read_int
		mov [p4], eax
		;****************Area****************
		
		imul [pi1], r1
		imul [pi2], r2
		imul [pi3], r3
		imul [pi4], r4
		
		;***************Computed Area*******************
		
		sub [ca1], pi1
		sub [ca2], pi2, pi1
		sub [ca3], pi3, pi2
		sub [ca4], pi4, pi3
		
		;***************Probability*********
		
		idiv [pb1], ca1, pi4
		idiv [pb2], ca2, pi4
		idiv [pb3], ca3, pi4
		idiv [pb4], ca4, pi4
		
		;***************Outcome***********
		
		imul [o1], pb1, p1
		imul [o2], pb2, p2
		imul [o3], pb3, p3
		imul [o4], pb4, p4
		;***************Expected Outcome***************
		
		mov [eo], o1+o2+o3+o4
		;***************Display******
		
		mov dword [esp + 12], pb1
		mov dword [esp + 8], p1
		mov dword [esp + 4], r1
		
		
		mov dword [esp], display
		call printf
		
		
        popa
        mov     eax, 0            
        leave                     
        ret



This post has been edited by ValenL: 24 October 2013 - 07:58 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Invalid combination of opcode and operands

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,282
  • Joined: 28-March 11

Re: Invalid combination of opcode and operands

Posted 24 October 2013 - 10:08 PM

When there is an error during Assembly, NASM will give you the line number the error occurred. Please post the exact error messages when posting your code with errors.
When I attempted to Assemble your code, this is what I got:

Quote

InvalOp.asm:120: error: invalid operand type


Now, when I click on that in the Compiler Output of my editor, it takes me right to line 120:
mov [eo], o1+o2+o3+o4

What is that? I will take a guess and say you are trying to take o1, o2, o3, and o4 and add them all up and place the result into eo? Doesn't work like that in Assembly. To add all those values together and put the result into the "Expected Output" variable you would need to do something along the lines of:
mov     eax, [o1]
add     eax, [o2]
add     eax, [o3]
add     eax, [o4]
mov     [eo], eax


Ok, that fixes the error: "InvalOp.asm:120: error: invalid operand type", Now we try to Assemble again... Whoa, 16 errors!!!

Quote

make (in directory: D:\NASM Projects\DIC\ValenL\InvalidOpcodes)
nasm -f win32 InvalOp.asm -o InvalOp.obj
InvalOp.asm:93: error: invalid combination of opcode and operands
InvalOp.asm:94: error: invalid combination of opcode and operands
InvalOp.asm:95: error: invalid combination of opcode and operands
InvalOp.asm:96: error: invalid combination of opcode and operands
InvalOp.asm:100: error: operation size not specified
InvalOp.asm:101: error: invalid combination of opcode and operands
InvalOp.asm:102: error: invalid combination of opcode and operands
InvalOp.asm:103: error: invalid combination of opcode and operands
InvalOp.asm:107: error: invalid combination of opcode and operands
InvalOp.asm:108: error: invalid combination of opcode and operands
InvalOp.asm:109: error: invalid combination of opcode and operands
InvalOp.asm:110: error: invalid combination of opcode and operands
InvalOp.asm:114: error: invalid combination of opcode and operands
InvalOp.asm:115: error: invalid combination of opcode and operands
InvalOp.asm:116: error: invalid combination of opcode and operands
InvalOp.asm:117: error: invalid combination of opcode and operands
make: *** [InvalOp.obj] Error 1
Compilation failed.


Let's goto line 93:
imul [pi1], r1

Hmm, let's look up the instruction imul. Well, there is no encoding for memory to memory operation. So, how would we fix that? Same for the other errors, they don't do memory to memory. Too late now, try to fix those.
Was This Post Helpful? 1
  • +
  • -

#3 ValenL  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 26
  • Joined: 26-March 13

Re: Invalid combination of opcode and operands

Posted 25 October 2013 - 12:51 AM

Thank you GunnerInc for the reply.

I have modified my code and eliminated those errors and at the moment I am now tackling a single "Floating point exception" and I think it has to do with the idiv portion of my code from what I checked.

Code has been updated.

%include "asm_io.inc"
;
; initialized data is put in the .data segment
;
segment .data
display dd "Area: %d | Points: %d | Probability: %d", 10, 0
display2 dd "Expected Outsome: %d", 0
radiusone dd "Enter number ", 0
radiustwo dd "Enter number ", 0
radiusthree dd "Enter number ", 0
radiusfour dd "Enter number ", 0
pointsone dd "Enter number ", 0
pointstwo dd "Enter number ", 0
pointsthree dd "Enter number ", 0
pointsfour dd "Enter number ", 0

;
; uninitialized data is put in the .bss segment
;
segment .bss
;
r1 resd 1 ;Radius
r2 resd 1
r3 resd 1
r4 resd 1
p1 resd 1 ;Points
p2 resd 1
p3 resd 1
p4 resd 1
ca1 resd 1 ;Computed Area
ca2 resd 1
ca3 resd 1
ca4 resd 1
pi1 resd 1 ;radius*radius
pi2 resd 1
pi3 resd 1
pi4 resd 1
pb1 resd 1 ;Probability
pb2 resd 1
pb3 resd 1
pb4 resd 1
o1 resd 1 ;Outcome
o2 resd 1
o3 resd 1
o4 resd 1
eo resd 1 ; Expected Outcome
;
; code is put in the .text segment
;
segment .text
        global  asm_main
		extern printf
asm_main:
        enter   0,0               ; setup routine
        pusha
		;***************CODE STARTS HERE***************************
		mov eax, radiusone
		call print_string
		call read_int
		mov [r1], eax
		
		mov eax, radiustwo
		call print_string
		call read_int
		mov [r2], eax
		
		mov eax, radiusthree
		call print_string
		call read_int
		mov [r3], eax
		
		mov eax, radiusfour
		call print_string
		call read_int
		mov [r4], eax
		;****************Radius End****************
		mov eax, pointsone
		call print_string
		call read_int
		mov [p1], eax
		
		mov eax, pointstwo
		call print_string
		call read_int
		mov [p2], eax
		
		mov eax, pointsthree
		call print_string
		call read_int
		mov [p3], eax
		
		mov eax, pointsfour
		call print_string
		call read_int
		mov [p4], eax
		;****************Points End****************
		
		mov eax, [pi1]
		imul eax, r1
		mov [pi1], eax 
		
		mov eax, [pi2]
		imul eax, r2
		mov [pi2], eax 
		
		mov eax, [pi3]
		imul eax, r3
		mov [pi3], eax 
		
		mov eax, [pi4]
		imul eax, r4
		mov [pi4], eax 
		
		;***************Area End*******************
		
		mov eax, [r1]
		mov [ca1], eax
		
		mov eax, [pi2]
		sub eax, [pi1]
		mov [ca2], eax 
		
		mov eax, [pi3]
		sub eax, [pi2]
		mov [ca3], eax 
		
		mov eax, [pi4]
		sub eax, [pi3]
		mov [ca4], eax 
		
		;***************Computed Area Ends*********
		
		mov ebx, [ca1]
		mov eax, pi4
		idiv ebx
		mov [ca1], ebx
		
		mov ebx, [ca2]
		idiv ebx, eax
		mov [ca2], ebx 
		
		mov ebx, [ca3]
		idiv ebx, eax
		mov [ca3], ebx 
		
		mov ebx, [ca4]
		idiv ebx, eax
		mov [ca4], ebx  
		
		;***************Probability Ends***********
		
		mov eax, [pb1]
		imul eax, p1
		mov [o1], eax
		
		mov eax, [pb2]
		imul eax, p2
		mov [o2], eax 
		
		mov eax, [pb3]
		imul eax, p3
		mov [o3], eax
		
		mov eax, [pb4]
		imul eax, p4
		mov [o4], eax
		
		;***************Outcome Ends***************
		
		mov eax, [o1]
		add eax, [o2]
		add eax, [o3]
		add eax, [o4]
		mov [eo], eax
		;***************Expected Outcome Ends******
		
		mov dword [esp + 12], pb1
		mov dword [esp + 8], p1
		mov dword [esp + 4], r1
		
		
		mov dword [esp], display
		call printf
		
		;***************CODE ENDS HERE*****************************
        popa
        mov     eax, 0            ; return back to C
        leave                     
        ret



This post has been edited by ValenL: 25 October 2013 - 12:56 AM

Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,282
  • Joined: 28-March 11

Re: Invalid combination of opcode and operands

Posted 25 October 2013 - 09:56 PM

Oh crap, I did not press the post button and lost the long but good post. Here is the short version.

Your seg fault is from terminating your program the wrong way. You are linking against the C Library, and it adds code to your executable that gets called before your code. You need to call exit (from the C lib) at the end of your code, not use ret.

extern printf, exit


    mov		eax, 0                    
    call 	exit


Also, your output is wrong!! What is the difference between: pb1 and [pb1]?? The first is the address of the variable, the second is the value. Which do you want displayed?

I will nitpick here... Use better variable names!!! A 1 (one) looks very similar to a lowercase l (el)

All this:
radiusone db "Enter number ", 0
radiustwo db "Enter number ", 0
radiusthree db "Enter number ", 0
radiusfour db "Enter number ", 0
pointsone db "Enter number ", 0
pointstwo db "Enter number ", 0
pointsthree db "Enter number ", 0
pointsfour db "Enter number ", 0

Is not needed, they are all the same string, just use one! You have an unneeded extra 98 bytes in your exe!
Was This Post Helpful? 1
  • +
  • -

#5 ValenL  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 26
  • Joined: 26-March 13

Re: Invalid combination of opcode and operands

Posted 25 October 2013 - 10:44 PM

my instructor gave class these preset files that we have to use. In ways im stuck with what its set at in regards to using ret.

I want to data in the variable displayed. So I'll have to use [var] to achieve that I'm assuming.

I don't mind the nitpicking at all. I did choose a crappy naming scheme for this. Though I should have taken the extra time to write out a better one.

I don't know what I was thinking in terms of using that many strings.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1