Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

push 1 less than %ecx to stack

I am trying the push onto the stack a value which is one less than %ecx.

So I tried this instruction for that:

pushl $(%ecx - 1)

However I get the below error from as.

fact.s: Assembler messages:
fact.s:49: Error: register value used as expression

As a workaround I did the following:

movl %ecx, %edx
subl $1, %edx
pushl %edx

But is there there a way to do it without using extra registers (%edx in this case) ? And in one instruction ?

like image 973
sps Avatar asked Dec 19 '25 17:12

sps


2 Answers

Two instructions:

pushl %ecx
subl $1, (%esp)      # or decl (%esp)
like image 170
rkhb Avatar answered Dec 23 '25 00:12

rkhb


Without extra registers? Sure. dec/push/inc. One instruction? No.

decl  %ecx
pushl %ecx
incl  %ecx
like image 32
Sami Kuhmonen Avatar answered Dec 23 '25 00:12

Sami Kuhmonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!