EzDevInfo.com

addressing

A PHP 5.4+ addressing library, powered by Google's dataset.

Assembler: Calculating a memory address with register base

I have this simple assembler command:

mov eax, fs:[30h];

My problem is that I need to know what specific address is really read by this command. I found a lot of documentation about the assembler addressing modes but nothing about the register: notation.

Could somebody please explain me the math behind the address calculation?


Source: (StackOverflow)

Cache calculating block offset and index

I've read several topics about this theme but I could not get the answer. So my question is:

1) How is the block offset calculated?

I want to know not the formula but the concept of it. As I know it is quantity of cases which a block can store the address. For example If there is a block with 8 byte storage and has to store 2 byte addresses. Does its block offset is 2 bit?(So there is 4 cases to store the address (the diagram below might make easier to see what I am saying).

enter image description here


Source: (StackOverflow)

Advertisements

Call Activity method from adapter

Is it possible to call mathod that is defined in Activity from ListAdapter?

(I want to make a Button in list's row and when this button is clicked it should perform the method, that is defined in current Activity. I tried to set onClickListener in my ListAdapter but I don't know how to call this method, what's its path...)

when I used Activity.this.method() I get the following error:

No enclosing instance of the type Activity is accessible in scope

Any Idea ?


Source: (StackOverflow)

x86 and Memory Addressing

I've been reading up on memory models in an assembly book I picked up and I have a question or two. Let's say that the address bus has 32 lines, the data bus has 32 lines and the CPU is 32-bit (for simplicity). Now if the CPU makes a read request and sends the 32bit address, but only needs 8 bits, all 32 bits come back anyway? Also, the addresses in memory are still addressed per byte correct? So fetching one byte would bring back 0000 0001 to address 0000 0004?

Thanks in advance


Source: (StackOverflow)

how do addressing modes work on a physical level?

I'm trying to learn this basic thing about processors that should be taught in every CS department of every university. Yet i can't find it on the net (Google doesn't help) and i can't find it in my class materials either.

Do you know any good resource on how addressing modes work on a physical level? I'm particularly interested in Intel processors.


Source: (StackOverflow)

Absolute addressing for runtime code replacement in x86_64

I'm currently using some code replace scheme in 32 bit where the code which is moved to another position, reads variables and a class pointer. Since x86_64 does not support absolute addressing I have trouble getting the correct addresses for the variables at the new position of the code. The problem in detail is, that because of rip relative addressing the instruction pointer address is different than at compile time.

So is there a way to use absolute addressing in x86_64 or another way to get addresses of variables not instruction pointer relative?

Something like: leaq variable(%%rax), %%rbx would also help. I only want to have no dependency on the instruction pointer.


Source: (StackOverflow)

MATLAB: extract submatrix with logical indexing

I'm looking for an elegant solution to this very simple problem in MATLAB. Suppose I have a matrix

>> M = magic(5)

M =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9 

and a logical variable of the form

I =

     0     0     0     0     0
     0     1     1     0     0
     0     1     1     0     0
     0     0     0     0     0
     0     0     0     0     0

If I try to retrieve the elements of M associated to 1 values in I, I get a column vector

>> M(I)

ans =

     5
     6
     7
    13

What would be the simplest way to obtain the matrix [5 7 ; 6 13] from this logical indexing?

If I know the shape of the non-zero elements of I, I can use a reshape after the indexing, but that's not a general case.

Also, I'm aware that the default behavior for this type of indexing in MATLAB enforces consistency with respect to the case in which non-zero values in I do not form a matrix, but I wonder if there is a simple solution for this particular case.


Source: (StackOverflow)

If a SNES has 128k memory and in assembly you can reference $FF:FFFF addresses, how does this work?

Am I misunderstanding something here? 128kB is way smaller than 0xFFFFFF bytes.


Source: (StackOverflow)

What memory is used for storing the reset vector?

from wikipedia: The reset vector for the 8086 processor is at address FFFF0h Where is the reset vector stored?


Source: (StackOverflow)

Find the address of a DLL in memory

I have just been getting into low level programming (reading/writing to memory that sort of thing) and have run into an issue i cannot find an answer to.

The piece of information i want to read from has an address that is relative to a DLL loaded in memory e,g, it is at mydll.dll + 0x01234567. the problem im having is that the dll moves around in memory but the offset stays the same. Is there anyway to find out the location of this dll in memory.

I am currently trying to do this preferably in c# but i would be grateful for help in most highish level languages.


Source: (StackOverflow)

How to offload memory offset calculation from runtime in C/C++?

I am implementing a simple VM, and currently I am using runtime arithmetic to calculate individual program object addresses as offsets from base pointers.

I asked a couple of questions on the subject today, but I seem to be going slowly nowhere.

I learned a couple of things thou, from question one - Object and struct member access and address offset calculation - I learned that modern processors have virtual addressing capabilities, allowing to calculate memory offsets without any additional cycles devoted to arithmetic.

And from question two - Are address offsets resolved during compile time in C/C++? - I learned that there is no guarantee for this happening when doing the offsets manually.

By now it should be clear that what I want to achieve is to take advantage of the virtual memory addressing features of the hardware and offload those from the runtime.

I am using GCC, as for platform - I am developing on x86 in windows, but since it is a VM I'd like to have it efficiently running on all platforms supported by GCC.

So ANY information on the subject is welcome and will be very appreciated.

Thanks in advance!

EDIT: Some overview on my program code generation - during the design stage the program is build as a tree hierarchy, which is then recursively serialized into one continuous memory block, along with indexing objects and calculating their offset from the beginning of the program memory block.

EDIT 2: Here is some pseudo code of the VM:

switch *instruction
   case 1: call_fn1(*(instruction+1)); instruction += (1+sizeof(parameter1)); break;
   case 2: call_fn2(*(instruction+1), *(instruction+1+sizeof(parameter1));
           instruction += (1+sizeof(parameter1)+sizeof(parameter2); break;
   case 3: instruction += *(instruction+1); break;  

Case 1 is a function that takes one parameter, which is found immediately after the instruction, so it is passed as an offset of 1 byte from the instruction. The instruction pointer is incremented by 1 + the size of the first parameter to find the next instruction.

Case 2 is a function that takes two parameters, same as before, first parameter passed as 1 byte offset, second parameter passed as offset of 1 byte plus the size of the first parameter. The instruction pointer is then incremented by the size of the instruction plus sizes of both parameters.

Case 3 is a goto statement, the instruction pointer is incremented by an offset which immediately follows the goto instruction.

EDIT 3: To my understanding, the OS will provide each process with its own dedicated virtual memory addressing space. If so, does this mean the first address is always ... well zero, so the offset from the first byte of the memory block is actually the very address of this element? If memory address is dedicated to every process, and I know the offset of my program memory block AND the offset of every program object from the first byte of the memory block, then are the object addresses resolved during compile time?

Problem is those offsets are not available during the compilation of the C code, they become known during the "compilation" phase and translation to bytecode. Does this mean there is no way to do object memory address calculation for "free"?

How is this done in Java for example, where only the virtual machine is compiled to machine code, does this mean the calculation of object addresses takes a performance penalty because of runtime arithmetics?


Source: (StackOverflow)

Assembly Language Indirect Addressing

I am working through some indirect addressing problems and I am not sure how to properly count bytes. We are given this code:

.data
v1  db  9,7,5,3,1
v2  dw  0
v3  dw  -1
v4  db  '$'

mov  dx,offset v2
mov  ah,9
int  21h

The question asks how many bytes will have been written to the standard output device after these instructions have been executed and the answer is 4.

For this problem, I set it up like so:

offset  0  1  2  3  4  5  6  7  8  9
data    09 07 05 03 01 00 00 FF FF 24

We are moving 5 into dx, writing two bytes 00 05. We then set the dos code to write it out, so our output writes out the two bytes making four? Please correct me if my logic is wrong.


Source: (StackOverflow)

MIPS - How to find the address value of branch and jump instructions

I have an exam coming up, and I am completely stuck on this question (see below); even looking at the model answer did not help. I've tried reading our main text for the topic, but still have no idea how to do this. If anyone could provide a step-by-step walk through of the question, I would be very grateful.

"Assuming the first instruction of the MIPS snippet below is located at memory address 0x10001000. What is the value for else and exit in bne and j instruction?"

1   0x10001000:   addi $s0, $0, 5
2   0x10001004:   sub $s2, $0, $s1
3   0x10001008:   beq $s0, $s2, else
4   0x1000100C:   add $s0, $0, $0
5   0x10001010:   add $t0, $s2, $s0
6   0x10001014:   j exit
7   0x10001018:   else: addi $s1, $s0, -1
8   0x1000101C:   exit:

Model Answer:

Else: 0000000000000011 Exit: 00000000000000010000000111

I have included a link to an image of the original question as well. http://i.imgur.com/NgHpZXs.png


Source: (StackOverflow)

how does pointer adressing work in c++

I am confused about pointer pointing to address of variable image

it points to last two bytes how does this work

#include <iostream>
using namespace std;

int main()
{
    int i = 1;
    short *j  = (short*)&i;
    cout << *j << endl;
}

.


Source: (StackOverflow)

Terms used for addressing modes. [intel 8085]

In the documentation of a processor I am working on it says :

Operand addressing modes available are implied, register, immediate, direct and register indirect (using the BC, DE and HL register pairs as 16-bit pointers to memory).

Can someone please explain the difference between these addressing modes in laymans terms, or perhaps post up a link where I may learn?

Thanks a lot.


Source: (StackOverflow)