Assembly x86 MASM Write required procedures for computing the results of a cubic
ID: 3841843 • Letter: A
Question
Assembly x86 MASM
Write required procedures for computing the results of a cubic equation and graphically displaying the results in the console window. A source file has been included to use as a starting point. You will need to do the following:
PART 1: Put in the code for the SolveForAandB procedure (35 points)
PART 2: Put in the code for the LinearEquation procedure (15 points)
PART 3: Put in code to compute the X increment value. (15 points)
PART 4: Put in the code for the CubicEquation procedure. (35 points)
INCLUDE Irvine32.inc
; The prototypes that the Plotter procedure calls are defined here.
INCLUDE prototypes.inc
; Local prototypes
CubicEquation PROTO, pY:PTR REAL8, x:REAL8
SineFunction PROTO, pY:PTR REAL8, x:REAL8
.data
; Cubic equation coefficients
coeffA REAL8 0.4
coeffB REAL8 1.4
coeffC REAL8 -4.0
coeffD REAL8 -6.4
windowTitle BYTE "0.4x^3 + 1.4x^2 - 4.0x -6.4",0
; Ranges for cubic plot
x0 REAL8 -10.0
x1 REAL8 10.0
y0 REAL8 -10.0
y1 REAL8 10.0
; Ranges for sine function plot
xsin0 REAL8 ?
xsin1 REAL8 ?
ysin0 REAL8 -2.0
ysin1 REAL8 2.0
fval4 REAL8 4.0
.code
main PROC
; Initialize the FPU
finit
; You can set the foreground and background colors
mov eax, yellow + (blue * 16)
call SetTextColor
; First develop and debug SolveForAandB
; You can check your values at http://www.webmath.com/equline1.html
; Then develop and debug LinearEquation
; etc.
; You call Plotter with the X & Y ranges, and the offset
; to the procedure calculating the Y values.
; Try this once your procedures are working.
;INVOKE Plotter, x0, x1, y0, y1, OFFSET windowTitle, OFFSET CubicEquation
; You can plot another function in the same program,
; and use different ranges.
; You need to define the xsin0 and xsin1 values to use this.
;INVOKE Plotter, xsin0, xsin1, ysin0, ysin1, OFFSET windowTitle, OFFSET SineFunction
exit
main ENDP
;-------------------------------------------------------------
; You can store a floating point value into a location ESI is
; pointing to as follows:
; fstp REAL8 PTR [esi]
;-------------------------------------------------------------
;-------------------------------------------------------------
SolveForAandB PROC USES esi,
xReal0:REAL8, ; x0 as real
xReal1:REAL8, ; x1 as real
yReal0:REAL8, ; y0 as real
yReal1:REAL8, ; y1 as real
pA:PTR REAL8, ; Pointer to A for storing result
pB:PTR REAL8 ; Pointer to B for storing result
; Returns A and B coefficients for linear equation.
;-------------------------------------------------------------
; PART 1: Put in the code for the SolveForAandB procedure
; The following is needed to keep the assembler from complaining
; Remove it and put in your code for the cubic function.
fld xReal0
fstp xReal0
fld xReal1
fstp xReal1
fld yReal0
fstp yReal1
mov esi, pA
mov esi, pB
ret
SolveForAandB ENDP
;----------------------------------------------------------
LinearEquation PROC USES esi eax,
pYReal:PTR REAL8, ; Pointer to y as real value
xReal:REAL8, ; x as real value
a:REAL8,
b:REAL8
;
; Computes the following equation:
; y = a * x + b
;----------------------------------------------------------
; PART 2: Put in the code for the LinearEquation procedure
; Remove the following and put in your code for the linear equation
; y = x
fld xReal
mov esi, pYReal
fstp REAL8 PTR [esi]
; The following is needed to stop the assembler from complaining
fld a
fstp a
fld b
fstp b
ret
LinearEquation ENDP
Explanation / Answer
Q5) a)The code is:
x1=linspace(30,40,40);
x2_1=14.25-x1*0.77 % x2 for the first line
x2_2=20/1.7-1.2/1.7*x1 % x2 for the second line
plot(x1,x2_1,'r',x1,x2_2,'b');
from the graph using data cursor the solution is (38.77,-15.6) (x1,x2) respectively
actually it is (-15.59,38.76)
Q5B)
on putting those values in the equation we can clearly see that this is the solution
Q4) b)The code is:
myfun= @(g,m,c,t,e,v) (g*m/c*(1-e^((-c/m)*t)))-v; % defining function
v=42;
e=2.71;
g=9.81;
t=11;
c=13;
fun=@(m) myfun(g,m,c,t,e,v);
x=fzero(fun,50) %finding it's root
fprintf('the value of the root is %f ',x);
x=61.82(app.) is the solution
Q4) a)The code is:
write v as a function of m
m=linspace(10,70,100)
v=42;
e=2.71;
g=9.81;
t=11;
c=13;
for i=1:100
v(i)=(g*m(i)/c*(1-e^((-c/m(i)*t))));
end
plot(m,v) % plot of m vs v
just copy and paste you will get the plot