2016-08-12 12:17:55 +00:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
2016-08-13 23:44:42 +00:00
|
|
|
;;; Mes --- Maxwell Equations of Software
|
|
|
|
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
;;;
|
|
|
|
;;; scm.mes: 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/>.
|
|
|
|
|
|
|
|
(define (i386:puts data length)
|
2016-08-13 20:43:55 +00:00
|
|
|
`(
|
2016-08-13 23:44:42 +00:00
|
|
|
#xba ,@(int->bv32 length) ;; mov $0xe,%edx
|
2016-08-13 20:43:55 +00:00
|
|
|
#xb9 ,@(int->bv32 data) ;; mov $data,%ecx
|
|
|
|
#xbb #x01 #x00 #x00 #x00 ;; mov $0x1,%ebx
|
|
|
|
#xb8 #x04 #x00 #x00 #x00 ;; mov $0x4,%eax
|
|
|
|
#xcd #x80 ;; int $0x80
|
|
|
|
))
|
2016-08-12 14:38:59 +00:00
|
|
|
|
2016-08-13 20:43:55 +00:00
|
|
|
(define (i386:exit code)
|
|
|
|
`(
|
|
|
|
#xbb ,@(int->bv32 code) ;; mov $code,%ebx
|
|
|
|
#xb8 #x01 #x00 #x00 #x00 ;; mov $0x1,%eax
|
|
|
|
#xcd #x80 ;; int $0x80
|
|
|
|
))
|
|
|
|
|
2016-08-13 23:44:42 +00:00
|
|
|
(define data
|
|
|
|
(string->list "Hello, world!\n"))
|
|
|
|
|
|
|
|
(define (text d)
|
2016-08-12 13:54:15 +00:00
|
|
|
(append
|
2016-08-13 23:44:42 +00:00
|
|
|
(i386:puts d (length data))
|
2016-08-13 20:43:55 +00:00
|
|
|
(i386:exit 0)
|
2016-08-13 08:32:07 +00:00
|
|
|
))
|
2016-08-13 20:43:55 +00:00
|
|
|
|
2016-08-13 20:21:59 +00:00
|
|
|
(define (write-any x) (write-char (if (char? x) x (integer->char x))))
|
2016-08-13 20:43:55 +00:00
|
|
|
(map write-any (make-elf text data))
|