Setting carry on CF

Oct 25, 2011 2 Replies

Porting some code pieces written over the last two decades on a small CF part (mcf52211) and moaning. I often set or clear carry upon exiting a call to indicate if the status index returned in d0 is meaningful. Clearing it without damaging registers is easy, say just tst.l d0 . But setting it is a madness, no way to directly manipulate the ccr, one must do say push d0 moveq #1,d0 to have the C bit set move.w d0,ccr that's what we were after pull d0



Then consider that unlike with 68k.cpu32 push and pull here are two opcodes each: push: subq.l #4,a7 move.l d0,a7



pull: movem.l (a7),d0 addq.l #4,a7



I looked with some hope at NEG etc. opcodes which I remembered were setting C, but that has been on the 6809, not on 68k... (beats me how I remember that over the decades but I do, unless I am wrong of course :-) ). Such a madness, I am glad I opted for power some 10-12 years ago to move to from cpu32, that CF part is not bad at all really but the instruction set is somewhat crippled. Not all bad, just some small but key things missing.



Dimiter


------------------------------------------------------ Dimiter Popoff Transgalactic Instruments



formatting link



------------------------------------------------------

formatting link


The use of something as architecture specific as a carry as a status flag is, well, architecture specific. What are you going to do if you ever port this code to one of the many architectures that don't have a carry flag at all? Or one that has many extra instructions setting carry (SH-4, for example), which makes it hard to preserve a carry long enough to be a useful status return.

You should pick a method of returning status that's appropriate to the machine you're running on. Perhaps use -1 to indicate "no status available".

Oh thanks but my code has been fine last 17 years - on cpu32 and on power, on which I emulate the C flag in one of the 32 CR flags. Yet to see code comparable in compactness and coding efficiency (the 17 years average at about 150 kilobytes working source/month).

Dimiter

------------------------------------------------------ Dimiter Popoff Transgalactic Instruments

formatting link

------------------------------------------------------

formatting link

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required