Code: Select all
mov si, msg
call print_string
hang:
jmp hang
print_string:
lodsb
cmp al, 0
je print
ret
print:
mov ah, 0x09
int 0x10
jmp print_string
msg db 'Welcome to OS', 0
times 510-($-$$) db 0
dw 0xAA55
Code: Select all
mov si, msg
call print_string
hang:
jmp hang
print_string:
lodsb
cmp al, 0
je print
ret
print:
mov ah, 0x09
int 0x10
jmp print_string
msg db 'Welcome to OS', 0
times 510-($-$$) db 0
dw 0xAA55
Code: Select all
cmp al,0
je print
Code: Select all
cmp al,0
jne print
Code: Select all
ORG 0x7C00
BITS 16
jmp 0x0:start
start:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0x7C00
sti
mov si, msg
call print_string
cli
hlt
print_string:
lodsb
test al, al
jnz print
ret
print:
mov ah, 0xE
int 0x10
jmp print_string
msg db 'Welcome to OS', 0
times 510-($-$$) db 0
dw 0xAA55
Some emulators stop updating the screen if you do that, and you may not see the printed message at all. You'd better try this:Rudster816 wrote:Code: Select all
cli hlt
Code: Select all
here:
hlt
jmp here
Code: Select all
CLI
JMP $
Code: Select all
bits 16
org 0x7C00
SECTION .text
jmp begin
begin:
jmp setup_stack
setup_stack:
mov esp, stack_end
jmp next
next:
mov si, msg
call print_string
cli
jmp $
print_string:
lodsb
cmp al, 0
jne print
ret
print:
mov ah, 0x09
int 0x10
jmp print_string
SECTION .bss
msg db 'Welcome to OS', 0
stack_begin:
resb 4096
stack_end:
times 510-($-$$) db 0
dw 0xAA55
You failed to take a lot of my advice, and your code is far worse then what you had to begin with. I'll do a rundown the problems (there's a lot)...ghostlyfoot wrote:This is what I managed to put together based on the wiki and your advice:
-SNIP-
It gives me many, many, many warnings when i assemble it, though. What is the problem?
NASM interprets .text meaning everything from the org offset until the .data section, .data meaning everything from there until the end of the binary, and .bss meaning locations in memory after the end of the binary. So, as misused as they are, they're still kind of correct.Rudster816 wrote:4. You need to create a flat binary, there are no .bss or .text sections
True, interrupts should be enabled. The HLT is not really necessary (JMP $ is just fine) but it reduces power consumption (on real hardware).Combuster wrote:Which doesn't fix the problem at all if interrupts are already off.
It also reduces cpu usage of your emulator, on emulated hardwareHobbes wrote:True, interrupts should be enabled. The HLT is not really necessary (JMP $ is just fine) but it reduces power consumption (on real hardware).Combuster wrote:Which doesn't fix the problem at all if interrupts are already off.
Code: Select all
bits 16 ; 16 bit REAL MODE
org 0x07C00 ; originates at 0x07C00
jmp 0x0:start ; jump to starting point at 0x0 offset start
start: ; starting point
; setup segments
cli ; disable interrupts
xor ax, ax ; make ax 0
mov ds, ax ; make ds 0
mov es, ax ; make es 0
mov fs, ax ; make fs 0
mov gs, ax ; make gs 0
mov ss, ax ; make ss 0
mov sp, 0x7C00 ; tell bios where the stack is?
sti ; enable interrupts
mov si, msg ; move our message into si
call print_string ; let's print
cli ; disable interrupts so nothing 'interrupts' our hang
jmp $ ; keep jumping to this line
print_string: ; will print a string in si
lodsb ; get si and put it in al
cmp al, 0 ; is al null?
jne print ; if it isn't, jmp to print
ret ; return to calling method
print: ; called by print_string
mov ah, 0xE ; tell bios we want to print
int 0x10 ; PRINT!
jmp print_string ; loop
msg db 'Welcome to OS', 0 ; make a message and name it 'msg'
times 510-($-$$) db 0 ; fill with 0s
dw 0xAA55 ; siggy
Of course, you could also just use something like:berkus wrote:Imagine an unattended PC crashing, setting its power consumption to the maximum (CPU full speed etc), and then staying in this condition until a human technician checks it. Maybe weeks.Combuster wrote:Well what matters more after a crash, debug info or a lower power consumption?
Code: Select all
#ifndef NDEBUG
jmp $
#else
hlt
#endif