ich 80386 von PC Assembly by paul caurterProblem beim Verständnis mul & IMUL Anweisungen von Assembler
mul source
- Wenn der Operand Byte groß, es wird multipliziert mit dem Byte in der AL Register Lernen und Das Ergebnis ist in die 16 Bits von AX gespeichert.
gut.
- Wenn die Quelle 16-Bit ist, ist es durch das Wort in AX multipliziert wird, und das 32-Bit-Ergebnis wird in DX gespeichert: AX.
Q1: Warum DX: AX? Warum kann es nicht in EAX/EDX gespeichert werden?
imul
ist wirklich verwirrend
imul dest, source1
imul dest, source1, source2
alt text http://img697.imageshack.us/img697/8976/imul.gif
ich Problem habe die Tabelle zu verstehen.
Q2: im zweiten Eintrag der Tabelle. Nochmals, warum DX: AX. Warum nicht EAX oder EDX?
nun folgenden Code-Schnipsel betrachten:
imul eax ; edx:eax = eax * eax
mov ebx, eax ; save answer in ebx
mov eax, square_msg ; square_msg db "Square of input is ", 0
call print_string ; prints the string eax
mov eax, ebx
call print_int ; prints the int stored in eax
call print_nl ; prints new line
Q3: Sein sagte previsously dass The notation EDX:EAX means to think of the EDX and EAX registers as one 64 bit register with the upper 32 bits in EDX and the lower bits in EAX.
So ist die Antwort auch in edx gespeichert ist, nicht wahr? im obigen Code haben wir keine EDX berücksichtigt, wir beziehen uns nur auf EAX Wie funktioniert das noch?
Q4: Ich habe ein Problem mit dem Rest aller Einträge in der Tabelle. Worst-Case-Multiplikationsergebnis von zwei n-Bit-Zahlen (n = 8/16/32 Bits) ist 2n Bits. Wie kommt es, dass das Ergebnis von zwei 16/32-Bit-Multiplikationen in einem Register derselben Größe gespeichert wird?
@ Q3: Ich wusste es. Dies ist der Code aus diesem Buch von Paul Carter. Kannst du mir sagen, wie der Code sein sollte? Ich bin verwirrt, wie man das Ergebnis druckt. – claws
Der angegebene Code ist nur ein Beispiel; Der Text sollte irgendwo erwähnen, dass das Quadrat nicht richtig berechnet wird, wenn die Eingabe außerhalb des erwarteten Bereichs liegt. Da Sie eine 'print_int'-Funktion aufrufen, um eine 32-Bit-Ganzzahl zu drucken, sehen Sie, ob Sie eine 'print_int64'-Funktion zum Drucken einer 64-Bit-Ganzzahl finden können. –
@ Q4: Ja, so soll es sein, aber die Tabelle sagt 16bit Multiplikation ist in 16bit Ergebnis gespeichert. 4. Eintrag: 'dest * = source1' => dest = dest * source1; Ziel ist 16 Bit und Quelle 1 ist 16 Bit. Und es ist der gleiche Fall für alle Tabelleneinträge. sogar der letzte Eintrag source1 & source2 sind 32 bit und dest ist auch 32 bit. – claws