Tidy some code. Print pc rel addresses as signed.
authorAlan Modra <amodra@gmail.com>
Mon, 3 Apr 2000 14:17:43 +0000 (14:17 +0000)
committerAlan Modra <amodra@gmail.com>
Mon, 3 Apr 2000 14:17:43 +0000 (14:17 +0000)
opcodes/ChangeLog
opcodes/avr-dis.c

index c6d1fea64c42ae25b51d4c86cf186820cf501486..8df6679572d3abc28cf55a80b9db99d00582eb42 100644 (file)
@@ -1,3 +1,9 @@
+2000-04-03  Denis Chertykov  <denisc@overta.ru>
+
+       * avr-dis.c: Syntax cleanup.
+       (add0fff): Print the pc relative address as a signed number.
+       (add03f8): Likewise.
+
 2000-04-01  Ian Lance Taylor  <ian@zembu.com>
 
        * disassemble.c (disassembler_usage): Don't use a prototype.  Mark
index 2d7eb947df76f4d04041d2c351eb51986b04d4ac..78766869ffa7e1e1c6467ef4a6617b86ea785af8 100644 (file)
@@ -26,7 +26,6 @@ typedef unsigned short u16;
 typedef unsigned long u32;
 
 #define IFMASK(a,b)     ((opcode & (a)) == (b))
-#define CODE_MAX        65537
 
 static char* SREG_flags = "CZNVSHTI";
 static char* sect94[] = {"COM","NEG","SWAP","INC","NULL","ASR","LSR","ROR",
@@ -38,8 +37,8 @@ static char* branchs[] = {
   "BRCC","BRNE","BRPL","BRVC",
   "BRGE","BRHC","BRTC","BRID"
 };
-static char* last4[] = {"BLD","BST","SBRC","SBRS"};
 
+static char* last4[] = {"BLD","BST","SBRC","SBRS"};
 
 
 static void dispLDD PARAMS ((u16, char *));
@@ -147,8 +146,8 @@ add0fff (op, dest, pc)
      char *dest;
      int pc;
 {
-  int opcode = op & 0x0fff;
-  sprintf(dest, ".%+-8d ; 0x%06X", opcode * 2, pc + 2 + opcode * 2);
+  int rel_addr = (((op & 0xfff) ^ 0x800) - 0x800) * 2;
+  sprintf(dest, ".%+-8d ; 0x%06X", rel_addr, pc + 2 + rel_addr);
 }
 
 
@@ -160,8 +159,8 @@ add03f8 (op, dest, pc)
      char *dest;
      int pc;
 {
-  int opcode = (op >> 3) & 0x7f;
-  sprintf(dest, ".%+-8d ; 0x%06X", opcode * 2, pc + 2 + opcode * 2);
+  int rel_addr = ((((op >> 3) & 0x7f) ^ 0x40) - 0x40) * 2;
+  sprintf(dest, ".%+-8d ; 0x%06X", rel_addr, pc + 2 + rel_addr);
 }
 
 
@@ -331,49 +330,31 @@ print_insn_avr(addr, info)
                      }
                      break;
                    case 0x1:
-                     {
-                       (*prin) (stream, "    LD      %s,Z+", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,Z+", rd);
                      break;
                    case 0x2:
-                     {
-                       (*prin) (stream, "    LD      %s,-Z", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,-Z", rd);
                      break;
                    case 0x9:
-                     {
-                       (*prin) (stream, "    LD      %s,Y+", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,Y+", rd);
                      break;
                    case 0xa:
-                     {
-                       (*prin) (stream, "    LD      %s,-Y", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,-Y", rd);
                      break;
                    case 0xc:
-                     {
-                       (*prin) (stream, "    LD      %s,X", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,X", rd);
                      break;
                    case 0xd:
-                     {
-                       (*prin) (stream, "    LD      %s,X+", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,X+", rd);
                      break;
                    case 0xe:
-                     {
-                       (*prin) (stream, "    LD      %s,-X", rd);
-                     }
+                     (*prin) (stream, "    LD      %s,-X", rd);
                      break;
                    case 0xf:
-                     {
-                       (*prin) (stream, "    POP     %s", rd);
-                     }
+                     (*prin) (stream, "    POP     %s", rd);
                      break;
                    default:
-                     {
-                       (*prin) (stream, "    ????");
-                     }
+                     (*prin) (stream, "    ????");
                      break;
                    }
                }
@@ -391,49 +372,31 @@ print_insn_avr(addr, info)
                      }
                      break;
                    case 0x1:
-                     {
-                       (*prin) (stream, "    ST      Z+,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      Z+,%s", rd);
                      break;
                    case 0x2:
-                     {
-                       (*prin) (stream, "    ST      -Z,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      -Z,%s", rd);
                      break;
                    case 0x9:
-                     {
-                       (*prin) (stream, "    ST      Y+,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      Y+,%s", rd);
                      break;
                    case 0xa:
-                     {
-                       (*prin) (stream, "    ST      -Y,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      -Y,%s", rd);
                      break;
                    case 0xc:
-                     {
-                       (*prin) (stream, "    ST      X,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      X,%s", rd);
                      break;
                    case 0xd:
-                     {
-                       (*prin) (stream, "    ST      X+,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      X+,%s", rd);
                      break;
                    case 0xe:
-                     {
-                       (*prin) (stream, "    ST      -X,%s", rd);
-                     }
+                     (*prin) (stream, "    ST      -X,%s", rd);
                      break;
                    case 0xf:
-                     {
-                       (*prin) (stream, "    PUSH    %s", rd);
-                     }
+                     (*prin) (stream, "    PUSH    %s", rd);
                      break;
                    default:
-                     {
-                       (*prin) (stream, "    ????");
-                     }
+                     (*prin) (stream, "    ????");
                      break;
                    }
                }