Stack Instructions:
PUSH A
PUSH B
SUB
POP X
Is X = A-B
or
X = B-A?
Thank you in advance! 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In theory,
SUBcould be defined either way (as @delnan says).In practice, most stack-based languages or instruction sets will follow the conventions of Reverse Polish notation:
5 2 -would be3, and can be thought of in terms of stack operations aspush 5; push 2; subtract. So, in your example,X = A-Bwould be the more typical expected result.(A real example:
isubin the JVM.)