4

I am trying to write a program which takes the binary input from a text file and sends it as a parameter to an assembly function. That assembly function must print this binary input to the screen. The input is sent from c code to assembly code by its address.

When I try to assemble my asm file, I get an "invalid combination of opcode and operands" error on the mov msg, [esp+8] line. I want to copy my char arg from the stack to my static variable. Why isn't that a valid instruction?

The full code is:

segment .data len equ 31 segment .bss msg resb 0 segment .text global sequence_generator sequence_generator: push ebp mov ebp, esp mov msg, [esp+8] mov eax,4 mov ebx,1 mov ecx,msg mov edx,len int 80h pop ebp ret 
2
  • 1
    mov msg, [esp+8] what you think this is doing? And this msg resb 0? And having edx equal to fixed 31 is intended? So the C code will always send 31+ characters? Commented Oct 10, 2016 at 12:44
  • BTW, if it's truly binary data, it will contain non-printable characters, which doesn't work very well in Linux, so probably you may want to do some processing over them to change unprintable values to '.', or to print hexadecimal values instead of bytes themselves. (so from data " " (triple space) you will print "20 20 20") Commented Oct 10, 2016 at 12:47

1 Answer 1

6

I wonder what have you tried to do in this line:

mov msg, [esp+8] 

But you are not allowed to move from memory to memory. Refer to this page, for instance.

If you want to move something from memory to memory, use a register as a temporary storage. For example:

mov eax, [var1] mov [var2], eax 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.