Can someone tell me what I am doing wrong in this program?
Write, assemble, and test a program to input 3 signed values (a, b, and c, in that order) and to calculate and
display the signed value of the expression b + 2(3a - 4c) + 5.

"call getVal  ;AX = a (user input)
mov M1, AX   ;M1 = a
call getVal  ;AX = b (user input)
mov M2, AX   ;M2 = b
call getVal  ;AX = c (user input)
mov M3, AX   ;M3 = c
call getVal  ;AX = d (user input)
mov BX, AX   ;BX = d
call getVal  ;AX = x (user input)
mov CX, AX   ;CX = x

mul BX       ;DX:AX = AX*BX = x*d = dx (usually DX=0
mov DX,M3    ; DX=c
add Ax,Dx    ;AX=c+dx
mul Cx       ; Ax=(c + dx)x

mov DX,M2    ; DX=b
add AX ,Dx   ; Ax=b + (c + dx)x
mul CX       ;AX=(b + (c + dx)x)x

mov DX,M1    ; DX=a
add Ax,Dx    ;Ax=a + (b + (c + dx)x)x
call putVal  ;displays contents of AX, which is a + (b + (c + dx)x)x"

What is the problem you are having? This looks like a legitimate assembly program fragment (assuming you are using EMU8086 or a DOS box of some sort), but not exactly a complete program. The biggest issue I can see is that it doesn't compute what your supposed to; this takes in five variables, not the three specified, and the formula it calculates does not match that in the problem statement.

I can help you with this problem, but there are several inconsistencies to deal with first.

1:) Formula:

b + 2(3a - 4c) + 5

So how does d (line 7) & x (line 9) fit into the scheme of things. and

a + (b + (c + dx)x)x

Is this what the result is supposed to be

2:) What does getVal do. I'm assuming it strips MSB from input. This means that when you enter the digit 9, what is returned is actually DEC 57 - HEX 39 - BIN 0011 1001. Does getVal adjust so AX = 9?

This article has been dead for over six months. Start a new discussion instead.