flat assembler
Message board for the users of flat assembler.

Index > OS Construction > is something wrong with my PrintString: (16bit and bios)

Author
Thread Post new topic Reply to topic
hckr83



Joined: 12 Nov 2006
Posts: 86
Location: usa
hckr83 09 Dec 2006, 18:36
I'm writing an OS to test my emulator I'm making(currently very limited for opcodes and devices)

My code may look a bit wierd to get around my limitation of opcodes but anyway..
Code:
mov ax,ds
mov es,ax
mov si,my_string ;point it to my string
call PrintString

nop
hlt

my_string db 'h','i',0

PrintString: ;PrintString --es:si points to the string
mov ax,es
push ds ;I don't have segment overrides so..
mov ds,ax
;set it up for bios int 10h, ah=0Ah
mov ah,0x0A
mov bx,0
mov bp,0
print_loop:
mov al,[si+bp]
sub al,0 ;eventually replace with cmp
jz print_done ;if it is the end of a null terminated string then stop
mov cx,1
int 0x10
;temp only!
push ax  ;save ax
mov ax,bp ;we just add 1 to bp
add ax,1
mov bp,ax
pop ax
jmp print_loop ;do loop

print_done:
pop ds
ret
    


also I'm sure that every opcode in that code works right

_________________
x86 CPU Emulation library: http://sourceforge.net/projects/x86lib
Post 09 Dec 2006, 18:36
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 09 Dec 2006, 19:37
hckr83, is that all of your OS code? If it is then you're forgetting three things:

  • Start the program at offset 0x7C00 using "org 0x7C00"
  • At the end of the program put "times 510-($-$$) db 0" to fill up the rest of the sector with zeros.
  • After you do the thing listed right above put "dw 0xAA55" which is a word value which tells the BIOS that the sector you were just working in is the boot sector.


If that isn't your problem, did you put anything into ax before you started putting the the value in it into the data segment and extra segment?
Post 09 Dec 2006, 19:37
View user's profile Send private message Reply with quote
hckr83



Joined: 12 Nov 2006
Posts: 86
Location: usa
hckr83 09 Dec 2006, 19:43
Quote:
# Start the program at offset 0x7C00 using "org 0x7C00"
# At the end of the program put "times 510-($-$$) db 0" to fill up the rest of the sector with zeros.
# After you do the thing listed right above put "dw 0xAA55" which is a word value which tells the BIOS that the sector you were just working in is the boot sector.

I already did the "equivalent" to that(I don't have fdd support yet so I just load it straight into memory)

Quote:
If that isn't your problem, did you put anything into ax before you started putting the the value in it into the data segment and extra segment?

I didn't completely understand what you just said but I AX doesn't have any special data in it, at the first part I use it to mov ES to DS
Post 09 Dec 2006, 19:43
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat 09 Dec 2006, 19:58
You should still make sure it contains zero before you do. Just either "mov ax, 0" or "xor ax, ax".
Post 09 Dec 2006, 19:58
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.