hi!

i'm starting to program in asm (i have a school project).

i'm programming in intel asm for an 8088 simulator (the one in
tanenbaum's "structured computer organization" book)

i have a question:

is it a mistake to write subroutines that use variables to store
(intermediate and return) values?
shouldn't they only use registers?

this way, you know you can always take that routine and put it wherever
you want, without having to use the variable too.

am i correct?
thanks

asy

Dani AI

Generated

Short answer to : using variables inside a routine is fine, but where those variables live matters. For portability and reentrancy you should prefer stack-based locals (or a caller-supplied workspace) rather than module-level globals. Registers are faster and typically used for return values and short-lived temporaries, but there are only a few of them, so combine register use with a small stack frame and a documented calling convention.

A minimal 8088 prologue/epilogue you can adopt looks like this:

push bp
mov  bp, sp
sub  sp, <locals>   ; reserve local space
...                 ; body uses [bp - offset] for locals
mov  sp, bp
pop  bp
ret

Decide and document: how parameters are passed (stack or registers), where results are returned (commonly AX on 16-bit x86), and which registers a callee must preserve. A common, practical rule is: AX/CX/DX are volatile (caller-saved); BX/SI/DI (and BP if not used as frame pointer) should be preserved by the callee. Save and restore any registers your routine clobbers if they are supposed to be preserved.

Note on : the 8051 has banked register sets, which is a different architecture concern and not applicable to the 8088. Finally, avoid globals if you need recursion, interrupts, or relocation; if a routine must be relocatable, allocate locals on the stack or accept a pointer to a workspace passed by the caller.

I think it can only be stored in registers as different banks are used to store data depending on the microcontroller you are using you could select different banks, in 8051 there are 4 different banks each containing 8 registers.

sorry but your answer is not very clear to me..

how does it relate to my original question?

thanks
asymmetric

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.