开发者

Declaring local variables in assembly

开发者 https://www.devze.com 2022-12-22 23:56 出处:网络
Is it possible to allocate locally-scoped memory in assembly? For example, consider the following (completely contrived) situation:

Is it possible to allocate locally-scoped memory in assembly?

For example, consider the following (completely contrived) situation:

I have two macros, one of which is dependent on the other. The first is:

minimum MACRO dest, num1, num2
; Finds the minimum of two unsigned numbers, stores the result in dest

And the second is:

tripMin MACRO dest, num1, num2, num3
; Finds the minimum of three unsigned numbers, s开发者_运维知识库tores the result in dest

minimum firstMin, num1, num2
minimum secondMin, num2, num3
minimum dest, firstMin, secondMin

(I know that this isn't a realistic example for a variety of reasons, but bear with me.)

Assuming that all the registers are otherwise occupied, is there any way to declare firstMin and secondMin locally within the macro?

Or am I just better off freeing a register by pushing its value onto the stack and popping it back when I'm done?


locally-scoped memory is a notion that only applies to scoped languages, not assembly.

If you were to write the same thing as a function in, say C, your temporaries would be stored on the stack (or available registers if there are some, depending on ABI). You can mimic the same thing. How to push/pop values from the stack is dependent on which assembly language you are using though.

However, this starts to look awfully like a function call.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号