assembly - invalid instruction suffix for `mov' (movw %ax, %ebx) -


when try compile following program:

.globl _start .section    .text  _start:     movw        $-23, %ax             movl        $-1,  %ebx   # -1 = $0xffffffff             movw        %ax,  %ebx              movl        $1, %eax             movl        $0, %ebx             int         $0x80 

i error message:

demo.s: assembler messages: demo.s:7: error: invalid instruction suffix `mov' 

so, root of proglem lies here:

movw        %ax,  %ebx 

but thing don't think i'm doing totally wrong plus that's example used in book i'm reading: professional assembly language richard blum (2005)

you didn't write, want program.

first put -23 ax, -1 ebx, try move ax ebx, not valid on x86 processor, ax 16bit, , ebx 32bit register. mov can't convert width of data during processing.

to make work there 2 basic options.

  • if want lower 16b of ebx modified (by 16b ax), can mov %ax, %bx, keeping upper 16b of ebx intact. (in case result -23 in ebx/bx/bl).

  • if want extend 16b value 32b value, can either:

    1. movswl %ax, %ebx # sign-extended conversion (movsx in intel syntax)
    2. movzwl %ax, %ebx # zero-extended conversion (movzx in intel syntax)

in 1. ebx (and bx , bl well) contain -23. in 2. ebx contain 0x0000ffe9, ebx 65513, bx , bl -23 if treated signed integer. or 65513 bx , 233 in bl when treated unsigned integers.

about book... sure? read again, must typo, or overlooking tiny detail.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -