projects
/
scheme.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2d16419
)
Fix string addressing and clobbered register
author
Luke Lau
<luke.lau@intel.com>
Wed, 24 Jul 2019 13:29:45 +0000
(14:29 +0100)
committer
Luke Lau
<luke.lau@intel.com>
Wed, 24 Jul 2019 13:29:45 +0000
(14:29 +0100)
codegen.scm
patch
|
blob
|
history
diff --git
a/codegen.scm
b/codegen.scm
index 25d99a199da43889ef289b1e6af1292595aa4af0..4848d4ddfa98731899f6b2ca92413b45eb3086ce 100644
(file)
--- a/
codegen.scm
+++ b/
codegen.scm
@@
-50,6
+50,9
@@
(define (codegen-print x si env)
(codegen-expr x si env) ; x should be a static-string, producing a label
(define (codegen-print x si env)
(codegen-expr x si env) ; x should be a static-string, producing a label
+ ; make a copy of string address since %rax and %rdi are clobbered
+ (emit "mov %rax, %rbx")
+
; get the length of the null terminated string
(emit "mov %rax, %rdi")
(emit "xor %al, %al") ; set %al to 0
; get the length of the null terminated string
(emit "mov %rax, %rdi")
(emit "xor %al, %al") ; set %al to 0
@@
-61,7
+64,7
@@
(emit "dec %rcx")
(emit "mov %rcx, %rdx") ; number of bytes
(emit "dec %rcx")
(emit "mov %rcx, %rdx") ; number of bytes
- (emit "mov %r
a
x, %rsi") ; addr of string
+ (emit "mov %r
b
x, %rsi") ; addr of string
(emit "mov $1, %rax") ; file handle 1 (stdout)
(emit "mov $1, %rdi") ; syscall 1 (write)
(emit "syscall"))
(emit "mov $1, %rax") ; file handle 1 (stdout)
(emit "mov $1, %rdi") ; syscall 1 (write)
(emit "syscall"))
@@
-213,7
+216,7
@@
('bool-literal (emit "movq $~a, %rax" (if e 1 0)))
('int-literal (emit "movq $~a, %rax" e))
('bool-literal (emit "movq $~a, %rax" (if e 1 0)))
('int-literal (emit "movq $~a, %rax" e))
- ('static-string (emit "
movq (~a)
, %rax" (cadr e))) ; move label
+ ('static-string (emit "
lea ~a
, %rax" (cadr e))) ; move label
(else (error #f "don't know how to codegen this"))))
(else (error #f "don't know how to codegen this"))))