OpenCores
URL https://opencores.org/ocsvn/cpu_lecture/cpu_lecture/trunk

Subversion Repositories cpu_lecture

[/] [cpu_lecture/] [trunk/] [html/] [34_Listing_of_end_conv.cc.html] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jsauermann
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
"http://www.w3.org/TR/html4/strict.dtd">
3
<HTML>
4
<HEAD>
5
<TITLE>html/Listing_of_end_conv.cc</TITLE>
6
<META NAME="generator" CONTENT="HTML::TextToHTML v2.46">
7
<LINK REL="stylesheet" TYPE="text/css" HREF="lecture.css">
8
</HEAD>
9
<BODY>
10
<P><table class="ttop"><th class="tpre"><a href="33_Listing_of_make_mem.cc.html">Previous Lesson</a></th><th class="ttop"><a href="toc.html">Table of Content</a></th><th class="ttop"></th></table>
11
<hr>
12
 
13
<H1><A NAME="section_1">34 LISTING OF end_conv.cc</A></H1>
14
 
15
<pre class="vhdl">
16
 
17
  1     #include "assert.h"
18
  2     #include "ctype.h"
19
  3     #include "stdio.h"
20
  4     #include "string.h"
21
  5
22
  6     //-----------------------------------------------------------------------------
23
  7     int
24
  8     main(int argc, const char * argv)
25
  9     {
26
 10     char buffer[2000];
27
 11     int pc, val, val2;
28
 12
29
 13        for (;;)
30
 14            {
31
 15              char * s = fgets(buffer, sizeof(buffer) - 2, stdin);
32
 16              if (s == 0)   return 0;
33
 17
34
 18              // map lines '  xx:' and 'xxxxxxxx; to 2* the hex value.
35
 19              //
36
 20              if (
37
 21                  (isxdigit(s[0]) || s[0] == ' ') &&
38
 22                  (isxdigit(s[1]) || s[1] == ' ') &&
39
 23                  (isxdigit(s[2]) || s[2] == ' ') &&
40
 24                   isxdigit(s[3]) && s[4] == ':')   // '  xx:'
41
 25                 {
42
 26                   assert(1 == sscanf(s, " %x:", &pc));
43
 27                   if (pc & 1)       printf("%4X+:", pc/2);
44
 28                   else              printf("%4X:", pc/2);
45
 29                   s += 5;
46
 30                 }
47
 31              else if (isxdigit(s[0]) && isxdigit(s[1]) && isxdigit(s[2]) &&
48
 32                       isxdigit(s[3]) && isxdigit(s[4]) && isxdigit(s[5]) &&
49
 33                       isxdigit(s[6]) && isxdigit(s[7]))             // 'xxxxxxxx'
50
 34                 {
51
 35                   assert(1 == sscanf(s, "%x", &pc));
52
 36                   if (pc & 1)   printf("%8.8X+:", pc/2);
53
 37                   else          printf("%8.8X:", pc/2);
54
 38                   s += 8;
55
 39                 }
56
 40              else                             // other: copy verbatim
57
 41                 {
58
 42                   printf("%s", s);
59
 43                   continue;
60
 44                 }
61
 45
62
 46               while (isblank(*s))   printf("%c", *s++);
63
 47
64
 48               // endian swap.
65
 49               //
66
 50               while (isxdigit(s[0]) &&
67
 51                      isxdigit(s[1]) &&
68
 52                               s[2] == ' ' &&
69
 53                      isxdigit(s[3]) &&
70
 54                      isxdigit(s[4]) &&
71
 55                               s[5] == ' ')
72
 56                  {
73
 57                   assert(2 == sscanf(s, "%x %x ", &val, &val2));
74
 58                   printf("%2.2X%2.2X  ", val2, val);
75
 59                   s += 6;
76
 60                  }
77
 61
78
 62              char * s1 = strstr(s, ".+");
79
 63              char * s2 = strstr(s, ".-");
80
 64              if (s1)
81
 65                 {
82
 66                   assert(1 == sscanf(s1 + 2, "%d", &val));
83
 67                   assert((val & 1) == 0);
84
 68                   sprintf(s1, " 0x%X", (pc + val)/2 + 1);
85
 69                   printf(s);
86
 70                   s = s1 + strlen(s1) + 1;
87
 71                 }
88
 72              else if (s2)
89
 73                 {
90
 74                   assert(1 == sscanf(s2 + 2, "%d", &val));
91
 75                   assert((val & 1) == 0);
92
 76                   sprintf(s2, " 0x%X", (pc - val)/2 + 1);
93
 77                   printf(s);
94
 78                   s = s2 + strlen(s2) + 1;
95
 79                 }
96
 80
97
 81              printf("%s", s);
98
 82            }
99
 83     }
100
 84     //-----------------------------------------------------------------------------
101
<pre class="filename">
102
tools/end_conv.cc
103
</pre></pre>
104
<P>
105
 
106
<P><hr><BR>
107
<table class="ttop"><th class="tpre"><a href="33_Listing_of_make_mem.cc.html">Previous Lesson</a></th><th class="ttop"><a href="toc.html">Table of Content</a></th><th class="ttop"></th></table>
108
</BODY>
109
</HTML>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.