Drill 4 Solutions

  1. Which of the following are valid expressions in the language as it stands after the most recent lecture?

    • (add1 4)
    • (zero? not)
    • (if (num? 4) (add1 4) true)
    • (+ 4 7)
    • (+ false true)
    • (let ((x 4)) (+ x 7))
    • (left (let ((x (pair 1 2))) (pair x 3)))
    • (left (right (pair (pair 1 2) 3)))
  2. Say you're developing an AST for a simple subset of HTML, as below: you have nested tags (like html, title, div, etc.) and text. Which of these might you have as constructors for your AST type?

        <title>Page title</title>
        <p>This is text</p>
        <strong>This is bolded text</strong>
        <em>This is italicized text</em>
  1. Does the current compiler ever put the address of a memory location on the stack into a register?

    • No.
  2. Write the assembly instruction that puts the value at stack index -8 into rax. (Your answer should start with mov.)

    • mov rax, [rsp + -8]