package asmc import ( "math" "git.akyoto.dev/cli/q/src/asm" "git.akyoto.dev/cli/q/src/config" "git.akyoto.dev/cli/q/src/x86" ) func (c *compiler) store(x asm.Instruction) { switch operands := x.Data.(type) { case *asm.MemoryNumber: if operands.Address.OffsetRegister == math.MaxUint8 { c.code = x86.StoreNumber(c.code, operands.Address.Base, operands.Address.Offset, operands.Address.Length, operands.Number) } else { c.code = x86.StoreDynamicNumber(c.code, operands.Address.Base, operands.Address.OffsetRegister, operands.Address.Length, operands.Number) } case *asm.MemoryLabel: start := len(c.code) if operands.Address.OffsetRegister == math.MaxUint8 { c.code = x86.StoreNumber(c.code, operands.Address.Base, operands.Address.Offset, operands.Address.Length, 0b00_00_00_00) } else { c.code = x86.StoreDynamicNumber(c.code, operands.Address.Base, operands.Address.OffsetRegister, operands.Address.Length, 0b00_00_00_00) } size := 4 opSize := len(c.code) - size - start memLabel := x.Data.(*asm.MemoryLabel) c.codePointers = append(c.codePointers, &pointer{ Position: Address(len(c.code) - size), OpSize: uint8(opSize), Size: uint8(size), Resolve: func() Address { destination, exists := c.codeLabels[memLabel.Label] if !exists { panic("unknown label") } return config.BaseAddress + c.codeStart + destination }, }) case *asm.MemoryRegister: if operands.Address.OffsetRegister == math.MaxUint8 { c.code = x86.StoreRegister(c.code, operands.Address.Base, operands.Address.Offset, operands.Address.Length, operands.Register) } else { c.code = x86.StoreDynamicRegister(c.code, operands.Address.Base, operands.Address.OffsetRegister, operands.Address.Length, operands.Register) } } }