stk segment stack 'stack' db 256 dup('?') stk ends data segment 'data' A db 10 B db 4 C dw -23 D dw ? E dw ? F dd ? data ends code segment 'code' assume cs:code, ds:data, ss:stk start: mov ax,data mov ds,ax mov ax,C imul C mov bl,A mov bh,0 sub ax,bx imul ax mov word ptr F,dx mov word ptr [F+4],ax imul C mov E,ax mov ah,B add E,ax mov ax,D idiv E mov D,ax sub D,20 mov dl,al add dl,30h mov ah,02h int 21h mov ah,4Ch int 21h code ends end start 

Error writing code to solve equation

 x= ((d^2 - a)^2)/(d^2 +b))-20, при a=10, b=4, d=-23 

Where is she?

  • Oh, int 21h ! And you tried to pass under a debugger? And then debugging assembler "in the head" is not an easy task. - VladD
  • one
    A few notes: 1. Call the variables your name (in the condition you have given a, b, d, the answer is in x, the code is given a, b, c, the answer is in d, plus two auxiliary variables). If you keep a square d somewhere, then call d_squared, d_v_kvadrate. Well, etc. 2. Line breaks break the code into meaningful blocks, so it will be much more readable. 3. Uncomment the code, just for yourself. 4. Finally, go through the debugger. - insolor

1 answer 1

Rewrote completely from scratch for fasm under Windows, but using 16-bit registers in computations. This requires some care, because during squaring, when calculating the dividend, the output exceeds 16 bits, the result of the exponentiation is placed in dx:ax . At each stage for control, I made a debugging output (now commented out).

 ; x= ((d^2 - a)^2)/(d^2 + b))-20, при a=10, b=4, d=-23 format PE console include 'win32ax.inc' entry start section '.data' data readable writeable A dw 10 B dw 4 D dw -23 _fmt db '%d',13,10,0 D2 dw ? divider dw ? section '.code' code readable executable start: ; D2 = D * D mov ax, [D] imul ax mov [D2], ax ; movsx eax, ax ; cinvoke printf, _fmt, eax ; mov ax, [D2] ; (D^2 + B) ; В данном случае удобнее считать сначала делитель add ax, [B] mov [divider], ax ; movsx eax, ax ; cinvoke printf, _fmt, eax ; (D^2 - A)^2 mov ax, [D2] sub ax, [A] imul ax ; результат в dx:ax ; push dx ; push ax ; shl edx, 16 ; mov dx, ax ; cinvoke printf, _fmt, edx ; pop ax ; pop dx idiv [divider] ; делимое в dx:ax, результат в ax ; push ax ; movsx eax, ax ; cinvoke printf, _fmt, eax ; pop ax sub ax, 20 movsx eax, ax cinvoke printf, _fmt, eax invoke getch invoke ExitProcess section '.idata' import data readable library kernel, 'kernel32.dll', \ msvcrt,'msvcrt.dll' import kernel,\ ExitProcess, 'ExitProcess' import msvcrt,\ printf,'printf',\ getch,'_getch' 

The result is 485. For verification, here is the python code:

 a=10 b=4 d=-23 x=((d**2-a)**2)//(d**2+b)-20 print(x) 

Conclusion: 485