Write a program to evaluate the arithmetic statement π₯ = βπ + (π β π β 4 β π β π)/ πΆ + π» i. Using a general register computer with 3 address constructions ii. Using a stack organized computer with zero address operation instructions.Β
i)
MUL R1, b, b R1"\\gets" M[b]*M[b]
MUL R2, 4, a R2"\\gets" M[4]*M[a]
MUL R2, R2, c R2"\\gets" R2*c
SUB R1, R1, R2 R1"\\gets" R1-R2
SUB R1, R1, b R1"\\gets" R1-M[b]
ADD R3, C, H R3"\\gets" M[C]+M[H]
DIV X, R1, R3 X"\\gets" R1/R3
ii)
PUSH 4 TOS"\\gets" 4
PUSH a TOS"\\gets" a
PUSH c TOS"\\gets" c
MUL TOS"\\gets"(4*a)
MUL TOS"\\gets"(4*a*c)
PUSH b TOS"\\gets" b
MUL TOS"\\gets" (b*b)
SUB TOS"\\gets" ((b*b)-(4*a*c))
SUB TOS"\\gets"(((b*b)-(4*a*c))-b)
PUSH TOS"\\gets" C
PUSH TOS"\\gets" H
ADD TOS"\\gets"(C+H)
DIV TOS"\\gets" (((b*b)-(4*a*c))-b)/(C+H)
POP X M[X]"\\gets" TOS
Comments
Leave a comment