Need to convert hex numbers to asm hex numbers.
Posted: Mon Mar 31, 2008 12:41 pm
There are actually two questions I need some clarification on, but let's try the bit that doesn't work first...
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:
- and that's the entire expression I'm searching for - by way of example, it matches the "X" in every LXI instruction, as well as the "normal" hex digits (0-9, A-F)!!!
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:
Textpad tells me no such patterns matched! I realise that the count specifiers means 2,3,or 4 hex digits, but since there are no 3-digit numbers, I thought I would be safe).
Here's a sample of the code I'm searching:
[EDIT] I'm sorry, I didn't put an example of what I'd like to see... Here's what I need to have happen to that example code:
I hope that helps clarify what I'm trying to do and failing...
[/EDIT]
Now, when I search for :
Textpad tells me there are no matches (there are 4 such patterns)
and if I try to be less restrictive, using, Textpad matches the XI in the last line of the example, but it doesn't match any of the hex patterns. In fact, it matches D,I,G and T (I've played around some more and verified this behaviour)
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!
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!