mir icon indicating copy to clipboard operation
mir copied to clipboard

could I use `global/static variable` in function?

Open fatfatson opened this issue 5 years ago • 3 comments

while writing mir-text code...

fatfatson avatar Mar 03 '21 07:03 fatfatson

Yes, you can have bss or data inside the function (between func and endfunc).

Any label (including for bss and data) has module scope. That is why it is possible to use data/bss in func. The actual placement of data/bss relative to function address is undefined but they are not placed inside the function insns.

vnmakarov avatar Mar 04 '21 14:03 vnmakarov

Yes, you can have bss or data inside the function (between func and endfunc).

Any label (including for bss and data) has module scope. That is why it is possible to use data/bss in func. The actual placement of data/bss relative to function address is undefined but they are not placed inside the function insns.

any example for this? thanks. maybe an existed variable in c/c++ or an mir global varaible

fatfatson avatar Mar 08 '21 05:03 fatfatson

any example for this? thanks.

Here is a MIR textual code storing a value into global var which is declared in function:

test: func
        local i64:addr
global: bss 8
        extern global
        mov addr, var
        mov (addr), 42 # store 42 to var
endfunc

vnmakarov avatar Mar 09 '21 16:03 vnmakarov