Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RISC vs CISC stack

Here is a quote from the book "Introduction to Assembly language" about RISC (vs CISC)

In MIPS, we could write procedures without using the stack. For most normal procedures, we do not have to use the stack. The availability of a large number of registers allows us to use register-based parameter passing. However, when we write recursive procedures, we have to use the stack.

I am very confused about the magic with working without the stack. Any standard program has a chain calls: Main()-> Function1() -> Function2() -> ... ->

Even with lots of registers (128) the way is usual:

  1. decide which registers you should take and save their context (usually pushing on the stack)
  2. provide operations
  3. return registers states (usually popping from the stack)

Nobody stops us to use register-based parameter passing in CISC, especially on modern processors. So, how is it possible to do a program con RISC without the stack?

like image 871
Artur A Avatar asked Feb 21 '23 00:02

Artur A


1 Answers

I think what they're referring to is argument passing. In most RISC machines, arguments are passed in registers and there are generally about 6-8 registers reserved for this purpose (and one for the return value). This isn't mandated, it's simply convention (and is called ABI or application binary interface). So, if there are fewer arguments to the function than registers and those arguments are simple enough to fit in a register, you don't need extra stack space to pass those arguments. On CISC machines, there aren't so many registers for arguments, so the ABI specifies that those arguments are passed on the stack.

Also, in RISC machines, there are many temporary registers available (specifically the callee save ones) for storing local variables. On CISC machines, local variables are generally allocated on the stack and registers are generally reserved for intermediate values.

like image 169
Nathan Binkert Avatar answered Mar 02 '23 19:03

Nathan Binkert