X64: jmp to a register
| @@ -1401,6 +1401,13 @@ | ||
| 1401 | 1401 | return nil; |
| 1402 | 1402 | end; |
| 1403 | 1403 | |
| 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 | + | |
| 1404 | 1411 | (* One instruction or label, as assemble reads it *) |
| 1405 | 1412 | proc statement(constExpr: ConstFn): ERROR; |
| 1406 | 1413 | var |
| @@ -1441,7 +1448,7 @@ | ||
| 1441 | 1448 | if Scan.tok # Scan.sComma then break; end; |
| 1442 | 1449 | Scan.next; |
| 1443 | 1450 | 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 | |
| 1445 | 1452 | (* a jump to a label *) |
| 1446 | 1453 | k := try lab(Scan.id); |
| 1447 | 1454 | Scan.next; |
| @@ -0,0 +1,4 @@ | ||
| 1 | +test/err/AsmJccRegister.raz:4:5: error: unknown instruction jz | |
| 2 | + 4 | jz rax; | |
| 3 | + | ^^ | |
| 4 | +raz: 1 error |
| @@ -0,0 +1,6 @@ | ||
| 1 | +module AsmJccRegister; | |
| 2 | +proc f; | |
| 3 | +code | |
| 4 | + jz rax; | |
| 5 | +end f; | |
| 6 | +end AsmJccRegister. |
| @@ -7,5 +7,6 @@ | ||
| 7 | 7 | 13 |
| 8 | 8 | 40 42 |
| 9 | 9 | 42 42 |
| 10 | +42 | |
| 10 | 11 | cdef 0 |
| 11 | 12 | 100 -1 |
| @@ -120,6 +120,12 @@ | ||
| 120 | 120 | db 0C3H; |
| 121 | 121 | end answer; |
| 122 | 122 | |
| 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 | + | |
| 123 | 129 | (* s without its first k bytes: s in rdi and rsi, k in rdx, the slice back in rax and rdx *) |
| 124 | 130 | proc tail(s: []U8; k: INT): []U8; |
| 125 | 131 | code |
| @@ -162,6 +168,7 @@ | ||
| 162 | 168 | c := 40; |
| 163 | 169 | Out.int(fetchAdd(ADR(c), 2)); Out.str(" "); Out.int(c); Out.ln; |
| 164 | 170 | Out.int(I64(two() * 21.0)); Out.str(" "); Out.int(answer()); Out.ln; |
| 171 | + Out.int(through(answer)); Out.ln; | |
| 165 | 172 | t := "abcdef"; |
| 166 | 173 | Out.str(tail(t[0..6], 2)); Out.str(" "); Out.int(LEN(tail(t[0..6], 6))); Out.ln; |
| 167 | 174 | Out.int(pick(3, t[0..6])); Out.str(" "); Out.int(pick(9, t[0..6])); Out.ln; |