Hacker News new | past | comments | ask | show | jobs | submit login

I've read CALLG/CALLS VAX example, and became curious -- why waste microcode for two types of function calls, isn't that hard? Isn't "initalizing a temporary structure" expensive? I found the nice explanation [0] and apparently no, it was pretty simple.

- A parameter list is a series of words in adjacent memory cells. The AP register points to the first of these. The first word holds a COUNT of the number of parameters. The remaining words hold the individual parameters.

- CALLG copies passed address to AP register. It must contain parameter list in the right format.

- CALLS simply pushes the parameter (argument count) to the stack. Since the stack grows toward low addresses, the stack ends up with exactly right sequence of words to represent a parameter list! So the instruction just copies stack pointer to AP, and calls the function. It also sets a special flag to pop values from stack on return.

This is a very neat approach -- with a bit more than a extra push, VAX got a nice instruction to optimize common case of function calls.

Unfortunately, this approach would not work with modern CPUs. In modern PCs, memory accesses are much slower that register accesses, so first few parameters are passed in registers. Calling function with multiple parameters is very different from calling it with one struct.

[0] http://www.math-cs.gordon.edu/courses/cs222/lectures/procedu...




VAX was designed in a time where it was common to write assembly by hand, and so programmer ergonomics was an important consideration. Instructions were introduced where today we would add a library function - this peaked with POLY [1] I think?

Nowadays ISAs are compiler targets and nothing more, so human-ergonomic instructions are hilariously quaint.

1: http://uranium.vaxpower.org/~isildur/vax/week.html




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: