Сейчас на форуме: asfa, _MBK_, Adler (+8 невидимых)

 eXeL@B —› Вопросы новичков —› Вопрос про деление
Посл.ответ Сообщение

Ранг: 0.2 (гость)
Активность: 0=0
Статус: Участник

Создано: 06 января 2013 22:09
· Личное сообщение · #1

Здравствуйте. Пытаюсь написать кейген к крекми от фантома. Немного не понимаю этого:
Code:
  1. MOV BL, 1A
  2. MOV AL, 61
  3. DIV BL

После этого EAX=00001303. Разве не должно получиться 3?



Ранг: 262.5 (наставник), 337thx
Активность: 0.340.25
Статус: Участник

Создано: 06 января 2013 22:16
· Личное сообщение · #2

Code:
  1. DIV - Unsigned Divide
  2.  
  3. Opcode   Instruction         Description
  4. F6 /6    DIV r/m8    Unsigned divide AX by r/m8; AL ¬ Quotient, AH ¬ Remainder
  5. F7 /6    DIV r/m16   Unsigned divide DX:AX by r/m16; AX ¬ Quotient, DX ¬ Remainder
  6. F7 /6    DIV r/m32   Unsigned divide EDX:EAX by r/m32 doubleword; EAX ¬ Quotient, EDX ¬ Remainder
  7. Description
  8.  
  9. Divides (unsigned) the value in the AX register, DX:AX register pair, or EDX:EAX register pair (dividend) by the source operand (divisor) and stores the result in the AX (AH:AL), DX:AX, or EDX:EAX registers. The source operand can be a general-purpose register or a memory location. The action of this instruction depends on the operand size, as shown in the following table:
  10.  
  11. Operand Size      Dividend      Divisor       Quotient       Remainder      Maximum Quotient
  12. Word/byte         AX      r/m8 AL       AH    255
  13. Doubleword/word   DX:AX      r/m16         AX      DX   65,535
  14. Quadword/doubleword        EDX:EAX         r/m32   EAX        EDX    232 - 1
  15. Non-integral results are truncated (chopped) towards 0. The remainder is always less than the divisor in magnitude. Overflow is indicated with the #DE (divide error) exception rather than with the CF flag.
  16.  
  17. Operation
  18.  
  19. IF SRC = 0
  20.    THEN #DE; (* divide error *)
  21. FI;
  22. IF OpernadSize = 8 (* word/byte operation *)
  23.    THEN
  24.                 temp ¬ AX / SRC;
  25.                 IF temp > FFH
  26.                     THEN #DE; (* divide error *) ;
  27.                     ELSE
  28.                           AL ¬ temp;
  29.                           AH ¬ AX MOD SRC;
  30.                 FI;
  31.    ELSE
  32.                 IF OperandSize = 16 (* doubleword/word operation *)
  33.                     THEN
  34.                           temp ¬ DX:AX / SRC;
  35.                           IF temp > FFFFH
  36.                                 THEN #DE; (* divide error *) ;
  37.                                 ELSE
  38.                                        AX ¬ temp;
  39.                                        DX ¬ DX:AX MOD SRC;
  40.                           FI;
  41.                     ELSE (* quadword/doubleword operation *)
  42.                           temp ¬ EDX:EAX / SRC;
  43.                           IF temp > FFFFFFFFH
  44.                                 THEN #DE; (* divide error *) ;
  45.                                 ELSE
  46.                                        EAX ¬ temp;
  47.                                        EDX ¬ EDX:EAX MOD SRC;
  48.                     FI;
  49.                 FI;
  50. FI;
  51.  
  52. Flags Affected
  53.  
  54. The CF, OF, SF, ZF, AF, and PF flags are undefined.
  55.  
  56. Protected Mode Exceptions
  57.  
  58. #DE      If the source operand (divisor) is 0
  59.          If the quotient is too large for the designated register.
  60. #GP(0)   If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
  61.          If the DS, ES, FS, or GS register contains a null segment selector.
  62. #SS(0)   If a memory operand effective address is outside the SS segment limit.
  63. #PF(fault-code)   If a page fault occurs.
  64. #AC(0)   If alignment checking is enabled and an unaligned memory reference is made while the current privilege level is 3.
  65.  
  66. Real-Address Mode Exceptions
  67.  
  68. #DE      If the source operand (divisor) is 0.
  69.          If the quotient is too large for the designated register.
  70. #GP      If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
  71.          If the DS, ES, FS, or GS register contains a null segment selector.
  72. #SS(0)   If a memory operand effective address is outside the SS segment limit.
  73.  
  74. Virtual-8086 Mode Exceptions
  75.  
  76. #DE      If the source operand (divisor) is 0.
  77.          If the quotient is too large for the designated register.
  78. #GP(0)   If a memory operand effective address is outside the CS, DS, ES, FS, or GS segment limit.
  79. #SS      If a memory operand effective address is outside the SS segment limit.
  80. #PF(fault-code)   If a page fault occurs.
  81. #AC(0)   If alignment checking is enabled and an unaligned memory reference is made.
  82.  
  83. Easy Assembler Shell v3.99 Copyright(C) 1999 Roman Novgorodov


| Сообщение посчитали полезным: devnikor, Veliant

Ранг: 301.4 (мудрец), 194thx
Активность: 0.170.01
Статус: Участник

Создано: 06 января 2013 22:16
· Личное сообщение · #3

Code:
  1. xor edx, edx


| Сообщение посчитали полезным: devnikor, nick8606, SReg


Ранг: 253.5 (наставник), 684thx
Активность: 0.260.25
Статус: Участник
radical

Создано: 06 января 2013 22:22 · Поправил: DimitarSerg
· Личное сообщение · #4

devnikor пишет:
1303

03 рез-т деления
0х13 = 19 остаток

-----
ds


| Сообщение посчитали полезным: devnikor

Ранг: 65.3 (постоянный), 10thx
Активность: 0.020
Статус: Участник

Создано: 09 января 2013 00:19 · Поправил: tomac
· Личное сообщение · #5

Veliant
А при чем здесь edx? Деление байтовое, значит, AX делится, а не DX:AX и не EDX:EAX.
devnikor
Если на этом вопрос решился, напиши об этом и закрой тему.



Ранг: 62.8 (постоянный), 11thx
Активность: 0.060
Статус: Участник

Создано: 09 января 2013 00:30
· Личное сообщение · #6

devnikor
ну вопервых
Code:
  1. MOV AL, 61

наследует от предыдущего кода AH
а это может очень круто влиять на результат
во вторых как вам правильно уже сказали цитируя ман -целочисленное деление это получение частного и остатка

| Сообщение посчитали полезным: DimitarSerg


Ранг: 253.5 (наставник), 684thx
Активность: 0.260.25
Статус: Участник
radical

Создано: 09 января 2013 00:37 · Поправил: DimitarSerg
· Личное сообщение · #7

tomac пишет:
А при чем здесь edx? Деление байтовое, значит, AX делится, а не DX:AX и не EDX:EAX.

Согласен.

Code:
  1. При 8-битовом делении це­лая часть отношения помещается в регистр AL, а остаток  -  в регистр АН.


Получается в данном конкретном случае играют роль два регистра EAX, EBX и возможный мусор в одном из них (EAX, точнее его часть (AH)), вот если его перед этим обнулить (xor ah,ah) - другое дело, а edx - нафиг не нужен. Я не спец может и ошибся, поправьте если что.

-----
ds


| Сообщение посчитали полезным: SReg
 eXeL@B —› Вопросы новичков —› Вопрос про деление
:: Ваш ответ
Жирный  Курсив  Подчеркнутый  Перечеркнутый  {mpf5}  Код  Вставить ссылку 
:s1: :s2: :s3: :s4: :s5: :s6: :s7: :s8: :s9: :s10: :s11: :s12: :s13: :s14: :s15: :s16:


Максимальный размер аттача: 500KB.
Ваш логин: german1505 » Выход » ЛС
   Для печати Для печати