flat assembler
Message board for the users of flat assembler.

Index > OS Construction > some more code that won't work

Author
Thread Post new topic Reply to topic
jatos



Joined: 04 Nov 2006
Posts: 20
jatos 05 Oct 2007, 12:26
Hi

I got some more code that fails to work correctly. This code worked when it was 16 bit code, and I now I have converted it to 32bit code it doesn't work

Code:
org 0x1600
use32

app_start:

func_set_registers:
        MOV ax, 0xB800
        MOV es, ax
        LEA ebp, [msg_1]
        MOV si, 0
               MOV ax, 0x0000
              MOV ds, ax
        MOV ebx, 0x0000
        MOV ax, 0x0000
        MOV cx, 0

func_print_string:
        MOV al, [ds:ebp]
        CMP al, 0
        JE app_end
        MOV [es:ebx], al    

        INC ebp
        ADD ebx, 2
        JMP func_print_string

jmp app_end

app_data:

        msg_1 db "Hello World!", 0 

app_end:
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        jmp app_end
    


I can't actually see anything wrong with the program. the boot loader is loading the code at 1600h (its the fat 12 boot level downloaded http://flatassembler.net/examples.php).

While I am it: is there anything it might be advisable for me to read, apart from the IA-32 dev manuals, which I have already read.

_________________
Jamie
Post 05 Oct 2007, 12:26
View user's profile Send private message Reply with quote
Artlav



Joined: 23 Dec 2004
Posts: 188
Location: Moscow, Russia
Artlav 05 Oct 2007, 13:37
My best guess is that 32bit code requires 32bit (protected) mode, while you run it in 16bit (real) mode.
use32 makes fasm compile it as 32bit code, yet the CPU still decode it as 16bit code, so that's what is being run:
Code:
app_start:

func_set_registers: 
mov      eax,0xc08eb800
lea   bp,[ds:di]
push  ss
add       [ds:bx+si],al
mov        esi,0xb8660000
add   [ds:bx+si],al
mov        ds,ax
mov    bx,0x0000
add        [ds:bx+si],al
mov        eax,0xb9660000
add   [ds:bx+si],al

func_print_string:
mov  al,[ds:di]
cmp   al,0
je      app_end
mov  [es:bp+di],al
inc        bp
add       bx,2
jmp     func_print_string

;...

app_end:
    


I can advice you to read some assembler programming tutorials, along with making sense of some examples. You can't learn it by reading dev manuals - it will be like learning foreign language by reading it's dictionary.
Post 05 Oct 2007, 13:37
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 05 Oct 2007, 16:28
In pmode you would use something like this:
Code:
org 0x1600use32app_start:func_set_registers:        mov esi,msg_1            mov edi,0xB8000        mov ah,' 'func_print_string:        mov al, byte[ds:esi]        cmp al,0        JE app_end        mov word[es:edi],ax            inc esi        add edi,2        JMP func_print_stringjmp app_endapp_data:        msg_1 db "Hello World!", 0 app_end:        NOP        NOP        NOP        NOP        NOP        NOP        NOP        NOP        NOP        NOP        jmp app_end    


The above code assumes data descriptor are 0 based.

You should also look up lodsb and stosw etc.
Post 05 Oct 2007, 16:28
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.