Page 1 of 1

Psuedocode implementation of ADD?

Posted: Wed Jan 20, 2010 1:42 pm
by Stevetronics
I have a coding problem. I'm in the process of writing an AVR ATmega168 simulator/emulator for my Ubuntu box, and yes, It'll be open source when I'm done. I'm looking for a way to implement the ADD instruction in java. ADD adds two registers without carry. I'm not really sure how to do that. Should I just implement a binary adder in code? I'm not sure what route to take. If anyone has an efficient suggestion, I'd be very grateful. Thanks!

Re: Psuedocode implementation of ADD?

Posted: Wed Jan 20, 2010 1:58 pm
by tetsujin
Stevetronics wrote:I have a coding problem. I'm in the process of writing an AVR ATmega168 simulator/emulator for my Ubuntu box, and yes, It'll be open source when I'm done. I'm looking for a way to implement the ADD instruction in java. ADD adds two registers without carry. I'm not really sure how to do that. Should I just implement a binary adder in code? I'm not sure what route to take. If anyone has an efficient suggestion, I'd be very grateful. Thanks!
I don't get it. Why not just read in the two registers into integers and add them together, set the carry flag if the answer is over 255, and store the bottom 8 bits of the result into the target register?

(Actually I guess you need to set other SREG flags as well: H, S, V, N, Z, and C. But still...)

Posted: Wed Jan 20, 2010 3:21 pm
by OrlandoArias
You may want to take a look at
http://gitorious.org/simavr

Yup/.

Posted: Wed Jan 20, 2010 4:25 pm
by Stevetronics
The SREG flag was the way to go. I tracked down Atmel's AVR instruction set info (not hard) and went with that. I'm working on it as we speak. Well, not quite. I have 2 tests, a quiz, and a paper tomorrow, so It'll have to wait. :(

Posted: Thu Jan 21, 2010 12:59 pm
by Halfbubble
My coding problems are usually related to ADD, but not the instruction :lol: