flat assembler
Message board for the users of flat assembler.

Index > Main > Problem executing code on boot diskette

Author
Thread Post new topic Reply to topic
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen
Hi, I'm making tests with boot diskettes but I don't understand something. If I execute the next code in a DOS window, everything works fine, but if I put the code on the diskette's boot sector, nothing happens.
This is the code:

format binary
;use16
;org 7C00h ;IT DOESN'T WORKS!!!!
;org 0100h ;IT DOESN'T WORKS EITHER!!!!

; Obtiene la hora del sistema.
; Devuelve:
; CH = hour (BCD)
; CL = minutes (BCD)
; DH = seconds (BCD)
clc ; Limpia el indicador CF
mov ah, 02h
int 1Ah
jc .error ; Salta en caso de error

; Imprime la hora
lea edx, [timemsg]
mov ah, 48
cmp ch, 9h
jle .L1 ; Verifica si la hora esta comprendida entre las
; 00 y las 09
cmp ch, 20h
jge .L2 ; Verifica si la hora esta comprendida entre las
; 20 y las 24

sub ch, 16
mov [edx], byte '1' ; La hora esta comprendida entre las 11 y las 19
jmp .printtime

.L1:
mov [edx], byte '0'
jmp .printtime

.L2:
mov [edx], byte '2'
sub ch, 32
jmp .printtime

.printtime:
xor ah, ch
mov [edx+1], ah
mov ah, 09h
int 21h ; Llama a la funcion del DOS que imprime la hora
; DS:DX

.end:
; Devuelve el control al DOS
mov ah, 4Ch
int 21h

.error:
mov ah, 09h
lea dx, [errmsg]
int 21h
jmp .end

errmsg db "An error occurs!$"
timemsg db "__:__:__$"
Post 21 Aug 2006, 00:42
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Have you noticed that you are using the DOS Int 21 services that are not available at boot time? You should check http://www.ctyme.com/intr/rb-0106.htm or http://www.ctyme.com/intr/rb-0210.htm . Check http://www.ctyme.com/intr/int-10.htm to see all the services that the BIOS provides for text and video handling.

Saludos!!
Post 21 Aug 2006, 01:25
View user's profile Send private message Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen
I've checked them out, but I didn't realize what you mention.

Thanks a lot, you clarified my mess.
Post 21 Aug 2006, 01:30
View user's profile Send private message Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen
It's not so clear now, if I build this code portion and write into a boot diskette, it doesn't work. Now I'm using Bios's INT 10 and if I test it on a DOS window it works, but it doesn't works on a boot diskette.
I'd thank any explanation, not just a solution code, I want to understand why this happens.

format binary
;use16
org 7C00h

; Int 10 - AH = 0Eh (VIDEO - TELETYPE OUTPUT)
; Escribe un caracter en la posicion del cursor
; actual y actualiza la posicion del cursor
; en AL esta el codigo del caracter a imprimir
call .printmsg

; Devuelve el control al DOS
mov ah, 4Ch
int 21h

.printmsg:
lea edx, [msg]
.start:
cmp [edx], byte 0
je .end
mov al, byte ptr edx
mov ah, 0Eh
int 10h
add edx, 1
jmp .start

.end:
ret

msg db "Hello world. Using Int 10h", 0
Post 21 Aug 2006, 09:04
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Code:
format binary
use16
org 7C00h

; Int 10 - AH = 0Eh (VIDEO - TELETYPE OUTPUT) 
; Escribe un caracter en la posicion del cursor 
; actual y actualiza la posicion del cursor 
; en AL esta el codigo del caracter a imprimir 

xor  ax, ax
push ax
pop  ds ; Importante porque sino estarias leyendo datos de cualquier parte y no desde 0:7c00h
push ax
pop  es
cli
mov  sp, 7c00h
mov  ss, ax
sti

call .printmsg

; Devuelve el control al DOS pero ahora mejor devolvasemoslo al BIOS
xor dx, dx ; tal vez no sea necesario
int 19h

.printmsg: 
lea edx, [msg] 
.start: 
cmp [edx], byte 0 
je .end 
mov al, byte ptr edx 
mov ah, 0Eh 
int 10h 
add edx, 1 
jmp .start 

.end: 
ret 

msg db "Hello world. Using Int 10h", 0    


Please the next time enclose the code with the tags [code] and [ /code] (without the space)

Note that the message "Hello world. Using Int 10h" will be repeated until you remove the floppy disk (because of the Int 19h call).
Post 21 Aug 2006, 14:45
View user's profile Send private message Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen
Thanks again. DS were missing.

PS: Sorry for the /untags
Post 21 Aug 2006, 19:20
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.