שימוש בשני שורדים

עמוד
מוצגות 2 תגובות – 1 עד 2 (מתוך 2 סה״כ)
  • מאת
    תגובות
  • #76811
    ofri
    משתתף

    מישהו יכול לתת לי דוגמא איך להשתמש בשני שורדים? לא הבנתי איך להשתמש בES.
    תודה

    #77996
    GalDor
    משתתף

    The basic thing is this: each team is allocated a segment (usually something like 0x2000) which only they can access. In other words, if XLII1 tries to write to 0x2000:0x0100 he succeeds, if XLII2 tries to read that byte he will also succeed, but if FSM1 tries to do so he will die from memory error.

    The value of that shared segment is initially given to your survivors in the ES register. That is, in the example above, the initial value of ES for XLII1 and XLII2 would be 0x2000, but for FSM1 it could be something like 0x2100.

    An example for such a thing is the following. In this example, survivor1 saves the address of a part of its code in the shared segment, and survivor2 reads that address and goes there. This way, both survivors are next to each other.
    ;;;;;;;;;;;;;;;;;;;;;survivor1;;;;;;;;;;;;;;;;;;;;;
    @start:
    add ax, @code2-@start ;ax now contains the address of @code2
    stosw  ;this stores ax in the address: ES:DI. DI is initialized to 0, so that address is: ES:0000. Note that we do
               ;not  know the actual value of ES (we don't know if it is 0x2000 or 0x2100) but this does not matter, since
               ;survivor2 will have the same value in ES.
    @code1:
    ;This will be run by survivor1
    ;Do stuff here
    @code2:
    ;This will be run by survivor2
    ;Do stuff here

    ;;;;;;;;;;;;;;;;;;;;;survivor2;;;;;;;;;;;;;;;;;;;;;
    push es
    pop ds ;DS now points to the shared segment. We don't know in advance what that value is, but we do know
                ;that survivor1 receives the same value.
    lodsw   ;This loads the value at DS:SI to ax. But, SI is initialized to 0, so it loads: DS:0000 to ax. Since DS is
                ;pointing to the private segment, this is the same address where survivor1 stored the address of
                ;@code2. So, now ax is the address of @code2 (in survivor1's code!).
    jmp ax ;This jumps to wherever ax points at. In this case, to @code2.

מוצגות 2 תגובות – 1 עד 2 (מתוך 2 סה״כ)
  • יש להתחבר למערכת על מנת להגיב.