SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By Stevetronics
#91359
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!
By tetsujin
#91362
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...)
By Stevetronics
#91381
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. :(
By Halfbubble
#91466
My coding problems are usually related to ADD, but not the instruction :lol: