+ (emit "## ~a = ~b" a b)
+ (emit "cmpq ~a(%rbp), %rax" si)
+ (emit "sete %al"))
+
+ ; '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
+
+ ; 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
+ (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")
+
+ (emit "movq %rbx, %rsi") ; string addr
+ (emit "movq %rcx, %rdx") ; num bytes
+ (emit "movq $1, %rdi") ; file handle (stdout)
+ (case target
+ ('darwin (emit "mov $0x2000004, %rax")) ; syscall 4 (write)
+ ('linux (emit "mov $1, %rax"))) ; syscall 1 (write)
+ (emit "syscall"))