mescc: Support negative divide.
[mes.git] / module / mescc / i386 / as.scm
index e544a3b9025f7edfdf2c9886043aebf65fce531c..d3092e3a709261aa51e3db2daac5d9fc0f3edb33 100644 (file)
         (r1 (get-r1 info)))
     `((,(string-append "and____%" r1 ",%" r0)))))
 
-(define (i386:r0/r1 info)
+(define (i386:r0/r1 info signed?)
   (let ((allocated (.allocated info))
         (r0 (get-r0 info))
         (r1 (get-r1 info)))
         `(,@(if (equal? r0 "eax") '()
                 `(("push___%eax")
                   (,(string-append "mov____%" r0 ",%eax"))))
-          ("xor____%edx,%edx")
+          ,(if signed? '("cltd") '("xor____%edx,%edx"))
           (,(string-append "idiv___%" r1))
           ,@(if (equal? r0 "eax") '()
                 `((,(string-append "mov____%eax,%" r0))
           ("push___%edx")
           (,(string-append "mov____%" r1 ",%ebx"))
           (,(string-append "mov____%" r0 ",%eax"))
-          ("xor____%edx,%edx")
+          ,(if signed? '("cltd") '("xor____%edx,%edx"))
           (,(string-append "idiv___%ebx"))
           ("pop____%edx")
           ("pop____%ebx")
           (,(string-append "mov____%eax,%" r0))
           ("pop____%eax")))))
 
-(define (i386:r0%r1 info)
+(define (i386:r0%r1 info signed?)
   (let ((allocated (.allocated info))
         (r0 (get-r0 info))
         (r1 (get-r1 info)))
         `(,@(if (equal? r0 "eax") '()
                 `(("push___%eax")
                   (,(string-append "mov____%" r0 ",%eax"))))
-          ("xor____%edx,%edx")
+          ,(if signed? '("cltd") '("xor____%edx,%edx"))
           (,(string-append "idiv___%" r1))
           (,(string-append "mov____%edx,%" r0)))
         `(("push___%eax")
           ("push___%edx")
           (,(string-append "mov____%" r1 ",%ebx"))
           (,(string-append "mov____%" r0 ",%eax"))
-          ("xor____%edx,%edx")
+          ,(if signed? '("cltd") '("xor____%edx,%edx"))
           (,(string-append "idiv___%ebx"))
           ("pop____%edx")
           ("pop____%ebx")