Skip to content

Commit d13c308

Browse files
committed
Add a86 support for division.
1 parent 52df8fa commit d13c308

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

langs/a86/ast.rkt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
(λ (a1 a2 n)
5858
(unless (register? a1)
5959
(error n "expects register; given ~v" a1))
60-
(unless (and (exact-integer? a2) (<= 0 a2 63))
60+
(unless (or (and (exact-integer? a2) (<= 0 a2 63))
61+
(eq? 'cl a2))
6162
(error n "expects exact integer in [0,63]; given ~v" a2))
6263
(values a1 a2)))
6364

@@ -142,6 +143,7 @@
142143
(instruct Push (a1) check:push)
143144
(instruct Pop (a1) check:register)
144145
(instruct Lea (dst x) check:lea)
146+
(instruct Div (den) check:register)
145147

146148
(instruct Offset (r i) check:offset)
147149
(instruct Extern (x) check:label-symbol)
@@ -170,7 +172,7 @@
170172
(define offset? Offset?)
171173

172174
(define (register? x)
173-
(and (memq x '(eax rax rbx rcx rdx rbp rsp rsi rdi r8 r9 r10 r11 r12 r13 r14 r15))
175+
(and (memq x '(cl eax rax rbx rcx rdx rbp rsp rsi rdi r8 r9 r10 r11 r12 r13 r14 r15))
174176
#t))
175177

176178
(define (label? x)
@@ -204,6 +206,7 @@
204206
(Push? x)
205207
(Pop? x)
206208
(Lea? x)
209+
(Div? x)
207210
(Comment? x)
208211
(Equ? x)
209212
(Dd? x)

langs/a86/printer.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
(string-append tab "lea "
154154
(arg->string d) ", [rel "
155155
(exp->string x) "]")]
156+
[(Div r)
157+
(string-append tab "div "
158+
(arg->string r))]
156159
[(Equ x c)
157160
(string-append tab
158161
(symbol->string x)

0 commit comments

Comments
 (0)