Evan McAfee
Evan McAfee

Reputation: 1

Assembly and C project loop

I am trying to get my C program to run on a computer with no operating system. I have a version of an MBR that just prints a (!), but when i try to add code to run my C program, as shown here the machine just reboots infinitely.

I only just got the assembly to compile because i took out some definitions and just put the numbers where it says //here Here is my code: `

[org 0x7c00]                        


mov [BOOT_DISK], dl                 



CODE_SEG equ GDT_code - GDT_start
DATA_SEG equ GDT_data - GDT_start

cli
lgdt [GDT_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp CODE_SEG:start_protected_mode

jmp $
                                    
                                     
GDT_start:                          
    GDT_null:
        dd 0x0
        dd 0x0

    GDT_code:
        dw 0xffff
        dw 0x0
        db 0x0
        db 0b10011010
        db 0b11001111
        db 0x0

    GDT_data:
        dw 0xffff
        dw 0x0
        db 0x0
        db 0b10010010
        db 0b11001111
        db 0x0

GDT_end:

GDT_descriptor:
    dw GDT_end - GDT_start - 1
    dd GDT_start

[bits 32]
start_protected_mode:


    mov al, '!'
    mov ah, 0x0f
    mov [0xb8000], ax

    ;open the file for reading
   mov eax, 5
file_name db 'e.exe'

   mov ebx, file_name
   mov ecx, 0             ;for read only access
   mov edx, 0777          ;read, write and execute by all
   int  0x80
    

    
   ;read from file
   mov eax, 3
   mov ebx, 1  //here
   mov ecx, 26 //here
   mov edx, 26 //here
   int 0x80

    jmp $


BOOT_DISK: db 0                                    

times 510-($-$$) db 0              
dw 0xaa55

`

Upvotes: 0

Views: 71

Answers (0)

Related Questions