Confuses the memory location of this Y86 build code

We had a piece of C code in one class, where we needed to convert it to Y86, and it was written on the board by some guy with teacher corrections, of course.

However, I confuse the memory addresses and the .pos directives in the initial part of the code:

int array[100], sum, i;

int main() {
    sum = 0;

    for(i = 0; i < 100; i++) {
        array[i] = i;
        sum += array[i];
    }
}

.pos 0
    irmovl Stack, %esp
    rrmovl %esp, %ebp
    jmp main
array:
.pos 430

sum: .long 0
i: .long 0

main:
  // (rest of the code that doesn't really matter here)

What I understand from this code:
It starts at position 0 ( .pos 0 ), the irmovl command takes 6 bytes, so the next rrmovl instruction starts at position 6 and this instruction takes 2 bytes, now we are at position 8.

The jmp command takes 5 bytes, starting at 8, now we are at position 13.

Now you need to save the stack space to store 100 integers for the array , .pos 430 400 (4 * 100 ) 17 ( , 430-13 = 17).

430, 4 , sum, 4 - i, 438.

438 .

, , :
.pos 430, 100 ? 400 , . .pos 413 ( 13 400 100 , , 413) , .pos 430?

?

+3
2

, pos . .

, "" 13, "" 430. 438 417 .

. , pos . , . 430 .

+3

, Y86. .

, , .pos 413 ( ). , " ", irmovl ... jump, , , .

, , .

+1

Source: https://habr.com/ru/post/1710868/


All Articles