[Coco] C Coding question

dlb db388696 at gmail.com
Wed Dec 25 23:12:56 EST 2024


I'm disassembling a program and came across something that was
interesting, to say the least.  Here's what I have:

The disassembly of this particular function was:
1066  0762 34   40        L0762        pshs   u          
 1067  0764 cc   ffbc                   ldd    #-68       
 1068  0767 17   f992                   lbsr   _stkchec   
 1069  076A 20   13                     bra    L077f      
 1070  076C 17   185b      L076c        lbsr   L1fca      
 1071  076F ed   7e                     std    -2,s       
 1072  0771 26   1c                     bne    L078f      
 1073  0773 cc   0001                   ldd    #1         
 1074  0776 17   1cfb                   lbsr   L2474      
 1075  0779 1083 ffff                   cmpd   #-1        
 1076  077D 27   10                     beq    L078f      
 1077  077F dc   35        L077f        ldd    <D0035     
 1078  0781 1093 37                     cmpd   <D0037     
 1079  0784 2d   05                     blt    L078b

This is the code in question    
 1080  0786 cc   0001                   ldd    #1         
 1081  0789 20   02                     bra    L078d      
 1082  078B 4f             L078b        clra              
 1083  078C 5f                          clrb              
 1084  078D 27   dd        L078d        beq    L076c      
 1085  078F 35   c0        L078f        puls   u,pc


This was written in C - it's scred, to be specific.  To get this code,
I had to do the following:

L0762()
{
    /* Why did they do this ??  Wouldn't (D0035 < D0037 work? */
    while ((D0035 >= D0037) == 0)
    {
        if ((L1fca() != 0) || (L2474(1) == -1))
        {
            break;
        }
    }
}

The comment in the code above states my question.  Wouldn't what my
suggestion do the same?  I cannot understand why anyone would write
code like that unless there's something I am missing.


More information about the Coco mailing list