raz / commit ac3c464a

commit
ac3c464a51a08c8400530dfa68a5e8f829a60112
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
ea3cb399
X64: jmp to a register

patch · log

5 files changed, +26 -1

src/X64.raz (history) modified +8 -1

@@ -1401,6 +1401,13 @@
14011401 return nil;
14021402 end;
14031403
1404+(* Whether the identifier at the scan is a register name, not a label *)
1405+proc atRegister(): BOOL;
1406+var r, size: INT;
1407+begin
1408+ return isReg(asmWord(), ADR(r), ADR(size));
1409+end;
1410+
14041411 (* One instruction or label, as assemble reads it *)
14051412 proc statement(constExpr: ConstFn): ERROR;
14061413 var
@@ -1441,7 +1448,7 @@
14411448 if Scan.tok # Scan.sComma then break; end;
14421449 Scan.next;
14431450 until false;
1444- elsif (aw[0] = 'j') and ((aw = "jmp") or (cond(part(aw, 1, 3)) >= 0)) and (Scan.tok = Scan.sIdent) then
1451+ elsif (aw[0] = 'j') and ((aw = "jmp") or (cond(part(aw, 1, 3)) >= 0)) and (Scan.tok = Scan.sIdent) and not atRegister() then
14451452 (* a jump to a label *)
14461453 k := try lab(Scan.id);
14471454 Scan.next;

test/err/AsmJccRegister.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AsmJccRegister.raz:4:5: error: unknown instruction jz
2+ 4 | jz rax;
3+ | ^^
4+raz: 1 error

test/err/AsmJccRegister.raz (history) added +6 -0

@@ -0,0 +1,6 @@
1+module AsmJccRegister;
2+proc f;
3+code
4+ jz rax;
5+end f;
6+end AsmJccRegister.

test/run/Asm.expect (history) modified +1 -0

@@ -7,5 +7,6 @@
77 13
88 40 42
99 42 42
10+42
1011 cdef 0
1112 100 -1

test/run/Asm.raz (history) modified +7 -0

@@ -120,6 +120,12 @@
120120 db 0C3H;
121121 end answer;
122122
123+(* the procedure f, jumped to through a register: its result comes back as ours *)
124+proc through(f: proc: I64): I64;
125+code
126+ jmp rdi;
127+end through;
128+
123129 (* s without its first k bytes: s in rdi and rsi, k in rdx, the slice back in rax and rdx *)
124130 proc tail(s: []U8; k: INT): []U8;
125131 code
@@ -162,6 +168,7 @@
162168 c := 40;
163169 Out.int(fetchAdd(ADR(c), 2)); Out.str(" "); Out.int(c); Out.ln;
164170 Out.int(I64(two() * 21.0)); Out.str(" "); Out.int(answer()); Out.ln;
171+ Out.int(through(answer)); Out.ln;
165172 t := "abcdef";
166173 Out.str(tail(t[0..6], 2)); Out.str(" "); Out.int(LEN(tail(t[0..6], 6))); Out.ln;
167174 Out.int(pick(3, t[0..6])); Out.str(" "); Out.int(pick(9, t[0..6])); Out.ln;