Good day. Something I already broke the brain. It is necessary to implement on C #, what happens in the controller.

CMP R0, R3 BLE loc_7BAE ; я Ρ‚Π°ΠΊ понимаю, Π·Π½Π°ΠΊΠΎΠ²ΠΎΠ΅ сравнСниС. (Z==1) || (N!=V) . . . loc_7BAE: ADDS R4, R0, #0 ; Π° Π²ΠΎΡ‚ Ρ‚ΡƒΡ‚, Ρƒ нас Π² ΠΊΠ°ΠΊΠΈΡ… случаях Π±ΡƒΠ΄Π΅Ρ‚ +1??? 

Well, that is, on Sharp we get it? or not quite like that?

 if (R0 <= R3) // R0, R3 - Int32 { R4 = R0; // R4 = R0 + 0 if(R0 == R3) R4++; // ??? } 

    2 answers 2

    The difference is that the ADD team does not update the flags, and the ADDS updates it depending on the result of the addition. Therefore, you will definitely not have +1, but if there are any BXX checks further, you need to look more closely.

    Learn more: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489i/Cihcjfjg.html

    Taken here: https://reverseengineering.stackexchange.com/a/4262

    • Yes thank you. I figured it out last night (stupidly completed the model and scrolled. And I realized that there is +0, otherwise it does not go out of the cycle). It’s just that this place is visited from two different conditions (there’s no high-level language without a goto. Apparently, some kind of optimization.) And in the second case, it’s always +1. I stupidly twice this place in the model. in different conditions delivered. - EugenOS

    Here's how it looked (can someone come in handy)

     00007B98 CMP R4, R3 00007B9A BLE loc_7BAA 00007B9C CMP R0, R3 00007B9E BLE loc_7BAE 00007BA0 MOVS R3, #8 00007BA2 SUBS R4, R3, R2 00007BA4 LSLS R4, R4, #0x10 00007BA6 LSRS R4, R4, #0x10 00007BA8 B loc_7BB0 00007BAA 00007BAA loc_7BAA: 00007BAA CMP R4, R0 00007BAC BLS loc_7BB0 00007BAE 00007BAE loc_7BAE: 00007BAE ADDS R4, R0, #0 00007BB0 00007BB0 loc_7BB0: 

    on sharpe it turned out like this:

     bool cmp_le(uint r1, uint r2) { // для ΠΈΠΌΠΈΡ‚Π°Ρ†ΠΈΠΈ ble ΠΏΡ€ΠΈΠ²ΠΎΠ΄ΠΈΠΌ сравниваСмыС ΠΊ Π·Π½Π°ΠΊΠΎΠ²Ρ‹ΠΌ значСниям ΠΈ сравниваСм int i1 = (int)r1; int i2 = (int)r2; return (i1 <= i2); } if (!cmp_le(R4, R3)) { if (cmp_le(R0, R3)) { R4 = R0;// adds r0,0 Π½ΠΎ ble => z=1 || n != v } else { R4 = (8 - R2) & 0xFFFF; } } else if (R4 > R0) { R4 = R0 + 1; // ?? adds r0,0 Π½ΠΎ bhi => z=0, c=1 }