I have successfully rewritten the 91 byte executable as provided in http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html in hexadecimal.# ELF32 header (52 bytes)
7F 45 4C 46 # signature
01 01 01 00 # ELFCLASS32, ELF2LSB, EV_CURRENT (file version), ELFOSABI_NONE
00 00 00 00 00 00 00 00 # padding
02 00 # executable
03 00 # for Intel 80386 (also known as x86, x86-32 and IA-32)
01 00 00 00 # object file version (EV_CURRENT)
54 80 04 08 # entry point 0x08048054 = 0x08048000 + 0x34 + 0x20
34 00 00 00 # program header offset: right after ELF header, 52 bytes)
00 00 00 00 # section header offset: no section headers
00 00 00 00 # The Intel386 architecture defines no flags; so this is 0.
34 00 # ELF header size (52 bytes)
20 00 # Program header size (32 bytes)
01 00 # Program header count
00 00 # e_shentsize
00 00 # e_shnum
00 00 # e_shstrndx
# Program header for ELF32 (32 bytes)
01 00 00 00 # Loadable program segment
00 00 00 00 # Offset of that segment
00 80 04 08 # p_vaddr 0x08048000
00 80 04 08 # p_paddr 0x08048000
5B 00 00 00 # file size (91 bytes)
5B 00 00 00 # memory size (same as file size)
05 00 00 00 # p_flags = readable and executable
00 10 00 00 # p_align = 4096 bytes
# _start (7 bytes)
B3 2B 31 C0 40 CD 80
I understand everything except the last 7 bytes, which are assembly instructions.
My question is what book should I use to learn to write 64-bit instructions in hexadecimal.
I plan to write these programs in hexadecimal for practice:
1. true
2. false
3. cat
4. pwd (just print string that's on 2nd stack slot, right?)
5. h2b (convert my hex format to binary)
6. b2h (and back)
7. hd (display hex in canonical format)
Maybe some more little ones. Then I'm going to take on writing an assembler, just complete enough to start expanding and improving itself.
Do you think this is a good plan?
Then I'll try making a linker and BASIC compiler in my own assembly.
Is this good for job opportunities? Will it be nice to see on GitHub?
>>60898481
You can convert the previous .hex file with this piece of shit script I wrote in 5 minutes but that worked since:#include <stdio.h>
static int skipComment(void) {
int c;
while ((c = getchar()) != 0x0A && c != EOF);
return c;
}
int main(void) {
//freopen(NULL, "wb", stdout);
int c, b, n = 0; // character, corresponding byte, scanned hex char count
while ((c = getchar()) != EOF) {
if (c == '#') {
c = skipComment();
if (c == EOF) return 0;
}
if (c >= '0' && c <= '9') {
if (n == 0) {
b = (c - '0') * 16;
n = 1;
fprintf(stderr, "%c", c);
} else {
b += (c - '0');
n = 0;
fprintf(stderr, "%c ", c);
putchar(b);
}
} else if (c >= 'A' && c <= 'F') {
if (n == 0) {
b = (c - 'A' + 10) * 16;
fprintf(stderr, "%c", c);
n = 1;
} else {
b += (c - 'A' + 10);
fprintf(stderr, "%c ", c);
n = 0;
putchar(b);
}
} else {
// ignore
}
}
fprintf(stderr, "\n");
return 0;
}
Also, general advice on becoming a better programming and filling GitHub portfolio for finding a job (I'm just starting out, almost dropped out of uni but managed to get one-year academic vacation because I skipped too many lessons because I didn't like what they're teaching (C#) but I think I'm mature enough now to take it the ass now).