2017-04-02 10:29:09 +00:00
|
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
|
|
|
|
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of Mes.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2017-05-21 20:25:02 +00:00
|
|
|
|
;;; as-i386.mes defines i386 assembly
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(cond-expand
|
|
|
|
|
(guile-2)
|
|
|
|
|
(guile)
|
|
|
|
|
(mes
|
mescc: Remove ELF creation, handled by hex2 now.
* module/language/c99/compiler.scm (make-global, global:type,
global:pointer, global:value): Move from elf-util.mes
* module/mes/as.mes: New file.
* module/mes/as-i386.mes: Use it.
* module/mes/as-i386.scm: Use it.
* module/mes/elf-util.mes: Remove.
* module/mes/elf.mes (elf32-addr, elf32-half, elf32-off, elf32-word,
make-elf, write-any, object->elf): Remove
(hex2->elf): New function with dummy implementation.
* module/mes/elf.scm: Update exports.
* module/mes/hex2.mes (object->elf): New function.
* module/mes/hex2.scm: Export it.
2017-06-25 07:26:25 +00:00
|
|
|
|
(mes-use-module (mes as))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-20 08:05:48 +00:00
|
|
|
|
(define (i386:nop)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
'(("nop")))
|
2017-07-20 08:05:48 +00:00
|
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
|
(define (i386:function-preamble)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
'(("push___%ebp")
|
|
|
|
|
("mov____%esp,%ebp")))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:function-locals)
|
2017-07-25 08:01:12 +00:00
|
|
|
|
`(("sub____%esp,$i32" (#:immediate ,(+ (* 4 1025) (* 20 4)))))) ; sub %esp,xxx 4*1024 buf, 20 local vars
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:push-label label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("push___$i32" (#:address ,label)))) ; push $0x<label>
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:push-label-mem label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____0x32,%eax" (#:address ,label)) ; mov 0x804a000,%eax
|
|
|
|
|
("push___%eax"))) ; push %eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-24 06:36:43 +00:00
|
|
|
|
|
|
|
|
|
;;; locals
|
|
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
|
(define (i386:push-local n)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or n (error "invalid value: push-local: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("push___0x8(%ebp)" (#:immediate1 ,n))
|
|
|
|
|
`("push___0x32(%ebp)" (#:immediate ,n))))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:push-local-address n)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or n (error "invalid value: push-local-address: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("lea____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("lea____0x32(%ebp),%eax" (#:immediate ,n)))
|
|
|
|
|
("push___%eax"))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
|
(define (i386:push-byte-local-de-ref n)
|
|
|
|
|
(or n (error "invalid value: push-byte-local-de-ref: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%ebp),%eax" (#:immediate ,n)))
|
|
|
|
|
("movzbl_(%eax),%eax")
|
|
|
|
|
("push___%eax"))))
|
2017-04-17 00:15:11 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:push-byte-local-de-de-ref n)
|
|
|
|
|
(or n (error "invalid value: push-byte-local-de-de-ref: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%ebp),%eax" (#:immediate ,n)))
|
|
|
|
|
("mov____(%eax),%eax")
|
|
|
|
|
("movzbl_(%eax),%eax")
|
|
|
|
|
("push___%eax"))))
|
2017-04-17 00:15:11 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:push-local-de-ref n)
|
|
|
|
|
(or n (error "invalid value: push-byte-local-de-ref: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%ebp),%eax" (#:immediate ,n)))
|
|
|
|
|
("mov____(%eax),%eax")
|
|
|
|
|
("push___%eax"))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local-add n v)
|
|
|
|
|
(or n (error "invalid value: i386:local-add: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (and (< (abs n) #x80)
|
|
|
|
|
(< (abs v) #x80)) `("add____$i8,0x8(%ebp)" (#:immediate1 ,n) (#:immediate1 ,v))
|
|
|
|
|
`("add____$i32,0x32(%ebp)" (#:immediate ,n) (#:immediate ,v))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:accu->local n)
|
|
|
|
|
(or n (error "invalid value: accu->local: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____%eax,0x8(%ebp)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%eax,0x32(%ebp)" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:base->local n)
|
|
|
|
|
(or n (error "invalid value: base->local: " n))
|
|
|
|
|
`(("mov____%edx,0x8(%ebp)" ,(- 0 (* 4 n))))) ; mov %edx,-<0xn>(%ebp)
|
|
|
|
|
|
|
|
|
|
(define (i386:base->local n)
|
|
|
|
|
(or n (error "invalid value: base->local: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`((if (< (abs n) #x80) `("mov____%edx,0x8(%ebp)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%edx,0x32(%ebp)" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local->accu n)
|
|
|
|
|
(or n (error "invalid value: local->accu: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%ebp),%eax" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local-address->accu n)
|
|
|
|
|
(or n (error "invalid value: ladd: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("lea____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("lea____0x32(%ebp),%eax" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local-ptr->accu n)
|
|
|
|
|
(or n (error "invalid value: local-ptr->accu: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(("mov____%ebp,%eax") ; mov %ebp,%eax
|
|
|
|
|
,(if (< (abs n) #x80) `("add____$i8,%eax" (#:immediate1 ,n))
|
|
|
|
|
`("add____$i32,%eax" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:byte-local->accu n)
|
|
|
|
|
(or n (error "invalid value: byte-local->accu: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("movzbl_0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("movzbl_0x32(%ebp),%eax" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:byte-local->base n)
|
|
|
|
|
(or n (error "invalid value: byte-local->base: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("movzbl_0x8(%ebp),%edx" (#:immediate1 ,n))
|
|
|
|
|
`,@(("mov_0x32(%ebp),%edx" (#:immediate ,n))
|
|
|
|
|
("movzbl_%dl,%edx"))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local->base n)
|
|
|
|
|
(or n (error "invalid value: local->base: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%ebp),%edx" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%ebp),%edx" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local-address->base n) ;; DE-REF
|
|
|
|
|
(or n (error "invalid value: local-address->base: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("lea____0x8(%ebp),%edx" (#:immediate1 ,n))
|
|
|
|
|
`("lea____0x32(%ebp),%edx" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local-ptr->base n)
|
|
|
|
|
(or n (error "invalid value: local-ptr->base: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(("mov____%ebp,%edx") ; mov %ebp,%edx
|
|
|
|
|
,(if (< (abs n) #x80) `("add____$i8,%edx" (#:immediate1 ,n))
|
|
|
|
|
`("add____$i32,%edx" (#:immediate ,n))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:value->local n v)
|
|
|
|
|
(or n (error "invalid value: value->local: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____$i32,0x8(%ebp)" (#:immediate1 ,n) (#:immediate ,v))
|
|
|
|
|
`("mov____$i32,0x32(%ebp)" (#:immediate ,n) (#:immediate ,v))))))
|
|
|
|
|
|
|
|
|
|
(define (i386:local-test n v)
|
|
|
|
|
(or n (error "invalid value: local-test: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(cond ((and (< (abs n) #x80)
|
|
|
|
|
(< (abs v) #x80)) `("cmp____$i8,0x8(%ebp)" (#:immediate1 ,n) (#:immediate1 ,v)))
|
|
|
|
|
((< (abs n) #x80) `("cmp____$i32,0x8(%ebp)" (#:immediate1 ,n) (#:immediate ,v)))
|
|
|
|
|
((< (abs v) #x80) `("cmp____$i8,0x32(%ebp)" (#:immediate ,n) (#:immediate1 ,v)))
|
|
|
|
|
(else `("cmp____$i32,0x32(%ebp)" (#:immediate ,n) (#:immediate ,v)))))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:pop-accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("pop____%eax"))) ; pop %eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:push-accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("push___%eax"))) ; push %eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:pop-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("pop____%edx"))) ; pop %edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:push-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("push___%edx"))) ; push %edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:ret)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("leave") ; leave
|
|
|
|
|
("ret"))) ; ret
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu->base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%eax,%edx"))) ; mov %eax,%edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu->base-address)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%eax,(%edx)"))) ; mov %eax,(%edx)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-accu->base-address)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%al,(%edx)"))) ; mov %al,(%edx)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu->base-address+n n)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or n (error "invalid value: accu->base-address+n: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____%eax,0x8(%edx)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%eax,0x32(%edx)" (#:immediate ,n)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:accu->label label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____%eax,0x32" (#:address ,label)))) ; mov %eax,0x<label>
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu-zero?)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("test___%eax,%eax")))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu-shl n)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or n (error "invalid value: accu:shl n: " n))
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("shl____$i8,%eax" (#:immediate1 ,n)))) ; shl $0x8,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-03-24 21:32:02 +00:00
|
|
|
|
(define (i386:accu<<base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("xor____%ecx,%ecx") ; xor %ecx,%ecx
|
|
|
|
|
("mov____%edx,%ecx") ; mov %edx,%ecx
|
|
|
|
|
("shl____%cl,%eax"))) ; shl %cl,%eax
|
2017-03-24 21:32:02 +00:00
|
|
|
|
|
2017-03-25 17:48:40 +00:00
|
|
|
|
(define (i386:accu>>base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("xor____%ecx,%ecx") ; xor %ecx,%ecx
|
|
|
|
|
("mov____%edx,%ecx") ; mov %edx,%ecx
|
|
|
|
|
("shr____%cl,%eax"))) ; shr %cl,%eax
|
2017-03-25 17:48:40 +00:00
|
|
|
|
|
2017-05-06 12:57:39 +00:00
|
|
|
|
(define (i386:accu-and-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("and____%edx,%eax"))) ; and %edx,%eax
|
2017-05-06 12:57:39 +00:00
|
|
|
|
|
2017-07-21 08:39:04 +00:00
|
|
|
|
(define (i386:accu-not)
|
|
|
|
|
'(("not____%eax"))) ; not %eax
|
|
|
|
|
|
|
|
|
|
(define (i386:accu-or-base)
|
|
|
|
|
'(("or_____%edx,%eax"))) ; or %edx,%eax
|
|
|
|
|
|
2017-05-06 12:57:39 +00:00
|
|
|
|
(define (i386:accu-xor-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("xor____%edx,%eax"))) ; xor %edx,%eax
|
2017-05-06 12:57:39 +00:00
|
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
|
(define (i386:accu+accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("add____%eax,%eax"))) ; add %eax,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu+base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("add____%edx,%eax"))) ; add %edx,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu+value v)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs v) #x80) `("add____$i8,%eax" (#:immediate1 ,v))
|
|
|
|
|
`("add____$i32,%eax" (#:immediate ,v)))))
|
|
|
|
|
|
|
|
|
|
(define (i386:base+value v)
|
|
|
|
|
`(,(if (< (abs v) #x80) `("add____$i8,%edx" (#:immediate1 ,v))
|
|
|
|
|
`("add____$i32,%edx" (#:immediate ,v)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("sub____%edx,%eax"))) ; sub %edx,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
(define (i386:accu*base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mul____%edx"))) ; mul %edx
|
mescc: Mini-mes (gcc-compiled) runs read-0.mes.
* module/language/c99/compiler.mes (expr->accu): Add mul.
(test->jump->info): Add le, ge.
(ast->info): Support int and char* initialization at top level.
* module/mes/as-i386.mes (i386:accu*base, i386:Xjump-cz,
i386:Xjump-ncz): New function.
* module/mes/as-i386.scm: Export them.
* doc/examples/t.c (test): Test them.
* module/mes/libc.mes (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
(libc): Export them.
* module/mes/mini-0.mes: Load full reader.
* mlibc.c (ungetc): New function.
(getchar): Support it.
(assert_fail, isdigit): New functions.
* mes.c (list length error lookup_ getchar ungetchar peekchar
peek_byte read_byte unread_byte greater_p less_p): Move functions
needed to run read-0.mes into core.
* doc/examples/mini-mes.c: Likewise.
* lib.c (length, error): Comment-out.
* math.c (greater_p, less_p): Comment-out.
* posix.c: (getchar, ungetchar, peekchar, peek_byte, read_byte,
unread_byte): Comment-out.
* reader.c (lookup_): Comment-out.
2017-03-22 05:39:24 +00:00
|
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
|
(define (i386:accu/base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%edx,%ebx") ; mov %edx,%ebx
|
|
|
|
|
("xor____%edx,%edx") ; xor %edx,%edx
|
|
|
|
|
("div____%ebx"))) ; div %ebx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu%base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%edx,%ebx") ; mov %edx,%ebx
|
|
|
|
|
("xor____%edx,%edx") ; xor %edx,%edx
|
|
|
|
|
("div____%ebx") ; div %ebx
|
|
|
|
|
("mov____%edx,%eax"))) ; mov %edx,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:base->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%edx,%eax"))) ; mov %edx,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:label->accu label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____$i32,%eax" (#:address ,label)))) ; mov $<n>,%eax
|
2017-06-11 11:11:40 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:label->base label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____$i32,%edx" (#:address ,label)))) ; mov $<n>,%edx
|
2017-06-11 11:11:40 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:label-mem->accu label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____0x32,%eax" (#:address ,label)))) ; mov 0x<n>,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:label-mem->base label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____0x32,%edx" (#:address ,label)))) ; mov 0x<n>,%edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:label-mem-add label v)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs v) #x80) `("add____$i8,0x32" (#:address ,label) (#:immediate1 ,v))
|
|
|
|
|
`("add____$i32,0x32" (#:address ,label) (#:immediate ,v)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-base-mem->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("add____%edx,%eax") ; add %edx,%eax
|
|
|
|
|
("movzbl_(%eax),%eax"))) ; movzbl (%eax),%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-mem->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("movzbl_(%eax),%eax"))) ; movzbl (%eax),%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-mem->base)
|
2017-07-20 08:05:48 +00:00
|
|
|
|
'(("movzbl_(%edx),%edx"))) ; movzbl (%edx),%edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:base-mem->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("add___%edx,%eax") ; add %edx,%eax
|
|
|
|
|
("mov____(%eax),%eax"))) ; mov (%eax),%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:mem->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____(%eax),%eax"))) ; mov (%eax),%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-20 08:05:48 +00:00
|
|
|
|
(define (i386:mem->base)
|
|
|
|
|
'(("mov____(%edx),%edx"))) ; mov (%edx),%edx
|
|
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
|
(define (i386:mem+n->accu n)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%eax),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%eax),%eax" (#:immediate ,n)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-24 06:36:43 +00:00
|
|
|
|
(define (i386:base-mem+n->accu v)
|
|
|
|
|
(or v (error "invalid value: base-mem+n->accu: " v))
|
|
|
|
|
`(("add___%edx,%eax")
|
|
|
|
|
,(if (< (abs v) #x80) `("mov____0x8(%eax),%eax" (#:immediate1 ,v))
|
|
|
|
|
`("mov____0x32(%eax),%eax" (#:immediate ,v)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:value->accu v)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or v (error "invalid value: i386:value->accu: " v))
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____$i32,%eax" (#:immediate ,v)))) ; mov $<v>,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:value->accu-address v)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____$i32,(%eax)" (#:immediate ,v)))) ; movl $0x<v>,(%eax)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:value->accu-address+n n v)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or v (error "invalid value: i386:value->accu-address+n: " v))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs v) #x80) `("mov____$i32,0x8(%eax)" (#:immediate1 ,n) (#:immediate ,v))
|
|
|
|
|
`("mov____$i32,0x32(%eax)" (#:immediate ,n) (#:immediate ,v)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:base->accu-address)
|
2017-07-28 13:27:25 +00:00
|
|
|
|
'(("mov____%edx,(%eax)"))) ; mov %edx,(%eax)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:base-address->accu-address)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____(%edx),%ecx") ; mov (%edx),%ecx
|
2017-07-28 13:27:25 +00:00
|
|
|
|
("mov____%ecx,(%eax)"))) ; mov %ecx,(%eax)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-base->accu-address)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%dl,(%eax)"))) ; mov %dl,(%eax)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-base->accu-address+n n)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or n (error "invalid value: byte-base->accu-address+n: " n))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____%dl,0x8(%eax)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%dl,0x32(%eax)" (#:immediate ,n)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:value->base v)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or v (error "invalid value: i386:value->base: " v))
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("mov____$i32,%edx" (#:immediate ,v)))) ; mov $<v>,%edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-04-17 00:15:11 +00:00
|
|
|
|
(define (i386:accu-mem-add v)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs v) #x80) `("add____$i8,(%eax)" (#:immediate1 ,v))
|
|
|
|
|
`("add____$i32,(%eax)" (#:immediate ,v)))))
|
2017-04-17 00:15:11 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:value->label label v)
|
|
|
|
|
(or v (error "invalid value: value->label: " v))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(("mov____$i32,0x32" (#:address ,label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
(#:immediate ,v))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:call-label label n)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`((call32 (#:offset ,label))
|
|
|
|
|
("add____$i8,%esp" (#:immediate1 ,(* n 4)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-11 11:11:40 +00:00
|
|
|
|
(define (i386:call-accu n)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
`(,@(i386:push-accu)
|
|
|
|
|
,@(i386:pop-accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
("call___*%eax") ; call *%eax
|
|
|
|
|
("add____$i8,%esp" (#:immediate1 ,(* n 4))))) ; add $00,%esp
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-21 08:39:04 +00:00
|
|
|
|
(define (i386:accu-negate)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("sete___%al") ; sete %al
|
|
|
|
|
("movzbl_%al,%eax"))) ; movzbl %al,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:xor-accu v)
|
2017-04-12 19:27:59 +00:00
|
|
|
|
(or v (error "invalid value: i386:xor-accu: n: " v))
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("xor___$i32,%eax" (#:immediate ,v)))) ;xor $0xff,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:xor-zf)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("lahf") ; lahf
|
|
|
|
|
("xor____$i8,%ah" (#:immediate1 #x40)) ; xor $0x40,%ah
|
|
|
|
|
("sahf"))) ; sahf
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu-cmp-value v)
|
2017-07-24 06:36:43 +00:00
|
|
|
|
`(,(if (< (abs v) #x80) `("cmp____$i8,%eax" (#:immediate1 ,v))
|
|
|
|
|
`("cmp____$i32,%eax" (#:immediate ,v)))))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu-test)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("test___%eax,%eax"))) ; test %eax,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("jmp32 " (#:offset ,label))))
|
2017-06-11 11:11:40 +00:00
|
|
|
|
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump-z label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("je32 " (#:offset ,label)))) ; jz . + <n>
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump-byte-z label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("test___%al,%al") ; test %al,%al
|
2017-07-24 16:42:24 +00:00
|
|
|
|
("je32 " (#:offset ,label)))) ; je <n>
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
|
|
|
|
;; signed
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump-g label)
|
2017-07-24 16:42:24 +00:00
|
|
|
|
`(("jg32 " (#:offset ,label)))) ; jg/jnle <n>
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
|
|
|
|
;; signed
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump-ge label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("jge32 " (#:offset ,label)))) ; jge/jnl <n>
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump-nz label)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("jne32 " (#:offset ,label)))) ; jnz . + <n>
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
2017-04-02 10:29:09 +00:00
|
|
|
|
(define (i386:byte-test-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("cmp____%al,%dl"))) ; cmp %al,%dl
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:test-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
(("cmp____%edx,%eax"))) ; cmp %edx,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-sub-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("sub____%dl,%al"))) ; sub %dl,%al
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-base-sub)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("sub____%al,%dl"))) ; sub %al,%dl
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:sub-base)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("sub____%edx,%eax"))) ; sub %edx,%eax
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:base-sub)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
`(("sub____%eax,%edx"))) ; sub %eax,%edx
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-05-06 15:30:14 +00:00
|
|
|
|
(define (i386:nz->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("setne__%al") ; setne %al
|
|
|
|
|
("movzbl_%al,%eax"))) ; movzbl %al,%eax
|
2017-05-06 15:30:14 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:z->accu)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("sete___%al") ; sete %al
|
|
|
|
|
("movzbl_%al,%eax"))) ; movzbl %al,%eax
|
2017-05-06 15:30:14 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:accu<->stack)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("xchg___%eax,(%esp)"))) ; xchg %eax,(%esp)
|