I'm writing a calculator program in postfix notation. I got the operations to work but it subracts no matter what sign I put into it. Gor example I put 12 12+, and it would subtract instead to add. Let me know what I'm doing wrong.
TITLE Program Assign4 (Assign4.asm)
INCLUDE Irvine32.inc
.data
input BYTE "Please input two numbers and operation in postfix notation or 0 to terminate the program:",0
minus BYTE " - ",0
plus BYTE " + ",0
divide BYTE " / ",0
multiply BYTE " * ",0
equal BYTE " = ",0
remainder BYTE " , ",0
warningMsg BYTE "The program is terminated!",0
array DWORD 2 (0),0
divisor DWORD ?,0
.code
main PROC
mov eax,white + (red * 16)
call SetTextColor
mov edx, OFFSET input
call WriteString
call Crlf
start:
mov ecx, LENGTHOF array
mov esi, OFFSET array
;input
mov esi, 0
mov ecx, LENGTHOF array
;---------------------------------------------------------------------------------
L2:
call ReadInt
mov array[esi], eax
.IF (esi == 0) && (eax == 0)
mov edx, OFFSET warningMsg
call WriteString
call Crlf
jmp terminate
.ENDIF
add esi, 4
loop L2
;compare numbers
mov eax, array[0]
mov ebx, array[4]
.IF eax == ebx
push eax
pop eax
call subtraction
.ELSEIF eax < ebx
push eax
pop eax
call addition
.ENDIF
jmp start
terminate:
exit
main ENDP
;subtraction prog
subtraction PROC
push eax
push edx
call WriteInt
mov edx, OFFSET minus
call WriteString
mov eax, ebx
call WriteInt
mov edx, OFFSET equal
call WriteString
pop edx
pop eax
sub eax, ebx
call WriteInt
call CrLf
ret
subtraction ENDP
;addtion prog
addition PROC
; print on screen
push eax
push edx
call WriteInt
mov edx, OFFSET plus
call WriteString
mov eax, ebx
call WriteInt
mov edx, OFFSET equal
call WriteString
pop edx
pop eax
add eax, ebx
call WriteInt
call CrLf
ret
addition ENDP
END main
Pro32,
Your main code loop is coded wrong!
Tell me why is your main code loop is based on input magnitude and not on your postfix operator?
You have more issues to deal with than the postfix operator not being used.
;compare numbers ** Based on what?
.IF eax == ebx
call subtraction
.ELSEIF eax < ebx
call addition
.ENDIF
Regards, P1 :8)
Ok I see what you mean. So in order for it to work in postfix notation. Should I check to see what was last inputed by the user? Since this is postfix notation, the last thing inputed are the operations. How can I go about doing that. How can i compare the last input to (-,+,/,*)
Pro32,
You have two more subroutines(/*) to write and your main code loop, with a better input parser than you have now.
You will help yourself, if you take the time to code it yourself, then ask for follow-up advise.
I know that, I don't do homework for someone, but I will assist those who try to help themselves. I believe by the lack of responses, that this is the main thought here.
Because I have learned to developed these self help skills, by the silence of those un-answered questions that I have authored. It was a blessing to me then and it will be a blessing to you now.
Regards, P1 :8)
PS: I do not have access to INCLUDE Irvine32.inc and do not know what is available through support routines there. The assignment is testing your ability to manage concepts within a structure problem.
Actually I left out the two remaining subroutines on purpose, because I know a lot of students all over the world will be writting the same program someday. I fixed the mistake that you pointed out and now I'm finished with the program. Thanks
BTW
I'm actually learning this on my own because the teacher has not taught anything. Just tells us to read the book and do the assignments without giving us any examples to back it up.
Pro32,
Congratulations!
BTW, When your done with school, teacher = boss, with about the same results. So don't get the idea it will become better.
My Boss has not look at my code in years. Which I appreciate, because as long as the code does what it is needed. Anyway, I've been fixing other people's code including my boss' since I got here.
Regards, P1 :8)