Assembler-Prog



  • Hallo Leute,

    kann kein Assembler, sondern nur C++, und muss aber für meine Prof folgendes lösen:

    y=a*x4-b*x2+c asl Assembler-Prog.

    Könnt ihr mir da helfen?
    Und wie kann ich das ganze mit nur 2 Registern lösen?

    Danke.

    Gruß,

    Stalin



  • Zeig erstmal wie weit du schon bist.

    Irgendwas musst du schon vorweisen. 🙂



  • Wieso sollst du ihm sowas vorweisen, wenn du kein Assembler kannst?
    Wenn du Assembler in der Schule lernst, wirst du doch sicher einfache Additionen
    bereits hinbekommen und einen Teil deiner Aufgabe bereits lösen können, oder?



  • y=a*x4-b*x2+c is mit zwei Registern zu lösen. So könnte das ganze realisiert werden ich glaub das is auch ohne assemblerkentnisse verständlich. Allerdings wird nich auch Überläufe von Registern überprüft. Das wird mit 2 Registern problematisch

    ;ich benutze eax und ebx.
    x dd 123d ;halt statt 123 der Wert für x max 32 bit lang
    b dd 123d ;Wert für b s.o.
    a dd 123d; Wert für a s.o.
    c dd 123d ;Wert für c s.o.
    y dd ? ;für y wird während der Laufzeit gesetzt
    mov eax, x
    imul EAX,x;  x*x
    imul EAX,x; x*x
    imul EAX,x ;x*x
    ;jetzt steht in EAX x^4 allerdings wird nich auf Überlauf überprüft
    imul EAX,a
    sub EAX,b
    mov EBX,x
    imul EBX,x;  x*x
    ;in EBX steht x^2
    mul EBX,b;x^2*b
    sub EBX,c;x^2*b-c
    sub EBX,EAX;a*x^4-b*x^2+c
    mov y,EBX;jetzt stehts in y
    

    keine sehr schöne Lösung zugegeben aber mit 2 Registern
    a b c y und x sind halt 32 bit variablen. Habs mal mit Tasm assembliert. Gab keine Fehler aber getestet isses auch nich



  • Also mvoidt, du vergisst hier Punkt- vor Strichrechnung. Das x^2 berechnest du im Prinzip zweimal, das ist unnötig. IMUL EAX verändert soweit ich weiß auch EDX, vielleicht ein unschöner Nebeneffekt. Hier mal meine Variante (ebenfalls ohne Überlaufabfrage):

    a DD 4
            b DD 5
            c DD 7
            x DD 10
            y DD ?
    
            mov eax,x       ; eax = x
            imul eax,eax    ; eax = x^2
            mov ebx,eax     ; ebx = x^2
            imul eax,eax    ; eax = x^4
            imul eax,a      ; eax = a*x^4
            imul ebx,b      ; ebx = b*x^2
            sub eax,ebx     ; eax = a*x^4-b*x^2
            add eax,c       ; eax = a*x^4-b*x^2-c
            mov y,eax       ; und das ganze nach y
    

    Ich habe es mal getestet, sollte funktionieren.



  • So es ging ja auch nicht ummich,sondern um einen Freund.
    Der muss das halt theoretisch zeigen auf Papier, so wie Load x in R1 usw.
    Ich hab doch davon keine AHnung. Dann dachte ich mir das dieses Forum doch dafür ganz gut sei oder?
    Sind EAX und EBX Register?
    Noch ne Frage: Kennt ihr den Befehl BLOD in Assembler?
    Der stand auf dem Aufgabenblatt und hat nen Wert in das lower-byte von einem Register geladen oder so ähnlich. Hab aber bei google nichts dazu gefunden.



  • imul verändert meines wissens nicht EDX. Das verwechselst du glaub ich mit MUL. Da is das so. Deswegen hab ich auch IMUL benutzt. Bin mir aber nich 100% sicher



  • So weit ich das gesehen habe, kommt das auf die Operandenkombination an.
    Bei nur einem Operanden wird das Ergebnis der Multiplikation in (e)ax:(e)dx gespeichert.
    Bei 2/3 Operanden kommt das Ergebnis in den ersten...



  • "One-operand form. This form is identical to that used by the MUL instruction. Here, the source operand (in a general-purpose register or memory location) is multiplied by the value in the AL, AX, or EAX register (depending on the operand size) and the product is stored in the AX, DX:AX, or EDX:EAX registers, respectively.

    Two-operand form. With this form the destination operand (the first operand) is multiplied by the source operand (second operand). The destination operand is a general-purpose register and the source operand is an immediate value, a general-purpose register, or a memory location. The product is then stored in the destination operand location.

    Three-operand form. This form requires a destination operand (the first operand) and two source operands (the second and the third operands). Here, the first source operand (which can be a general-purpose register or a memory location) is multiplied by the second source operand (an immediate value). The product is then stored in the destination operand (a general-purpose register)."

    Aus "Intel Pentium Instruction Set Reference" (Ich glaube das war bei einem MASM Package dabei)


Anmelden zum Antworten