diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 8be7718a50..59c59a166f 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -1260,6 +1260,7 @@ pub: mode AddressingMode pos token.Position pub mut: + segment string // fs: displacement AsmArg // 8, 16 or 32 bit literal value base AsmArg // gpr index AsmArg // gpr diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 78fdc20917..c2b969c15b 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -2488,6 +2488,9 @@ fn (mut g Gen) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt) { g.write('%$arg.name') } ast.AsmAddressing { + if arg.segment != '' { + g.write('%%$arg.segment:') + } base := arg.base index := arg.index displacement := arg.displacement @@ -2500,7 +2503,6 @@ fn (mut g Gen) asm_arg(arg ast.AsmArg, stmt ast.AsmStmt) { } .displacement { g.asm_arg(displacement, stmt) - g.write('()') } .base_plus_displacement { g.asm_arg(displacement, stmt) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 5d71961980..e160463909 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -942,6 +942,12 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt { if p.prev_tok.position().line_nr < p.tok.position().line_nr { break } + mut segment := '' + if p.tok.kind == .name && p.peek_tok.kind == .colon { + segment = p.tok.lit + p.next() + p.next() + } match p.tok.kind { .name { args << p.reg_or_alias() @@ -985,7 +991,9 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt { break } .lsbr { - args << p.asm_addressing() + mut addressing := p.asm_addressing() + addressing.segment = segment + args << addressing } .rcbr { break