Skip to content

cmd/asm: accepts MOVB (BX)(R8*4), AH incorrectly #14288

Closed

Description

@randall77

MOVB (BX)(R8*4), AH
The assembler accepts this instruction but silently misassembles it to:
MOVB (BX)(R8*4), SP
This is because we need the RAX prefix for the indexed address, but then the RAX prefix also forces the use of standard register naming instead of the weird *H register naming.

gas rejects this instruction movb (%rbx,%r8,4),%ah with can't encode register '%ah' in an instruction requiring REX prefix.

@rsc

Activity

  1. added this to the Go1.7 milestone on Feb 10, 2016
  2. changed the title [-]bad assembly accepted, misassembled[/-] [+]cmd/asm: bad assembly accepted, misassembled[/+] on Feb 10, 2016
  3. rsc commented on Feb 10, 2016

    @rsc
    Contributor

    We'll catch this as part of the big asm fixup.

  4. rsc commented on Feb 10, 2016

    @rsc
    Contributor

    But expanding what I said yesterday just a bit: never use MOVB or MOVW with a register destination, since it's inefficient (it's a read-modify-write on the target register). Instead use MOVL for reg->reg and use MOVBLZX or MOVWLZX for mem->reg; those are pure writes on the target register.

  5. rsc commented on Feb 10, 2016

    @rsc
    Contributor

    Actually, on third glance I'm even more surprised you are trying to address AH (not AL). Why?

  6. randall77 commented on Feb 11, 2016

    @randall77
    ContributorAuthor

    SSA never uses AH. I just ran into this while writing a test case.

  7. modified the milestones: Go1.8, Go1.7 on May 19, 2016
  8. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Oct 5, 2016
  9. modified the milestones: Go1.9, Go1.8 on Oct 21, 2016
  10. changed the title [-]cmd/asm: bad assembly accepted, misassembled[/-] [+]cmd/asm: accepts MOVB (BX)(R8*4), AH incorrectly[/+] on Oct 21, 2016
  11. modified the milestones: Go1.10, Go1.9 on Jun 26, 2017
  12. modified the milestones: Go1.10, Go1.11 on Nov 22, 2017
  13. modified the milestones: Go1.11, Unplanned on May 23, 2018
  14. gopherbot commented on Oct 19, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/849950 mentions this issue: cmd/internal/obj/x86: reject high byte registers with REX prefix

  15. added a commit that references this issue on Oct 30, 2026
    b0d3d28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions