Playback speed
undefinedx
Share post
Share post at current time
0:00
/
0:00

Paid episode

The full episode is only available to paid subscribers of Computer, Enhance!

Monday Q&A #9 (2023-04-24)

Answers to questions from last week's videos
15

Each Monday I answer questions from the comments on the prior week’s videos. Transcripts are not available for Q&A videos due to length. I do produce closed captions for them, but Substack still has not enabled closed captions on videos :(

NOTE: There’s a “typo” in this Q&A, where I write [bp + 8] and [bp + 9]. It should be [bp - 8] and [bp - 9]! Everything else is correct about the explanation, but as we talked about in the previous video, the stack grows “backwards” on x86, so if you save a pointer before advancing the stack pointer, it becomes a subtraction. If you were optimizing to save a register and were using the already-decremented sp, only then would it be an addition.

Questions addressed in this video:

  • [00:40] “just to make it clear, if we're doing something like:

    lea ax, [bx +20]

    Would it be correct to say, this saves us an instruction, cause in order to do the add and the mov, we'd have to do this?

    mov ax, bx

    add ax, 20”

  • [04:35] “So if you see square brackets in x86, it is always either pulling/putting a value from/into memory. With the only exception being LEA, where it serves as a compact way of doing arithmetic that looks like [regX + n*regY + constant] where n is 1, 2, 4, or 8. Is that true?

    I ask because it seems immensely helpful with scanning assembly to easily point to what is and isn't addressing memory.”

  • [11:31] “If I create an array in a C function on the stack, is that stack the same as this one? Also, I can create a lot more variables than there are registers in a typical function and they are all supposed to be on the stack. If they are all in there, then how is a variable that is in the middle of the stack accessed when my function needs it?”

  • [27:31] “What is a stack-frame?”

  • [29:56] “What is a closure?”

  • [40:03] “Is there any strong reason to prefer either calling convention?”

  • [43:14] “The jmp and call instructions in assembly appear as absolute addresses, but seem to be encoded as a relative address. If that's the case, how do function pointers work? Because I'll need to take the address of the function pointer and subtract my current ip to know how to jump, right?”

The full video is for paid subscribers

Programming Courses
A series of courses on programming topics.