Fredrick
Fredrick

Reputation: 13

subtract instruction in processors

Why should a processor implement a subtract instruction ? Why cant the compilers change subtraction to 2-s complement additions?

Upvotes: 1

Views: 664

Answers (2)

m4tt1mus
m4tt1mus

Reputation: 1641

Addition and subtraction are used enough that it makes sense to build it in. It is a trade off between having more native instructions which require less CPU cycles to faster CPU cycles (more cycles / second).

Upvotes: 0

Gareth McCaughan
Gareth McCaughan

Reputation: 19981

Because if every subtraction had to be two instructions (negate and add) then you'd waste a lot of memory traffic (because code would become larger), cache space (because code would be larger), and instruction decode time (because there would be more instructions to decode), for a tiny gain in CPU simplicity. Totally not worth it.

Upvotes: 2

Related Questions