Adding 3 numbers with Simple Add

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Adding 3 numbers with Simple Add

pawdwanlearner
Hello folks, I am now in the process of writing my VM translator. I have been able to implement everyting except the portion in the stack test where you push 3 values to the stack and are expected to add them together. Only problem is the simple add i coded in assembly was only good for the simple add test which only push two numbers to the stack at a time. So my question is how do i add more than two numbers with simple add, or do i have to rewrite the simple add into something that has more functionality. Any pointers on this would be helpful. its at this point my stack test is failing.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding 3 numbers with Simple Add

cadet1620
Administrator
There isn't an "add 3 numbers" stack operation. What you are seeing is an expression being evaluated.
57 & - ((31+53) - 112)

push constant 57
push constant 31
push constant 53
add                              adds 32+53 leaves 84 on the stack
push constant 112
sub                              subtracts 84-112 leaves -28 on the stack
neg                              negates -28 leaves 28 on the stack
and                              bitwise And 57 & 28 leaves 24 on the stack

Warning, I did the math in my head as I was typing; it may be worng 8-(

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding 3 numbers with Simple Add

pawdwanlearner
Ahhhh, I see i was going to go that route but didn't quite know if that was correct.
I need to check my sub function to be sure its pulling the values off the stack in the correct order. I found it curious that if i push 7 and then push 6 that it was actually like saying 6-7 instead of 7-6. so in those cases i needed to say D=M-D instead of D=D-M to get the correct result. Is my logic correct on this or did i HACKa solution.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding 3 numbers with Simple Add

cadet1620
Administrator
pawdwanlearner wrote
Ahhhh, I see i was going to go that route but didn't quite know if that was correct.
I need to check my sub function to be sure its pulling the values off the stack in the correct order. I found it curious that if i push 7 and then push 6 that it was actually like saying 6-7 instead of 7-6.
push a
push b
sub

computes a-b.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding 3 numbers with Simple Add

pawdwanlearner
Done Moving on to memory segment manipulation. Thanks for your help sir. I was curious you seem to be the most knowledgeable here on these matters. Are you an engineer of some kind, and if so what makes you participate in this forum to answer our questions.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Adding 3 numbers with Simple Add

cadet1620
Administrator
My "about me" post.

I do this as a way to pay back the people who helped me learn this stuff back in the dark ages, and because I like to teach.

I encourage you to teach what you know and enjoy to others. I find it quite rewarding.

--Mark
Loading...