Psuedocode implementation of ADD?

Your source for all things Atmel.

Moderator: phalanx

Post Reply
Stevetronics
Posts: 25
Joined: Fri Sep 11, 2009 4:39 pm
Location: Cleveland, OH

Psuedocode implementation of ADD?

Post by Stevetronics » Wed Jan 20, 2010 1:42 pm

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!
"Oh, you have to plug it into the wall!" - Just before 120VAC hit his 'Mega168.

tetsujin
Posts: 135
Joined: Wed Jul 23, 2008 5:07 pm
Contact:

Re: Psuedocode implementation of ADD?

Post by tetsujin » Wed Jan 20, 2010 1:58 pm

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...)
---GEC

OrlandoArias
Posts: 23
Joined: Sun Jan 10, 2010 1:22 pm
Location: The Wired 2.0

Post by OrlandoArias » Wed Jan 20, 2010 3:21 pm

You may want to take a look at
http://gitorious.org/simavr

Stevetronics
Posts: 25
Joined: Fri Sep 11, 2009 4:39 pm
Location: Cleveland, OH

Yup/.

Post by Stevetronics » Wed Jan 20, 2010 4:25 pm

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. :(
"Oh, you have to plug it into the wall!" - Just before 120VAC hit his 'Mega168.

Halfbubble
Posts: 3
Joined: Sat Dec 05, 2009 1:12 pm

Post by Halfbubble » Thu Jan 21, 2010 12:59 pm

My coding problems are usually related to ADD, but not the instruction :lol:

Post Reply