+(define (codegen-eq a b si env)
+ (codegen-expr a si env)
+ (emit "movq %rax, ~a(%rbp)" si)
+ (codegen-expr b (- si wordsize) env)
+ (emit "subq ~a(%rbp), %rax" si)
+ (emit "not %rax")
+ (emit "andq $1, %rax"))
+
+; 'write file handle addr-string num-bytes
+
+(define (codegen-print x si env)
+ (codegen-expr x si env) ; x should be a static-string, producing a label
+
+ ; get the length of the null terminated string
+ (emit "mov %rax, %rdi")
+ (emit "xor %al, %al") ; set %al to 0
+ (emit "mov $-1, %rcx") ; max search length = max int = -1
+ (emit "cld") ; clear direction flag, search up in memory
+ (emit "repne scasb") ; scan string, %rcx = -strlen - 1 - 1
+
+ (emit "not %rcx") ; -%rcx = strlen + 1
+ (emit "dec %rcx")
+
+ (case target
+ ('darwin
+ (emit "movq %rax, %rsi") ; string addr
+ (emit "movq %rcx, %rdx") ; num bytes
+ (emit "movq $1, %rdi") ; file handle (stdout)
+ (emit "movq $0x2000004, %rax")) ; syscall 4 (write)
+ ('linux
+ (emit "mov %rax, %rsi") ; string addr
+ (emit "mov %rcx, %rdx") ; num bytes
+ (emit "mov $1, %rax") ; file handle (stdout)
+ (emit "mov $1, %rdi"))) ; syscall 1 (write)
+ (emit "syscall"))
+