Skip to content

Commit fa068ca

Browse files
committed
Add -z suffix jump and cmov instructions; update a86 docs
Docs now include a section about conditional flags. Closes #165.
1 parent 68dc141 commit fa068ca

3 files changed

Lines changed: 252 additions & 46 deletions

File tree

langs/a86/ast.rkt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
(error n "expects register or offset; given ~v" a2))
3838
(values a a1 a2)))
3939

40-
(define check:arith
40+
(define check:arith
4141
(λ (a a1 a2 n)
4242
(unless (register? a1)
4343
(error n "expects register; given ~v" a1))
@@ -88,7 +88,7 @@
8888
(unless (or (and (exact-integer? a2) (<= 0 a2 63))
8989
(eq? 'cl a2))
9090
(error n "expects exact integer in [0,63]; given ~v" a2))
91-
(values a a1 a2)))
91+
(values a a1 a2)))
9292

9393
(define check:offset
9494
(λ (a r i n)
@@ -150,7 +150,7 @@
150150
(syntax-case stx ()
151151
[(instruct Name (x ...) guard)
152152
(with-syntax ([Name? (datum->syntax stx (string->symbol (string-append (symbol->string (syntax->datum #'Name)) "?")))])
153-
#'(begin (provide Name Name?)
153+
#'(begin (provide Name Name?)
154154
(define-match-expander Name
155155
(lambda (stx)
156156
(syntax-case stx ()
@@ -170,13 +170,13 @@
170170
(struct->vector i2))))
171171
(define hash-proc (λ (i hash) (hash (struct->vector i))))
172172
(define hash2-proc (λ (i hash) (hash (struct->vector i))))]
173-
173+
174174
#:property prop:custom-print-quotable 'never
175175
#:methods gen:custom-write
176176
[(define write-proc
177177
(instr-print 'Name)
178178
#;(make-constructor-style-printer
179-
(lambda (obj) 'Name)
179+
(lambda (obj) 'Name)
180180
(lambda (obj)
181181
(rest (rest (vector->list (struct->vector obj)))))))])
182182
(define Name? %Name?)))]))
@@ -212,6 +212,8 @@
212212
(instruct Sub (dst src) check:arith)
213213
(instruct Cmp (a1 a2) check:src-dest)
214214
(instruct Jmp (x) check:target)
215+
(instruct Jz (x) check:target)
216+
(instruct Jnz (x) check:target)
215217
(instruct Je (x) check:target)
216218
(instruct Jne (x) check:target)
217219
(instruct Jl (x) check:target)
@@ -222,6 +224,8 @@
222224
(instruct Jno (x) check:target)
223225
(instruct Jc (x) check:target)
224226
(instruct Jnc (x) check:target)
227+
(instruct Cmovz (dst src) check:cmov)
228+
(instruct Cmovnz (dst src) check:cmov)
225229
(instruct Cmove (dst src) check:cmov)
226230
(instruct Cmovne (dst src) check:cmov)
227231
(instruct Cmovl (dst src) check:cmov)
@@ -238,9 +242,9 @@
238242
(instruct Sal (dst i) check:shift)
239243
(instruct Sar (dst i) check:shift)
240244
(instruct Push (a1) check:push)
245+
(instruct Pop (a1) check:register)
241246
(instruct Pushf () check:none)
242247
(instruct Popf () check:none)
243-
(instruct Pop (a1) check:register)
244248
(instruct Lea (dst x) check:lea)
245249
(instruct Not (x) check:register)
246250
(instruct Div (den) check:register)
@@ -340,7 +344,7 @@
340344
[(cons (Label s) asm)
341345
(cons s (label-decls asm))]
342346
[(cons (Extern s) asm)
343-
(cons s (label-decls asm))]
347+
(cons s (label-decls asm))]
344348
[(cons _ asm)
345349
(label-decls asm)]))
346350

@@ -370,7 +374,7 @@
370374
[(cons (Call (? label? s)) asm)
371375
(cons s (label-uses asm))]
372376
[(cons (Lea _ (? label? s)) asm)
373-
(cons s (label-uses asm))]
377+
(cons s (label-uses asm))]
374378
[(cons _ asm)
375379
(label-uses asm)]))
376380

langs/a86/printer.rkt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
[(Plus e1 e2)
7474
(string-append "(" (exp->string e1) " + " (exp->string e2) ")")]
7575
[_ (label-symbol->string e)]))
76-
76+
7777
(define tab (make-string 8 #\space))
7878

7979
;; Instruction -> String
@@ -84,8 +84,8 @@
8484
(format "~a~a; ~.s" s (make-string (- 40 (string-length s)) #\space) (instruction-annotation i))
8585
(format "~a ; ~.s" s (instruction-annotation i)))
8686
s)))
87-
88-
87+
88+
8989
;; Instruction -> String
9090
(define (simple-instr->string i)
9191
(match i
@@ -107,7 +107,7 @@
107107
[(Sub a1 a2)
108108
(string-append tab "sub "
109109
(arg->string a1) ", "
110-
(arg->string a2))]
110+
(arg->string a2))]
111111
[(Cmp a1 a2)
112112
(string-append tab "cmp "
113113
(arg->string a1) ", "
@@ -127,14 +127,20 @@
127127
[(Or a1 a2)
128128
(string-append tab "or "
129129
(arg->string a1) ", "
130-
(arg->string a2))]
130+
(arg->string a2))]
131131
[(Xor a1 a2)
132132
(string-append tab "xor "
133133
(arg->string a1) ", "
134134
(arg->string a2))]
135135
[(Jmp l)
136136
(string-append tab "jmp "
137137
(jump-target->string l))]
138+
[(Jz l)
139+
(string-append tab "jz "
140+
(jump-target->string l))]
141+
[(Jnz l)
142+
(string-append tab "jnz "
143+
(jump-target->string l))]
138144
[(Je l)
139145
(string-append tab "je "
140146
(jump-target->string l))]
@@ -165,6 +171,14 @@
165171
[(Jnc l)
166172
(string-append tab "jnc "
167173
(jump-target->string l))]
174+
[(Cmovz dst src)
175+
(string-append tab "cmovz "
176+
(reg->string dst) ", "
177+
(arg->string src))]
178+
[(Cmovnz dst src)
179+
(string-append tab "cmovnz "
180+
(reg->string dst) ", "
181+
(arg->string src))]
168182
[(Cmove dst src)
169183
(string-append tab "cmove "
170184
(reg->string dst) ", "
@@ -211,13 +225,13 @@
211225
[(Push a)
212226
(string-append tab "push "
213227
(arg->string a))]
228+
[(Pop r)
229+
(string-append tab "pop "
230+
(reg->string r))]
214231
[(Pushf)
215232
(string-append tab "pushf")]
216233
[(Popf)
217234
(string-append tab "popf")]
218-
[(Pop r)
219-
(string-append tab "pop "
220-
(reg->string r))]
221235
[(Lea d (? offset? x))
222236
(string-append tab "lea "
223237
(arg->string d) ", "

0 commit comments

Comments
 (0)