2018-07-22 12:24:36 +00:00
|
|
|
|
;;; GNU Mes --- Maxwell Equations of Software
|
2018-05-25 06:05:02 +00:00
|
|
|
|
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2017-04-02 10:29:09 +00:00
|
|
|
|
;;;
|
2018-07-22 12:24:36 +00:00
|
|
|
|
;;; This file is part of GNU Mes.
|
2017-04-02 10:29:09 +00:00
|
|
|
|
;;;
|
2018-07-22 12:24:36 +00:00
|
|
|
|
;;; GNU Mes is free software; you can redistribute it and/or modify it
|
2017-04-02 10:29:09 +00:00
|
|
|
|
;;; 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.
|
|
|
|
|
;;;
|
2018-07-22 12:24:36 +00:00
|
|
|
|
;;; GNU Mes is distributed in the hope that it will be useful, but
|
2017-04-02 10:29:09 +00:00
|
|
|
|
;;; 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
|
2018-07-22 12:24:36 +00:00
|
|
|
|
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2018-05-25 06:05:02 +00:00
|
|
|
|
;;; define i386 assembly
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2018-05-25 06:05:02 +00:00
|
|
|
|
(define-module (mescc i386 as)
|
|
|
|
|
#:use-module (mes guile)
|
|
|
|
|
#:use-module (mescc as)
|
|
|
|
|
#:export (
|
|
|
|
|
i386:accu%base
|
|
|
|
|
i386:accu*base
|
|
|
|
|
i386:accu*n->label
|
|
|
|
|
i386:accu*n->local
|
|
|
|
|
i386:accu+accu
|
|
|
|
|
i386:accu+base
|
|
|
|
|
i386:accu+value
|
|
|
|
|
i386:accu->base
|
|
|
|
|
i386:accu->base-mem
|
|
|
|
|
i386:byte-accu->base-mem
|
|
|
|
|
i386:word-accu->base-mem
|
|
|
|
|
i386:accu->base-mem+n
|
|
|
|
|
i386:byte-accu->base-mem+n
|
|
|
|
|
i386:word-accu->base-mem+n
|
|
|
|
|
i386:accu->label
|
|
|
|
|
i386:accu->local
|
|
|
|
|
i386:accu->local+n
|
|
|
|
|
i386:accu->local+n
|
|
|
|
|
i386:accu-and
|
|
|
|
|
i386:accu-and-base
|
|
|
|
|
i386:accu-and-base-mem
|
|
|
|
|
i386:accu-base
|
|
|
|
|
i386:accu-cmp-value
|
|
|
|
|
i386:accu-mem-add
|
|
|
|
|
i386:accu-mem->base-mem
|
|
|
|
|
i386:accu-negate
|
|
|
|
|
i386:accu-not
|
|
|
|
|
i386:accu-or-base
|
|
|
|
|
i386:accu-or-base-mem
|
|
|
|
|
i386:accu-shl
|
|
|
|
|
i386:accu-test
|
|
|
|
|
i386:accu-xor-base
|
|
|
|
|
i386:accu-zero?
|
|
|
|
|
i386:accu/base
|
|
|
|
|
i386:accu<->stack
|
|
|
|
|
i386:accu<<base
|
|
|
|
|
i386:accu>>base
|
|
|
|
|
i386:base+value
|
|
|
|
|
i386:base->accu
|
|
|
|
|
i386:base->accu-mem
|
|
|
|
|
i386:base->label
|
|
|
|
|
i386:base-mem->accu-mem
|
|
|
|
|
i386:base-mem+n->accu
|
|
|
|
|
i386:base-mem->accu
|
|
|
|
|
i386:base-sub
|
|
|
|
|
i386:byte-accu->base-mem
|
|
|
|
|
i386:word-accu->base-mem
|
|
|
|
|
i386:byte-base->accu-mem
|
|
|
|
|
i386:byte-base->accu-mem+n
|
|
|
|
|
i386:byte-base-mem->accu
|
|
|
|
|
i386:byte-base-sub
|
|
|
|
|
i386:byte-local->base
|
|
|
|
|
i386:byte-mem->accu
|
|
|
|
|
i386:word-mem->accu
|
|
|
|
|
i386:byte-mem->base
|
|
|
|
|
i386:byte-sub-base
|
|
|
|
|
i386:byte-test-base
|
|
|
|
|
i386:call-accu
|
|
|
|
|
i386:call-label
|
|
|
|
|
i386:formal
|
|
|
|
|
i386:function-locals
|
|
|
|
|
i386:function-preamble
|
|
|
|
|
i386:jump
|
|
|
|
|
i386:jump
|
|
|
|
|
i386:jump-a
|
|
|
|
|
i386:jump-ae
|
|
|
|
|
i386:jump-b
|
|
|
|
|
i386:jump-be
|
|
|
|
|
i386:jump-byte-z
|
|
|
|
|
i386:jump-g
|
|
|
|
|
i386:jump-ge
|
|
|
|
|
i386:jump-l
|
|
|
|
|
i386:jump-le
|
|
|
|
|
i386:jump-nz
|
|
|
|
|
i386:jump-z
|
|
|
|
|
i386:label->accu
|
|
|
|
|
i386:label->base
|
|
|
|
|
i386:label-mem->accu
|
|
|
|
|
i386:label-mem->base
|
|
|
|
|
i386:label-mem-add
|
|
|
|
|
i386:local->accu
|
|
|
|
|
i386:local->base
|
|
|
|
|
i386:local-add
|
|
|
|
|
i386:local-address->accu
|
|
|
|
|
i386:local-address->accu
|
|
|
|
|
i386:local-address->base
|
|
|
|
|
i386:local-ptr->accu
|
|
|
|
|
i386:local-ptr->base
|
|
|
|
|
i386:local-test
|
|
|
|
|
i386:mem+n->accu
|
|
|
|
|
i386:byte-mem+n->accu
|
|
|
|
|
i386:word-mem+n->accu
|
|
|
|
|
i386:mem->accu
|
|
|
|
|
i386:mem->base
|
|
|
|
|
i386:nop
|
|
|
|
|
i386:nz->accu
|
|
|
|
|
i386:pop-accu
|
|
|
|
|
i386:pop-base
|
|
|
|
|
i386:push-accu
|
|
|
|
|
i386:push-base
|
|
|
|
|
i386:push-byte-local-de-de-ref
|
|
|
|
|
i386:push-byte-local-de-ref
|
|
|
|
|
i386:push-word-local-de-ref
|
|
|
|
|
i386:push-label
|
|
|
|
|
i386:push-label-mem
|
|
|
|
|
i386:push-local
|
|
|
|
|
i386:push-local-address
|
|
|
|
|
i386:push-local-de-ref
|
|
|
|
|
i386:ret
|
|
|
|
|
i386:ret-local
|
|
|
|
|
i386:sub-base
|
|
|
|
|
i386:test-base
|
|
|
|
|
i386:value->accu
|
|
|
|
|
i386:value->accu-mem
|
|
|
|
|
i386:value->accu-mem+n
|
|
|
|
|
i386:value->base
|
|
|
|
|
i386:value->label
|
|
|
|
|
i386:value->local
|
|
|
|
|
i386:xor-accu
|
|
|
|
|
i386:xor-zf
|
|
|
|
|
i386:g?->accu
|
|
|
|
|
i386:ge?->accu
|
|
|
|
|
i386:l?->accu
|
|
|
|
|
i386:le?->accu
|
|
|
|
|
i386:a?->accu
|
|
|
|
|
i386:ae?->accu
|
|
|
|
|
i386:b?->accu
|
|
|
|
|
i386:be?->accu
|
|
|
|
|
i386:z->accu
|
|
|
|
|
i386:byte-accu
|
|
|
|
|
i386:signed-byte-accu
|
|
|
|
|
i386:word-accu
|
|
|
|
|
i386:signed-word-accu
|
|
|
|
|
))
|
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
|
|
|
|
|
2017-12-03 15:33:35 +00:00
|
|
|
|
(define (i386:push-word-local-de-ref n)
|
|
|
|
|
(or n (error "invalid value: push-word-local-de-ref: " n))
|
|
|
|
|
(let ((n (- 0 (* 4 n))))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____0x8(%ebp),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("mov____0x32(%ebp),%eax" (#:immediate ,n)))
|
|
|
|
|
("movzwl_(%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))))))
|
|
|
|
|
|
mescc: Mescc-tools support: char foo[BAR] = {'a', 'b', 'c'}.
* stage0/x86.M1 (mov____%al,0x8(%ebp), mov____%al,0x32(%ebp),
mov____%ax,0x8(%ebp), mov____%ax,0x32(%ebp)): New define.
* module/mes/as-i386.mes (i386:accu->local+n,i386:byte-accu->local+n,
i386:word-accu->local+n): New function.
* module/language/c99/compiler.mes (accu->local+n): New function.
(initzer->data): Return char as single byte.
(decl->info): Support char foo[BAR] = {'a', 'b', 'c'}.
* scaffold/tests/66-local-char-array.c: Test it.
* make.scm (add-scaffold-test): Build it.
2017-11-27 18:51:18 +00:00
|
|
|
|
(define (i386:accu->local+n id n)
|
|
|
|
|
(let ((n (+ (- 0 (* 4 id)) n)))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____%eax,0x8(%ebp)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%eax,0x32(%ebp)" (#:immediate ,n))))))
|
|
|
|
|
|
2017-08-06 16:49:19 +00:00
|
|
|
|
(define (i386:accu*n->local i n)
|
|
|
|
|
(or n (error "invalid value: accu->local: " n))
|
|
|
|
|
(let ((o (- 0 (* 4 i))))
|
|
|
|
|
(let loop ((i 0))
|
|
|
|
|
(if (>= i n) '() ;; FIXME: byte, word-sized
|
|
|
|
|
(let ((o (+ o i)))
|
|
|
|
|
(append
|
|
|
|
|
(if (< (abs o) #x80) `(("mov____0x8(%eax),%ebx" (#:immediate1 ,i))
|
|
|
|
|
("mov____%ebx,0x8(%ebp)" (#:immediate1 ,o)))
|
|
|
|
|
`(("mov____0x8(%eax),%ebx" (#:immediate1 ,i))
|
|
|
|
|
("mov____%ebx,0x32(%ebp)" (#:immediate ,o))))
|
|
|
|
|
(loop (+ i 4))))))))
|
2017-07-24 06:36:43 +00:00
|
|
|
|
|
|
|
|
|
(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->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
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:accu->base-mem)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%eax,(%edx)"))) ; mov %eax,(%edx)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:byte-accu->base-mem)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%al,(%edx)"))) ; mov %al,(%edx)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-08-06 10:27:16 +00:00
|
|
|
|
(define (i386:word-accu->base-mem)
|
|
|
|
|
'(("mov____%ax,(%edx)"))) ; mov %ax,(%edx)
|
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:accu->base-mem+n n)
|
|
|
|
|
(or n (error "invalid value: accu->base-mem+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-08-06 10:27:16 +00:00
|
|
|
|
(define (i386:byte-accu->base-mem+n n)
|
|
|
|
|
(or n (error "invalid value: accu->base-mem+n: " n))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____%al,0x8(%edx)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%al,0x32(%edx)" (#:immediate ,n)))))
|
|
|
|
|
|
|
|
|
|
(define (i386:word-accu->base-mem+n n)
|
|
|
|
|
(or n (error "invalid value: accu->base-mem+n: " n))
|
|
|
|
|
`(,(if (< (abs n) #x80) `("mov____%ax,0x8(%edx)" (#:immediate1 ,n))
|
|
|
|
|
`("mov____%ax,0x32(%edx)" (#:immediate ,n)))))
|
|
|
|
|
|
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
|
|
|
|
|
2017-08-06 16:49:19 +00:00
|
|
|
|
(define (i386:accu*n->label label n)
|
|
|
|
|
(append
|
|
|
|
|
'(("push___%edx"))
|
|
|
|
|
(let loop ((i 0))
|
|
|
|
|
(if (>= i n) '() ;; FIXME: byte, word-sized
|
|
|
|
|
(append
|
|
|
|
|
`(("mov____$i32,%edx" (#:address ,label))
|
|
|
|
|
("mov____0x8(%eax),%ebx" (#:immediate1 ,i))
|
|
|
|
|
("mov____%ebx,0x8(%edx)" (#:immediate1 ,i)))
|
|
|
|
|
(loop (+ i 4)))))
|
|
|
|
|
'(("pop____%edx"))))
|
|
|
|
|
|
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)
|
2018-05-13 15:05:28 +00:00
|
|
|
|
'(("and____%edx,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:accu-and v)
|
|
|
|
|
`(("and____$i32,%eax" (#:immediate ,v))))
|
|
|
|
|
|
|
|
|
|
(define (i386:accu-and-base-mem)
|
|
|
|
|
'(("and____(%edx),%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:accu-or-base-mem)
|
|
|
|
|
'(("or_____(%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
|
2017-07-28 18:36:21 +00:00
|
|
|
|
("idiv___%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
|
2017-07-28 18:36:21 +00:00
|
|
|
|
("idiv___%ebx") ; div %ebx
|
2017-07-02 14:25:14 +00:00
|
|
|
|
("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
|
|
|
|
|
2017-08-08 08:00:13 +00:00
|
|
|
|
(define (i386:word-mem->accu)
|
|
|
|
|
'(("movzwl_(%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)
|
2018-05-13 15:05:28 +00:00
|
|
|
|
'(("mov____(%edx),%eax")))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:mem->accu)
|
2018-05-13 15:05:28 +00:00
|
|
|
|
'(("mov____(%eax),%eax")))
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-20 08:05:48 +00:00
|
|
|
|
(define (i386:mem->base)
|
2018-05-13 15:05:28 +00:00
|
|
|
|
'(("mov____(%edx),%edx")))
|
2017-07-20 08:05:48 +00:00
|
|
|
|
|
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-08-06 10:27:16 +00:00
|
|
|
|
(define (i386:byte-mem+n->accu n)
|
|
|
|
|
`(,(if (< (abs n) #x80) `("movzbl_0x8(%eax),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("movzbl_0x32(%eax),%eax" (#:immediate ,n)))))
|
|
|
|
|
|
|
|
|
|
(define (i386:word-mem+n->accu n)
|
|
|
|
|
`(,(if (< (abs n) #x80) `("movzwl_0x8(%eax),%eax" (#:immediate1 ,n))
|
|
|
|
|
`("movzwl_xb0x32(%eax),%eax" (#:immediate ,n)))))
|
|
|
|
|
|
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
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:value->accu-mem 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
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:value->accu-mem+n n v)
|
|
|
|
|
(or v (error "invalid value: i386:value->accu-mem+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
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:base->accu-mem)
|
2017-07-28 13:27:25 +00:00
|
|
|
|
'(("mov____%edx,(%eax)"))) ; mov %edx,(%eax)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:accu-mem->base-mem)
|
|
|
|
|
'(("mov____(%eax),%ecx")
|
|
|
|
|
("mov____%ecx,(%edx)")))
|
|
|
|
|
|
|
|
|
|
(define (i386:base-mem->accu-mem)
|
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
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:byte-base->accu-mem)
|
2017-07-02 14:25:14 +00:00
|
|
|
|
'(("mov____%dl,(%eax)"))) ; mov %dl,(%eax)
|
2017-04-02 10:29:09 +00:00
|
|
|
|
|
2017-07-28 20:45:32 +00:00
|
|
|
|
(define (i386:byte-base->accu-mem+n n)
|
|
|
|
|
(or n (error "invalid value: byte-base->accu-mem+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-29 18:46:16 +00:00
|
|
|
|
(define (i386:accu-zero?)
|
|
|
|
|
'(("test___%eax,%eax")))
|
|
|
|
|
|
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)
|
2018-05-19 09:41:53 +00:00
|
|
|
|
`(("jg32 " (#:offset ,label))))
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
2017-06-13 18:31:03 +00:00
|
|
|
|
(define (i386:jump-ge label)
|
2018-05-19 09:41:53 +00:00
|
|
|
|
`(("jge32 " (#:offset ,label))))
|
2017-06-12 19:00:50 +00:00
|
|
|
|
|
2017-07-29 18:46:16 +00:00
|
|
|
|
(define (i386:jump-l label)
|
|
|
|
|
`(("jl32 " (#:offset ,label))))
|
|
|
|
|
|
|
|
|
|
(define (i386:jump-le label)
|
|
|
|
|
`(("jle32 " (#:offset ,label))))
|
|
|
|
|
|
2018-05-19 09:41:53 +00:00
|
|
|
|
(define (i386:g?->accu)
|
|
|
|
|
'(("setg___%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:ge?->accu)
|
|
|
|
|
'(("setge__%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:l?->accu)
|
|
|
|
|
'(("setl___%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:le?->accu)
|
|
|
|
|
'(("setle__%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
;; unsigned
|
|
|
|
|
(define (i386:jump-a label)
|
|
|
|
|
`(("ja32 " (#:offset ,label))))
|
|
|
|
|
|
|
|
|
|
(define (i386:jump-ae label)
|
|
|
|
|
`(("jae32 " (#:offset ,label))))
|
|
|
|
|
|
|
|
|
|
(define (i386:jump-b label)
|
|
|
|
|
`(("jb32 " (#:offset ,label))))
|
|
|
|
|
|
|
|
|
|
(define (i386:jump-be label)
|
|
|
|
|
`(("jbe32 " (#:offset ,label))))
|
|
|
|
|
|
|
|
|
|
(define (i386:a?->accu)
|
|
|
|
|
'(("seta___%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:ae?->accu)
|
|
|
|
|
'(("setae__%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:b?->accu)
|
|
|
|
|
'(("setb___%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:be?->accu)
|
|
|
|
|
'(("setbe__%al")
|
|
|
|
|
("movzbl_%al,%eax")))
|
|
|
|
|
|
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)
|
mescc: Tinycc support: Char and short sign extend.
* module/mes/as-i386.mes (i386:accu*n->local, i386:byte-accu->local+n,
i386:word-accu->local+n): Remove.
(i386:byte-accu, i386:signed-byte-accu, i386:word-accu,
i386:signed-word-accu): New function.
* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (accu->local+n-text): Simplify.
(mem->accu, convert-accu): New function.
(expr->accu): Use them.
* stage0/x86.M1 (mov____%al,0x32(%ebp), mov____%al,0x8(%ebp),
mov____%ax,0x32(%ebp), mov____%ax,0x8(%ebp), movzbl_0x32(%ebp),%eax,
movzbl_0x8(%ebp),%eax, movzwl_0x32(%ebp),%eax,
movzwl_0x8(%ebp),%eax): Deprecate.
* scaffold/tests/7r-sign-extend.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
2018-05-18 21:58:10 +00:00
|
|
|
|
|
|
|
|
|
(define (i386:byte-accu)
|
|
|
|
|
'(("movzbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:signed-byte-accu)
|
|
|
|
|
'(("movsbl_%al,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:word-accu)
|
|
|
|
|
'(("movzwl_%ax,%eax")))
|
|
|
|
|
|
|
|
|
|
(define (i386:signed-word-accu)
|
|
|
|
|
'(("movswl_%ax,%eax")))
|