Using the CX register on 386 and AMD64 in Go Assembly

64 views
Skip to first unread message

Neven Sajko

unread,
Mar 30, 2019, 5:40:28 PM3/30/19
to golan...@googlegroups.com
The official documentation on using the Go assembly [0] says this:

> When using the compiler and assembler's -dynlink or -shared modes, any
> load or store of a fixed memory location such as a global variable must
> be assumed to overwrite CX. Therefore, to be safe for use with these
> modes, assembly sources should typically avoid CX except between memory
> references.

A couple unclear things are: what is a "fixed memory location"; and
does this apply to amd64 or just to 386?

The text implies that a writer of 386 Go assembly code should assume
CX clobbered after dereferencing SB. But what about dereferencing FP,
SP, or a real register like AX or R10, does that also clobber CX?

[0] https://golang.org/doc/asm

keith....@gmail.com

unread,
Mar 30, 2019, 7:55:43 PM3/30/19
to golang-nuts
Fixed memory location is a global variable.
This only applies to 386, not amd64.
This applies only to (SB) dereferences, not to any other (SP, FP, or standard register).

The text doesn't really say it, but it applies to LEAL as well as loads and stores.
Reply all
Reply to author
Forward
0 new messages