flat assembler
Message board for the users of flat assembler.

Index > OS Construction > 16 bit os...

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I have been working on this for over five hours... I'm trying to get my code to load to the exectuable at 0600h indirectly, like an actual OS would... but it doesn't want to work... Can someone please look at this... I'm not sure whether or not [bx] means the value of bx or the mem addr of it... Thanks...

Code:
use16
org 0x7C00
jmp Start

;DATA
msg db "Hello World!", 13, 10, 0 ;13 = Carriage Return, 10 = New Line, 0 = End of String
err db "Error!", 13, 10, 0
hur db "Hurrah!", 13, 10, 0
buffer db 0

Sectors db 1


Start:
        mov si, msg
        call PrintFunction
        ;call ConsoleFunction ;Reserved for later use
        mov ax, 0000h
        mov es, ax
        mov bx, 0060h
        mov ah, 02h
        mov al, [Sectors] ;Sectors to be read
        mov ch, 0
        mov cl, 2
        mov dh, 0
        int 13h
        jmp ReadFileStart

Hang:
        jmp Hang

ReadFileStart:
        cmp bx, 0xFD00
        je GotoFile
        inc bx
        jmp ReadFileStart

GotoFile:
        inc bx
        shl bx, 1
        add bx, 0000h
        jmp bx

;CONSOLE RESERVED FOR LATER USE
;ConsoleFunction:
;        mov ah, 00h
;        int 0x16
;        mov bp, buffer
;        ;cmp ah, 0x1C
;        ;je Check
;        cmp ah, 0x01
;        je Done
;
;        mov ah, 0x0E
;        int 0x10
;        mov [bp], al
;        inc bp
;        jmp ConsoleFunction

PrintFunction:
        lodsb
        cmp al, 0
        je Done
        mov ah, 0x0E
        int 0x10
        jmp PrintFunction

Done:
        ret

;Fill in emptyness with X's
times 510-($-$$) db 'X'
dw 0xAA55

org 0600h

FHeader db "SOS1","Hello World", 0, 0xFC, "prg", 0, 0xFD
FData:
        jmp ProgStart
        HelloMsg db "Hello world from Small 16-bit OS!", 13, 10, 0
        ProgStart:
                mov si, HelloMsg
                call PrintFunction
;FEnd db "FEND"
times 512-($-$$) db 'X'
    
Post 08 Dec 2006, 03:05
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach
the [] thing can be tricky. for a normal variable the name give you the var address, and [] will give you it's contents. for a register bx will give you the content while [bx] give you the content from the address in bx. since registers don't have addresses it's a bit diffrent.
Post 08 Dec 2006, 10:16
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks
Post 08 Dec 2006, 12:47
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I tried something in a hex editor I use (Icy Hexplorer - pretty nice one for free, might I add), I looked up the jmp command in GotoFile, and it jumps to some odd area in memory where there's an X at. So then I tried to comment out GotoFile all together, as well as the contents of ReadFileStart, and put inside of it "jmp FData", and instead of printing the string like it should it reprints the "Hello World!" message (msg) three times.
Post 09 Dec 2006, 19:14
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Does anyone know what it could be doing wrong?
Post 09 Dec 2006, 22:50
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
If I'm reading your code right then

1) You load the next sectors to es:bx = 0x0000:0x0060 not 0x0000:0x0600

mov bx, 0060h => mov bx,0x0600

or

mov ax,0x0060
mov es,ax
mov bx,0x0000 ; xor bx,bx

2) It loops until the value of bx is 0xFD00, not the value pointed to by bx, it should also be byte not word:

cmp bx,0xFD00 => cmp byte [bx],0xFD

HTH
Post 10 Dec 2006, 20:55
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
You... Are... AWESOME! Very HappyVery HappyVery HappyVery HappyVery Happy THANK YOU!!!! This thing's had me stumped for the past weekend! I was doing the segment:offset thing wrong (backwards) when I was calculating the get the absolute address.
Post 11 Dec 2006, 03:43
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
hehe I've done it so many times myself it's almost second nature to correct now Laughing
Post 11 Dec 2006, 13:27
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
For me it's just something else I'm getting used to. Smile Is the BX register set apart from the other general registers in the sense that it can act as a pointer?
Post 11 Dec 2006, 16:13
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
no. you can use any general register (ax bx cx dx si di bp sp (in 16bit)) as a pointer to a value at the address of the register

e.g.

mov byte [ax],0xFF

or more complex code up to 2 general purpose registers, 1 allowed to have a multiplier, and a constant value:

e.g.

mov byte [di+4*cx+2],dl

This moves the byte value in dl to the address pointed to by di + (4 × cx) + 2. This is useful if di points to the destination of a block of data and your using cx as the loop counter for some algorithm, the constant allows you to adjust as necessary.
Post 11 Dec 2006, 17:45
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
Post 11 Dec 2006, 18:04
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thank you all for clarifying that!
Post 15 Dec 2006, 03:44
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.