Basic Expression Algorithm
The basic algorithm for expressions is easy: postorder.
; given expr x, return register with value
(defun genarith (x)
(if (atom x) ; if leaf, id/num
(genload x (getreg)) ; load: mem -> reg
(genop (op x) ; else op
(genarith (lhs x)) ; on subtrees
(genarith (rhs x))) ) )
>(genarith '(* (+ a b) 3)) MOVL A,EAX MOVL B,EBX ADDL EBX,EAX MOVL 3,ECX IMULL ECX,EAX EAX