memory-address

Difference between memory addresses of variables is constant

烂漫一生 提交于 2019-12-12 04:55:55
问题 I ran the following code and this is the output I got: #include <stdio.h> int main() { int x = 3; int y = x; printf("%d\n", &x); printf("%d\n", &y); getchar(); return 0; } Output: 3078020 3078008 Now, the output changes every time I run the program, but the difference between the location of x to the location of y is always 12. I wondered why. Edit: I understand why the difference is constant. What I don't understand is why the difference is specifically 12, and why the memory address of y,

Adding offset to base from register in MIPS

痴心易碎 提交于 2019-12-12 03:46:51
问题 If I have a number in t3, can I use lw $s3, $t3($t0) to get the value stored at the memory referenced by base+offset where the base is in t0 and the offset is in t3 into s3? 回答1: I believe that the solution plaknas gives is only half-correct, as you have to take the word size into account when "creating" the offset in MIPS. Here is the correct answer, assuming a word size of 4 bytes: sll $t3, $t3, 2 add $t0, $t0, $t3 lw $s3, 0($t0) 回答2: Apparently it cannot be done. The better way to do it is

Why does address range 0xC0000000 ~ 0xFFFFFFFF always give 0x00 or 0xFF after switching to protected mode before enabling paging?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 19:09:14
问题 I'm making a custom boot loader, and currently in the stage of enabling paging after switching to protected mode. I tried to check all memory range is usable from 0x00000000 to 0xFFFFFFFF to make sure my kernel has full control over memories. Checking is done by copying value to the memory address and printing the value through video memory(0xB8000). But the address range from 0xC0000000 to 0xFFFFFFFF always contains 0x00(if executed by QEMU) or 0xFF(if executed in real hardware through

vxWorks 6.8 mapping physical to virtual memory

馋奶兔 提交于 2019-12-11 18:46:42
问题 This is my first question here :). I been trying for while now to map physical memory to virtual memory in vxWorks 6.8 with no success, I'm trying to use "vmMap" function but somehow it keeps return with: errno = 0x30065 S_taskLib_NAME_NOT_FOUND. my code is: int page_size=0; PHYS_ADDR GPIO_BASE_VIRTUAL_ADDR = 0x40E00000; VIRT_ADDR VIRTUAL_ADDR=0; page_size =vmPageSizeGet(); if((VIRTUAL_ADDR = (VIRT_ADDR)memalign(page_size,page_size*2))==NULL)// allocate 2 pages { printf("error in memalign()

Printing same physical address in a c program

限于喜欢 提交于 2019-12-11 16:45:21
问题 Is there is a way to print the same physical address in these programs (while using the shared memory concept) rather than printing different logical addresses? The reason for me to print the same physical address :... /*It's optional to read this, since I have provided a lot of information which is not to the core */ In my lab, I have two programs: one to store a string in a physical memory via shared memory concept and one to print the same string via accessing the shared memory. Program 1:

C pointers - Different address

牧云@^-^@ 提交于 2019-12-11 16:02:52
问题 I'm trying to learn about C pointers but I cannot understand somethings... The following code: #include <stdio.h> void foo(int *x, int *y); void foo(int *x, int *y) { printf("x = %p\ny = %p\n", &x, &y); *x = 5; *y = 6; } int main(void) { int a, b; printf("a = %p\nb = %p\n", &a, &b); foo(&a, &b); return 0; } Why are the addresses different? The first printf (main) output two addresses. the other printf (foo) output different addresses. I'm passing addresses to foo (& operator). 回答1: In main ,

How to return the name of a variable stored at a particular memory address in C++

非 Y 不嫁゛ 提交于 2019-12-11 12:59:22
问题 first time posting here after having so many of my Google results come up from this wonderful site. Basically, I'd like to find the name of the variable stored at a particular memory address. I have a memory editing application I wrote that edits a single value, the problem being that every time the application holding this value is patched, I have to hardcode in the new memory address into my application, and recompile, which takes so much time to upkeep that its almost not worthwhile to do.

Why 32-bit processor can only address 4GiB of memory, even with large word size?

戏子无情 提交于 2019-12-11 11:51:55
问题 Until now I thought that a 32-bit processor can use 4 GiB of memory because 2 32 is 4 GiB, but this approach means processor have word size = 1 byte . So a process with 32-bit program counter can address 2 32 different memory words and hence we have 4 GiB. But if a processor has word size larger than 1 byte , which is the case with most of processors now days I believe ( My understanding is that word size is equal to the width of data bus, so a processor with 64-bit data bus must have a word

If the stack grows at numerically lower address why does pointer comparison reverses this?

血红的双手。 提交于 2019-12-11 11:33:37
问题 Since the stack grows downwards, ie towards numerically smaller memory addresses why does &i < &j is true. Correct me if I'm wrong, but I'd imagine this was a design decision of C creators (that C++ maintains). But I wonder why though. It is also strange that a heap-allocated object pin lies at numerically higher memory address than a stack variable and this also contradicts the fact that the heap lies at numerically smaller memory addresses than the stack (and increases upwards). #include

Why do variable pointers contain the address of the same data type?

你说的曾经没有我的故事 提交于 2019-12-11 11:07:05
问题 General syntax of pointer declaration: data-type *pointer_name; A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address. The data type of pointer must be same as the variable, which the pointer is pointing. Why is it important that a pointer variable should contain the address of a variable of the same data type? As a