Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
A call/return uses the stack, you should set one up first to prevent issues with that.
Also, do you use any image building program? They might overwrite parts of your bootsector with the information required for a FAT filesystem. Your first code snippet is short enough to fit before that table
Last edited by Combuster on Wed Feb 10, 2010 4:01 pm, edited 1 time in total.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
anything after main label doesn't work if there is jump. if i comment jump it still doesn't work because there is call. i tried to set stack segment and stack pointer but still doesn't work.
Combuster: i use bfi.exe for creating floppy image
Hobbes is right - your original code should have given you an error on your last line. Change dw aa55h to dw 0aa55h or dw 0xaa55. Also you should add a BPB table to the code as well along with a stack being properly set up.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Doesn't compile for me. Are you using FASM instead of the NASM mentioned in the subject?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
I know first post is confusing but I wrote that code here on the forum and I didn't realize that aa55h wouldn't work, I use 0xaa55 instead, there wasn't problem.
I have already fixed the issue. Problem was that I hadn't defined BPB table. Here's working program:
[bits 16]
[org 0]
jmp short CorrectRegisters
nop ;; I need to start bpb table at 0x03 so i need to step one adress
;; Here comes BPB table
welcome db "Welcome",0x0
main:
mov si,welcome
call PrintString
jmp $
;; Set all segments to 0x07C0 and set up stack pointer
CorrectRegisters:
mov ax,0x07C0
mov es,ax
mov ds,ax
mov ss,ax
mov sp,(0x07C0 - 16)
jmp short main
...
I doubt this does what you intended - it places the stack at 07C0:07B0 downward = 0x000083B0 - ~0x00007FB0 physical
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]