Einzelnen Beitrag anzeigen

NicoDE
(Gast)

n/a Beiträge
 
#49

Re: Maschinensprache

  Alt 20. Okt 2005, 12:27
Zitat von Neutral General:
Kennt nicht jemand zufällig den Hex-Wert den man eingeben muss damit das Programmn nicht direkt beendet wird ?
Sieh in der Dokumentation deines Prozessors und des verwendeten Betriebssystem nach (ersteres z.B. bei Intel, letzteres z.B. in Ralf Browns Interrupt-Liste).

Zitat von Neutral General:
2. Ich hab jetzt versucht 'hello world !' zu schreiben wenn ich aber das hex-Zeichen für '!' eingebe (21) passiert beim Aufruf der Exe-Datei unbeschreibliches
Du schreibst ein COM-Programm. EXE-Dateien haben noch einen/mehrere Header mit Informationen für das Ladeprogramm des Betriebssystems. Eine 16-Bit-EXE für MS-DOS könnte so aussehen (der Quellcodeauzug stammt aus meiner BiosHelp.pas):
Delphi-Quellcode:
const
  BlockSize = $1000;
type { ; RomDump (dumps memory to STDOUT)     }
  PRomDumpCode = ^TRomDumpCode; { ; Copyright (C) 2003 Nico Bendlin      }
  TRomDumpCode = packed record { ; (BlockSize MUST be multiple of 10h)  }
    head: TImageDosHeader; {                                        }
    note: array [0..$4F] of AnsiChar; { @@note: db      'RomDump', ...         }
    init: packed record { @@init:                                }
      x00050: array [0..2] of Byte; {         mov     ax, 4400h              }
      x00053: array [0..2] of Byte; {         mov     bx, 0001h              }
      x00056: array [0..1] of Byte; {         int     21h                    }
      x00058: array [0..1] of Byte; {         jc      @@code                 }
      x0005A: array [0..3] of Byte; {         and     dx, 0082h              }
      x0005E: array [0..3] of Byte; {         cmp     dx, 0082h              }
      x00062: array [0..1] of Byte; {         jne     @@code                 }
      x00064: Byte; {         push    cs                     }
      x00065: Byte; {         push    ds                     }
      x00066: array [0..2] of Byte; {         mov     dx, offset @@note      }
      x00069: array [0..1] of Byte; {         mov     ah, 09h                }
      x0006B: array [0..1] of Byte; {         int     21h                    }
      x0006D: array [0..2] of Byte; {         mov     ax, 4C01h              }
      x00070: array [0..1] of Byte; {         int     21h                    }
    end; {                                        }
    code: packed record { @@code:                                }
      x00072: Byte; BlockCount: Word; {         mov     cx, <BlockCount>       }
      x00075: Byte; DatSegment: Word; {         mov     dx, <DatSegment>       }
      x00078: array [0..1] of Byte; {         jcxz    @@last                 }
    end; {                                        }
    loop: packed record { @@loop:                                }
      x0007A: Byte; {         push    cx                     }
      x0007B: Byte; {         push    dx                     }
      x0007C: array [0..1] of Byte; {         mov     ds, dx                 }
      x0007E: Byte; DatOffset: Word; {         mov     dx, <DatOffset>        }
      x00081: array [0..2] of Byte; {         mov     cx, <BlockSize>        }
      x00084: array [0..2] of Byte; {         mov     bx, 0001h              }
      x00087: array [0..2] of Byte; {         mov     ax, 4000h              }
      x0008A: array [0..1] of Byte; {         int     21h                    }
      x0008C: Byte; {         pop     dx                     }
      x0008D: Byte; {         pop     cx                     }
      x0008E: array [0..1] of Byte; {         jc      @@exit                 }
      x00090: array [0..3] of Byte; {         add     dx, <BlockSize / 10h>  }
      x00094: array [0..1] of Byte; {         loop    @@loop                 }
    end; {                                        }
    last: packed record { @@last:                                }
      x00096: array [0..1] of Byte; {         mov     ds, dx                 }
      x00098: Byte; DatOffset: Word; {         mov     dx, <DatOffset>        }
      x0009B: Byte; LenghtMod: Word; {         mov     cx, <LenghtMod>        }
      x0009E: array [0..2] of Byte; {         mov     bx, 0001h              }
      x000A1: array [0..2] of Byte; {         mov     ax, 4000h              }
      x000A4: array [0..1] of Byte; {         jcxz    @@exit                 }
      x000A6: array [0..1] of Byte; {         int     21h                    }
      x000A8: array [0..1] of Byte; {         jc      @@exit                 }
      x000AA: array [0..1] of Byte; {         mov     al, 00h                }
    end; {                                        }
    exit: packed record { @@exit:                                }
      x000AC: array [0..1] of Byte; {         mov     ah, 4Ch                }
      x000AE: array [0..1] of Byte; {         int     21h                    }
    end; {                                        }
  end; {                                        }
const
  RomDumpCodeSize = SizeOf(TRomDumpCode) - SizeOf(TImageDosHeader);
  RomDumpCode: TRomDumpCode = (
    head: (
      e_magic : IMAGE_DOS_SIGNATURE;
      e_cblp : Word(RomDumpCodeSize) and $1FF;
      e_cp : Word((RomDumpCodeSize - 1) shr 9) + 1;
      e_crlc : $0000;
      e_cparhdr : SizeOf(TImageDosHeader) shr 4;
      e_minalloc: $0000;
      e_maxalloc: $FFFF;
      e_ss : $0000;
      e_sp : $1000;
      e_csum : $0000;
      e_ip : SizeOf(RomDumpCode.note);
      e_cs : $0000;
      e_lfarlc : SizeOf(TImageDosHeader);
      e_ovno : $0000;
      e_res : ($0000, $0000, $0000, $0000);
      e_oemid : $0000;
      e_oeminfo : $0000;
      e_res2 : (
        $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000, $0000);
      _lfanew : $00000000
    );
    note: #13#10'RomDump 2.2'#13#10 +
      'Copyright (C) 2003 Nico Bendlin'#13#10#13#10 +
      'Usage: RomDump > filename'#13#10#13#10'$';
    init: (
      x00050: ($B8, $00, $44);
      x00053: ($BB, $01, $00);
      x00056: ($CD, $21);
      x00058: ($72, $18);
      x0005A: ($81, $E2, $82, $00);
      x0005E: ($81, $FA, $82, $00);
      x00062: ($75, $0E);
      x00064: $0E;
      x00065: $1F;
      x00066: ($BA, $00, $00);
      x00069: ($B4, $09);
      x0006B: ($CD, $21);
      x0006D: ($B8, $01, $4C);
      x00070: ($CD, $21);
    );
    code: (
      x00072: $B9; BlockCount: $0020;
      x00075: $BA; DatSegment: $E000;
      x00078: ($E3, $1C)
    );
    loop: (
      x0007A: $51;
      x0007B: $52;
      x0007C: ($8E, $DA);
      x0007E: $BA; DatOffset: $0000;
      x00081: ($B9, Lo(BlockSize), Hi(BlockSize));
      x00084: ($BB, $01, $00);
      x00087: ($B8, $00, $40);
      x0008A: ($CD, $21);
      x0008C: $5A;
      x0008D: $59;
      x0008E: ($72, $1C);
      x00090: ($81, $C2, Lo(BlockSize shr 4), Hi(BlockSize shr 4));
      x00094: ($E2, $E4)
    );
    last: (
      x00096: ($8E, $DA);
      x00098: $BA; DatOffset: $0000;
      x0009B: $B9; LenghtMod: $0000;
      x0009E: ($BB, $01, $00);
      x000A1: ($B8, $00, $40);
      x000A4: ($E3, $06);
      x000A6: ($CD, $21);
      x000A8: ($72, $02);
      x000AA: ($B0, $00)
    );
    exit: (
      x000AC: ($B4, $4C);
      x000AE: ($CD, $21)
    )
  );
  Mit Zitat antworten Zitat