how does the cpu knows that the data in memory is data or a command? (C programming) -
i expect that data begins @ example 0x100 (memory location) , before it's commands... not sure! help!
okay, detail question: see memory long array 1 byte space. space filled hex numbers. variables can fill memory example 0x0000 - 0xffff. how know example 0x002f command (for example 'mov') or number data?
the cpu doesn't know. it's conventions.
when start computer or embedded device starts executing bootloaer flash storage.
in turn, bootloader loads startup code persistent storage memory , starts executing (typically os kernel) @ address loaded it.
in turn, kernel load additional modules , init code @ known memory locations , execute there.
at point, memory virtualization enabled, , executable files loaded in memory , each associated process , address space. executable header , os conventions define code , data segments locations.
but code segment may contain embedded data, , dynamically allocated memory may contain code, instance in just-in-time compilers or malicious programs.
ok illustrate: imagine address space of running compiler...
[ code seg .exe ] [ data seg .exe ] [ dynamic alloc ]
the difference between these memory regions [code] read+execut, [data] readonly, [dynamic] read+write, +execute
- [code] contains
- mainly machine instructions
- but may contain immediate data, such integer constants , on
- [data] contains
- things strings language keywords, error messages, etc.
- code because have dictionary of machine instructions can generate code
- [dynamic] contains
- runtime allocated data structures such strings, trees, etc.
- runtime generated code, written exe compiler building
- runtime generated code, executed jit computing complex expressions @ compile-time
so see, can have data , code in section. that's makes computers powerful, see turing machines.
Comments
Post a Comment