[SOLVED]Problems with reading sectors from floppy

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.
Post Reply
sumanx
Posts: 9
Joined: Wed Feb 01, 2012 9:17 am

[SOLVED]Problems with reading sectors from floppy

Post by sumanx »

Hi, I have just joined the forum, and I think you guys are doing to a great job!!

I am having a problem with reading sectors from floppy. I am creating a virtual floppy image using dd and testing it on Linux, using VirtualBox.

Here is the code:

boot.asm

Code: Select all

[org 0x7C00]
[bits 16]

jmp start
%include "print.inc" ;has the print function


start:
mov ax,0x1000 ;Location in memory to jump to
mov es,ax ;move to es
xor ax,ax ;zero out ax

mov ah,2 ;Bios Function No
mov al,1 ;No. of Sectors
mov ch,1 ;Track to read
mov cl,2 ;Sector to read
mov dh,1 ;Head to read
mov dl,0 ;Drive to read
int 0x13 
jc start ;If there was a problem, go back to the beginning

jmp 0x1000:0x0000 ; jump to the memory location


Hello db "Hello",0 ;message to print



TIMES 510-($-$$) db 0
DW 0x55AA


kernel.asm

Code: Select all

jmp _start

%include "print.inc"

_start:
mov si,_Hello
call print

cli
hlt

_Hello db "Hello from the kernel",0

cli 
hlt

TIMES 512-($-$$) db 0
I assemble and make an image using:

Code: Select all

nasm kernel.asm -f bin -o kernel.bin
nasm boot.asm -f bin -o boot.bin
dd if=boot.bin of=image.img conv=notrunc status=noxfer seek=0
dd if=kernel.bin of=image.img seek=1 conv=notrunc status=noxfer 
but it doesn't work. All I get is a cursor at the top left of the screen, but I do not get the message 'Hello'.
Can someone please explain what I am doing wrong?

Edit: I figured out the solution. Check the third post.
Last edited by sumanx on Sun Feb 05, 2012 3:08 am, edited 1 time in total.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Problems with reading sectors from floppy

Post by Chandra »

Lots of issues. You didn't setup the segment registers neither did you setup the stack pointer. Furthermore, use a far jump at the begining of your code to make sure CS:IP is set up correctly. To start with the basics, check out the wiki.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
sumanx
Posts: 9
Joined: Wed Feb 01, 2012 9:17 am

[SOLVED]Problems with reading sectors from floppy

Post by sumanx »

I finally got the solution to the problem, which was that dh and ch had to be 0.
Thanks anyway
Post Reply