I'm dealing with two-complement math using 16bit registers. Please take a look at my routines and tell me if I'm doing anything wrong or if there is a better way of doing it: --------- Adding two signed numbers is: add numl, fatl adc numh, fath --------- For subtracting two signed numbers I'm using this: sub numl, fatl sbc numh, fath Maybe I should use this instead (I guess the result is the same): com fatl com fath adiw fatl, $01 add numl, fatl adc numh, fath --------- For 16x16bit signed multiply : clr zero muls auxh, genh ; (signed)S1h * (signed)S0h movw matl, prdl mul auxl, genl ; S1l * S0l mov inth, prdh mulsu genh, auxl ; (signed)S0h * S1l sbc math, zero ; Sign extend add inth, prdl adc matl, prdh adc math, zero mulsu auxh, genl ; (signed)S1h * S0l sbc math, zero ; Sign extend add inth, prdl adc matl, prdh adc math, zero ; Result here --------- Thanks, Mark Jordan
Message
Back to basics - math questions
2004-08-30 by Mark Jordan
Attachments
- No local attachments were found for this message.