Author Topic: creating a floppy  (Read 16864 times)

shawn marks

  • Guest
creating a floppy
« on: October 05, 2009, 01:37:04 PM »
Ok so i have this mbr.asm that just prints a message now the problem that i am running into is that i have to jump to memory location 0x1000 execute some code and then jump back to the mbr and print a $ but have no clue how to do it this is what mbr looks like now:

org 0x7c00
xor ax,ax
mov es,ax
mov ah,0
mov al,3
int 10h

mov ah,13h
mov al,1
mov bh,0
mov bl,0ah
mov cx,mlen
mov dh,0
mov dl,0
mov bp, msg
int 10h

;jump to 0x1000 here??????
;print '$' here

mov dh,1
msg db "This is a message"
mlen equ $-msg
times 512-($-$$)-2 db 0
dw 0AA55h

Debbie Wiles

  • Guest
Re: creating a floppy
« Reply #1 on: October 05, 2009, 04:45:22 PM »
First thing you need to tdo in yor boot sector is toset up your segment registers. Something like:

jmp 0:.1
.1

should do that for CS. This is because, although the boot sector is loaded at physicaladdress 0x7C00, that could be 0x7C0:0 or it could be 0:0x7C00 (and some BIOS could even set it some other way).

Then you need to know where in your boot sector you need to jump back to, so the other code can jump back to the correct place. Alternatively, you could CALL the code you want to execute, and the system will set things up correctly for when you RET back to it.

If it helps, my boot sector can be found at http://www.ukcpu.net/Programming/OS/bootsect.asm

It doe not execute code in the way you want, but will show you how to correctlyset up the segment registers.

It's amazing what you can do with just 512 bytes to work with. When I was testing it, I had it load and display a text file that was over 100 KB in size and fragmented all over the disk :)

Debbie Wiles

  • Guest
Re: creating a floppy
« Reply #2 on: October 05, 2009, 04:46:50 PM »
Oops, sourceforge removed a line break. The small piece of code should haveread:

jmp 0:.1

.1

shawn marks

  • Guest
Re: creating a floppy
« Reply #3 on: October 05, 2009, 05:00:10 PM »
debs basically i have two files here the first one is the boot sector and the second one is just to print the date and time the date and time sits at 0x1000 is the address that it needs to sit at so if i do the call and ret like so i have the mbr as follows:

org 0x7c00
xor ax,ax
mov es,ax
mov ah,0
mov al,3
int 10h

mov ah,13h
mov al,1
mov bh,0
mov bl,0ah
mov cx,mlen
mov dh,0
mov dl,0
mov bp, msg
int 10h

call 100h

mov dh,1
msg db "Print Message"
mlen equ $-msg
times 512-($-$$)-2 db 0
dw 0AA55h

and then i have the following for the datetime.asm

[BITS 16]               ;Set code generation to 16 bit mode

[org 100h]      ;set addressing to begin at 100H

start:
call cls   ;call routine to clear screen
call dspmsg   ;call routine to display message

call date
call cvtmo
call cvtday
call cvtcent
call cvtyear
call dspdate

call time
call cvthrs
call cvtmin
call cvtsec
call dsptime

int 20h ;halt operation (VERY IMPORTANT!!!)

ret

cls:
mov ah,06h   ;function 06h (Scroll Screen)
mov al,0   ;scroll all lines
mov bh,1FH   ;Attribute (bright white on blue)
mov ch,0   ;Upper left row is zero
mov cl,0   ;Upper left column is zero
mov dh,24   ;Lower left row is 24
mov dl,79   ;Lower left column is 79
int 10H   ;BIOS Interrupt 10h (video services)
ret


dspmsg:
mov ah,13h   ;function 13h (Display String)
mov al,0   ;Write mode is zero
mov bh,0   ;Use video page of zero
mov bl,0fh   ;Attribute (bright white on bright blue)
mov cx,8   ;Character string is 25 long
mov dh,3   ;position on row 3
mov dl,0   ;and column 28
push ds      ;put ds register on stack
pop es      ;pop it into es register
lea bp,[msg]   ;load the offset address of string into BP
int 10H
ret

msg: db 'My name :D'

date:
;Get date from the system
mov ah,04h   ;function 04h (get RTC date)
int 1Ah      ;BIOS Interrupt 1Ah (Read Real Time Clock)
ret

;CH - Century
;CL - Year
;DH - Month
;DL - Day

cvtmo:
;Converts the system date from BCD to ASCII
mov bh,dh ;copy contents of month (dh) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [dtfld],bh
mov bh,dh
and bh,0fh
add bh,30h
mov [dtfld + 1],bh
ret

cvtday:
mov bh,dl ;copy contents of day (dl) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [dtfld + 3],bh
mov bh,dl
and bh,0fh
add bh,30h
mov [dtfld + 4],bh
ret

cvtcent:
mov bh,ch ;copy contents of century (ch) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [dtfld + 6],bh
mov bh,ch
and bh,0fh
add bh,30h
mov [dtfld + 7],bh
ret

cvtyear:
mov bh,cl ;copy contents of year (cl) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [dtfld + 8],bh
mov bh,cl
and bh,0fh
add bh,30h
mov [dtfld + 9],bh
ret

dtfld: db '00/00/0000'

dspdate:
;Display the system date
mov ah,13h ;function 13h (Display String)
mov al,0 ;Write mode is zero
mov bh,0 ;Use video page of zero
mov bl,0Fh ;Attribute
mov cx,10 ;Character string is 10 long
mov dh,4 ;position on row 4
mov dl,0 ;and column 28
push ds ;put ds register on stack
pop es ;pop it into es register
lea bp,[dtfld] ;load the offset address of string into BP
int 10H
ret

time:
;Get time from the system
mov ah,02h
int 1Ah
ret

;CH - Hours
;CL - Minutes
;DH - Seconds

cvthrs:
;Converts the system time from BCD to ASCII
mov bh,ch ;copy contents of hours (ch) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [tmfld],bh
mov bh,ch
and bh,0fh
add bh,30h
mov [tmfld + 1],bh
ret

cvtmin:
mov bh,cl ;copy contents of minutes (cl) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [tmfld + 3],bh
mov bh,cl
and bh,0fh
add bh,30h
mov [tmfld + 4],bh
ret

cvtsec:
mov bh,dh ;copy contents of seconds (dh) to bh
shr bh,1
shr bh,1
shr bh,1
shr bh,1
add bh,30h ;add 30h to convert to ascii
mov [tmfld + 6],bh
mov bh,dh
and bh,0fh
add bh,30h
mov [tmfld + 7],bh
ret

tmfld: db '00:00:00'

dsptime:
;Display the system time
mov ah,13h ;function 13h (Display String)
mov al,0 ;Write mode is zero
mov bh,0 ;Use video page of zero
mov bl,0Fh ;Attribute
mov cx,8 ;Character string is 8 long
mov dh,5 ;position on row 5
mov dl,0 ;and column 28
push ds ;put ds register on stack
pop es ;pop it into es register
lea bp,[tmfld] ;load the offset address of string into BP
int 10H
ret

int 20H


all i need it to do is jump to the 0x1000 and then jump back to the mbr and print like a $ character that's it the printing i know how to do it's just the rest i do not