I need to "pretty" up some hexadecimal numbers in ASCII form in a very long file (20,000 lines). The lines are in standard text format, this isn't some wierd hex editing question (I hope!).
So what I'm trying to do is convert the raw DDT hex numbers (like "FFFE") to compiler-friendly hex numbers ("0FFFEH"). Basically, I need to add a "H" suffix to all such numbers, and I need to add a prefix if (and only if!) the hex number starts with A/B/C/D/E/F.
All such numbers appear as ONLY 2 or 4-digit numbers, and ALWAYS at the end of the line, so the $ appears to be a great anchor point.
I've tried using the [:xdigit:] regexp (posix mode off), but it doesn't seem to work as expected - if I try to match a single hex digit, with the pattern:
Code: Select all
[:xdigit:]
Because of this behaviour, I can't trust it to find and prepend/append the necessary characters - because it seems to match X's as well, it also matches L's in HL, etc, so it incorrectly matches non-hex numbers and digits.
And whenever I try to use count patterns (like looking for only 2 or 4-digit hex numbers so registers like a,b,c,d,e and f don't get modified), the search seems to fail. So, for example if I use the following search pattern:
Code: Select all
[:xdigit:]\{2,4\}$
Here's a sample of the code I'm searching:
Code: Select all
JMP 0127
JMP 01C2
JMP 4F23
MOV B,E
MVI L,41
MOV D,E
MOV C,L
??= 20
??= 28
INX SP
??= A0
DAD H
??= 20
STA DD39
MOV C,L
MOV H,C
MOV M,D
DCR L
LXI SP,F939
Code: Select all
JMP 0127H
JMP 01C2H
JMP 4F23H
MOV B,E
MVI L,41H
MOV D,E
MOV C,L
??= 20H
??= 28H
INX SP
??= 0A0H
DAD H
??= 20H
STA 0DD39H
MOV C,L
MOV H,C
MOV M,D
DCR L
LXI SP,0F939H
[/EDIT]
Now, when I search for :
Code: Select all
[:xdigit:]\{2\}$
and if I try to be less restrictive, using
Code: Select all
[:xdigit:]\{2\}
So, what am I doing wrong?
The next question is, can anyone help with the replacement pattern to use so that I can prepend AND append the 0 and H to the matching patterns?
I realise this is a big ask, but the behaviour is bizarre, and I'm at the end of my wits (I have abnormally small wits).
Thanks in advance!