diff --git a/asm/assemble.go b/asm/assemble.go index 1be3793..f0f2648 100644 --- a/asm/assemble.go +++ b/asm/assemble.go @@ -261,6 +261,11 @@ func subSP(size int) []byte { // SUBQ $size, SP if size >= -128 && size <= 127 { return []byte{0x48, 0x83, 0xEC, byte(int8(size))} } + // 128..255 do not fit SUB's unsigned imm8, but the Go assembler + // switches to ADDQ $-size, SP whose sign-extended imm8 does. + if size >= -255 && size <= 255 { + return []byte{0x48, 0x83, 0xC4, byte(int8(-size))} + } return append([]byte{0x48, 0x81, 0xEC}, le32(int64(size))...) }