Re: LLVM discussion

@visualstudio, I do not recommend you make a compiler at all. For now, just have an interpreter. A compiler isn't actually needed yet. Wait until your very good with assembly language, machine language (I know, but its required to assemble a game into direct machine code without use of an already available assembler), or, if you are able to use assembly, find a good assembler (I recommend NASM), and then use that instead. Simply have your interpreter translate the game into assembly language and have NASM assemble it. Below, I have an example hello world program in NASM:
This is a Hello world program for the DOS operating system.
section .text
org 0x100; semicolons are comments and ignored. 0x100 is 256 in our decimal system.
    mov    ah, 0x9
    mov    dx, hello
    int    0x21

    mov    ax, 0x4c00
    int    0x21

section .data
hello:    db 'Hello, world!', 13, 10, '$'
An example of a similar program for Microsoft Windows:
global _main
extern _MessageBoxA@16
extern _ExitProcess@4

section code use32 class=code
_main:
    push    dword 0      ; UINT uType = MB_OK
    push    dword title  ; LPCSTR lpCaption
    push    dword banner ; LPCSTR lpText
    push    dword 0      ; HWND hWnd = NULL
    call    _MessageBoxA@16

    push    dword 0      ; UINT uExitCode
    call    _ExitProcess@4

section data use32 class=data
    banner:    db 'Hello, world!', 0
    title:    db 'Hello', 0
An equivalent program for Linux:
global _start

sectio n .text
_start:
    mov    eax, 4 ; write
    mov    ebx, 1 ; stdout
    mov    ecx, msg
    mov    edx, msg.len
    int    0x80   ; write(stdout, msg, strlen(msg));

    mov    eax, 1 ; exit
    mov    ebx, 0
    int    0x80   ; exit(0)

section .data
msg:    db    "Hello, world!", 10
.len:    equ    $ - msg
For X64 processors:
section .text
org 0x100
    mov    ah, 0x9
    mov    dx, hello
    int    0x21

    mov    ax, 0x4c00
    int    0x21

section .data
hello:    db 'Hello, world!', 13, 10, '$'
An example of a similar program for Microsoft Windows:
global _main
extern _MessageBoxA@16
extern _ExitProcess@4

section code use32 class=code
_main:
    push    dword 0      ; UINT uType = MB_OK
    push    dword title  ; LPCSTR lpCaption
    push    dword banner ; LPCSTR lpText
    push    dword 0      ; HWND hWnd = NULL
    call    _MessageBoxA@16

    push    dword 0      ; UINT uExitCode
    call    _ExitProcess@4

section data use32 class=data
    banner:    db 'Hello, world!', 0
    title:    db 'Hello', 0
An equivalent program for Linux:
global _start

section .text
_start:
    mov    rax, 4 ; write
    mov&nbs p;   rbx, 1 ; stdout
    mov    rcx, msg
    mov    rdx, msg.len
    int    0x80   ; write(stdout, msg, strlen(msg));

    mov    rax, 1 ; exit
    mov    rbx, 0
    int    0x80   ; exit(0)

section .data
msg:    db    "Hello, world!", 10
.len:    equ    $ - msg
I know, it looks complicated, but its actually quite easy. Of course, after the assembly is done, have the program link it with ld or some other linker. Do not try and design your own linker!

_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : visualstudio via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : stewie via Audiogames-reflector

Reply via email to