feat: gasm-devkit 0.1.0 — GAsm lexer, parser, linter, formatter, LSP and amd64 assembler
Assisted-by: Qwen 3.8 Max Preview
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package asm
|
||||
|
||||
// Operand is an instruction operand: a Reg, a Mem reference or an Imm value.
|
||||
type Operand interface {
|
||||
isOperand()
|
||||
}
|
||||
|
||||
// Imm is an immediate value. Its encoded width is chosen by the instruction
|
||||
// (sign-extended imm8 where possible, otherwise imm32, imm64 for MOV).
|
||||
type Imm int64
|
||||
|
||||
func (Imm) isOperand() {}
|
||||
|
||||
// Mem is a memory operand of the form disp(base)(index*scale).
|
||||
type Mem struct {
|
||||
Base Reg
|
||||
Index Reg
|
||||
Scale int // 1, 2, 4 or 8; 0 means no index
|
||||
Disp int64
|
||||
Size int // operand width in bytes
|
||||
HasBase bool
|
||||
HasIndex bool
|
||||
}
|
||||
|
||||
func (Mem) isOperand() {}
|
||||
|
||||
// Ptr builds a plain displaced memory operand (base)+disp of the given size.
|
||||
func Ptr(base Reg, disp int64, size int) Mem {
|
||||
return Mem{Base: base, Disp: disp, Size: size, HasBase: true}
|
||||
}
|
||||
|
||||
// Idx builds an indexed memory operand disp(base)(index*scale).
|
||||
func Idx(base, index Reg, scale int, disp int64, size int) Mem {
|
||||
return Mem{Base: base, Index: index, Scale: scale, Disp: disp, Size: size, HasBase: true, HasIndex: true}
|
||||
}
|
||||
|
||||
// Rip builds a RIP-relative memory operand (RIP)+disp.
|
||||
func Rip(disp int64, size int) Mem {
|
||||
return Mem{Disp: disp, Size: size}
|
||||
}
|
||||
Reference in New Issue
Block a user