parisc asm questions
Randolph,
The add instruction doesn't use the carry bit as input, but it does produce a carry bit. The addc instruction both uses and produces a carry bit. The addi instruction also does not use the carry bit as input, but it does produce a carry bit (I use the term "carry bit", although the architecture has a set of "carry/borrow bits", but in terms of the instructions referenced here, only one of the bits matters, so I refer to it as the carry bit).
So I see a variety of problems with your examples:
1) Your first loop uses addc, which means that it will use the carry bit, which may be in an undefined state the first time you execute it, if you have done nothing to set it the way you want. You can either use an add instruction before the loop to do the first add, or you can do an "add %r0,%r0,%r0" to clear the carry bit before the loop.
2) The addi in the loop messes with the carry bit, which you don't want. In most cases it will set the carry bit, unless %arg1 is less than 4. The normal convention would be to use ldo -4(%arg1),%arg1 instead. The addib instruction is ok, since it does not use or set the carry bit.
3) In the second loop the add instruction is not a noop, since it has the effect of clearing the carry bit.
Quoted 2 lines
The add instruction doesn't use the carry bit as input, but it does produce a carry bit. The addc instruction both uses and produces a carry
[...]
Thanks for the explanation. With some help from Grant on IRC I managed to figure this out as well.
Another question though -- it looks like I cannot use r4 as a scratch register as it messes with the stack. From looking at the documentation (linux/Documentation/parisc/registers) it just says that the GRs are used "as specified by ABI". Is this ABI documented some place? I did look at the PDC documentation which lists some of the registers, but I don't see anything about GR4.
randolph
Signature · 4 lines
@..@ http://www.TauSq.org/ (----) ( >__< ) ^^ ~~ ^^