flat assembler
Message board for the users of flat assembler.
![]() Goto page Previous 1, 2 |
Author |
|
macomics 21 Aug 2022, 22:47
While you are in real mode, the value in ds and es is entered according to the upper 16 bits of the address for accessing the required data (ds) or writing data (es)
To manually copy a string to a segment of color text memory, you do this: Code: push cs mov ax, $B800 pop ds mov es, ax mov cx, str0_bytes mov si, str0 xor di, di mov ah, 15 ; WHITE_TEXT_ON_BLACK @@: ; [ds:si] = str0[i] lods byte [si] ; al = [ds:si]; si += 1 ; [es:di] = color_text_screen[page = 0][row = 0][col = i] stos word [di] ; [es:di] = ax; di += 2 loop @b jmp $ str0 db 'Test string' str0_bytes = $ - str0 |
|||
![]() |
|
macomics 21 Aug 2022, 22:57
That is, I want to tell you that the address is determined by two components SEG * 16 + OFF. Where SEG is one of the segment registers (CS, DS, ES, FS, GS, SS), and OFF can be either an immediate value (IMM) within 64 kb or one or more of the base and index registers (BX, BP, SI, DI, BX+SI, BX+DI, BP+SI, BP+DI, BX+IMM, BP+IMM, BX+SI+IMM, BX+DI+IMM, BP+SI+IMM, BP+DI+IMM, SI+IMM, DI+IMM). I think I've listed everything.
Code: $00000 - $003FF ; Real IDT $00400 - $005FF ; BIOS_vars $00600 - $00FFF ; empty $01000 - $811FF ; TEST.APP (CS = DS = $0100 range [$01000 .. $10FFF], SI = str0 -> DS:SI = $01017; IP = $0000 -> CS:IP = $01000) $81200 - $97FFF ; empty $98000 - $9FBFF ; stack segment (SS = $9800 range [$98000 .. $A7FFF], SP = $7BFE -> SS:SP = $9FBFE) $9FC00 - $9FFFF ; ExtBIOS_vars if exists $A0000 - $AFFFF ; Video segment $B0000 - $B7FFF ; Mono text segment $B8000 - $BFFFF ; Color text segment (ES = $B800 range [$B8000 .. $C7FFF], DI = $0000 -> ES:DI = $B8000) $C0000 - $CFFFF ; Video BIOS $D0000 - $EFFFF ; Other ROM or Extended memory $F0000 - $FFFFF ; Main BIOS |
|||
![]() |
|
retro 21 Aug 2022, 23:44
still confused... i dunno if i should post my boot loader and test program code here, 'cos that way i'd be kinda cheating and not reasoning a bit... to be honest, i think not even i fully understood my own code lol
|
|||
![]() |
|
macomics 21 Aug 2022, 23:48
Better publish it. This way it will at least become clear where you made the mistake. And not guessing by coming up with suitable examples.
|
|||
![]() |
|
retro 21 Aug 2022, 23:57
yeah, here's boot.asm again, this time on very weak steroids:
Code: format binary as "img" use16 org $7c00 mov ah,$0e mov bx,welcome printmsg: mov al,[bx] int $10 inc bx cmp al,$0d jne printmsg xor ax,ax mov es,ax mov ds,ax mov bp,$a000 mov sp,bp mov bx,$7e00 mov ah,$02 mov al,$01 mov ch,$00 mov cl,$01 mov dh,$00 mov dl,$01 int $13 mov bp,$8000 exec: mov al,[bx] mov [bp],al inc bp inc bx cmp bx,$8000 jne exec jmp $ welcome db "Welcome to the Aaron loader! Loading floppy...",$0a,$0d times 510-($-$$) db $00 db $55,$aa and here's test.asm, the test program for boot.asm: Code: format binary as "img" use16 mov ah,$0e mov al,'a' int $10 times 512-($-$$) db $00 i wasn't sure about which ram location to use for the test program, i thought using $7c00 would work 'cos that's the origin of the bootloader and it can only be executed starting from this address, but that'd overwrite the bootloader, so i decided to use $7c00 for the loader, $7e00 for reading test.img, and $8000 for writing. |
|||
![]() |
|
macomics 22 Aug 2022, 00:11
retro wrote:
Code: $00000 - $003FF ; Real IDT $00400 - $005FF ; BIOS_vars $00600 - $07BFF ; empty (29,5 kb) $07C00 - $07DFF ; Boot sector $07E00 - $07FFF ; Sector 1 (after int $13) $08000 - $081FF ; Sector 1 (test.asm) $08200 - $09FFF ; stack segment (7,5 kb) $0A000 - $9FBFF ; empty (599 kb) $9FC00 - $9FFFF ; ExtBIOS_vars if exists $A0000 - $AFFFF ; Video segment $B0000 - $B7FFF ; Mono text segment $B8000 - $BFFFF ; Color text segment $C0000 - $CFFFF ; Video BIOS $D0000 - $EFFFF ; Other ROM or Extended memory $F0000 - $FFFFF ; Main BIOS |
|||
![]() |
|
retro 22 Aug 2022, 00:30
by the way, have you ever had that feeling you feel after thinking of everything, except the most obvious one? well, i just discovered i can just slap a "jmp $7e00" inside exec, so the test program gets executed...
|
|||
![]() |
|
macomics 22 Aug 2022, 00:38
That's why I make up memory maps
|
|||
![]() |
|
retro 22 Aug 2022, 00:41
yeah, i should make memory maps too. how do you do them? is it actually made by an app or you just calculate everything?
|
|||
![]() |
|
macomics 22 Aug 2022, 00:51
I calculate everything manually. It's not that complicated. There is a set of blocks that are initially present due to the BIOS. The remaining blocks are calculated quickly and should be located in free space.
Before loading: Code: $00000 - $003FF ; Real IDT $00400 - $005FF ; BIOS_vars $00600 - $07BFF ; stack segment (29,5 kb) $07C00 - $9FBFF ; empty (608 kb) $9FC00 - $9FFFF ; ExtBIOS_vars, if exists (1 - 4 kb) * $A0000 - $AFFFF ; Video segment $B0000 - $B7FFF ; Mono text segment $B8000 - $BFFFF ; Color text segment $C0000 - $CFFFF ; Video BIOS $D0000 - $EFFFF ; Other ROM or Extended memory $F0000 - $FFFFF ; Main BIOS Although I have defined a stack segment, this does not mean that it will be in this place. But often it is located right here. In any case, it is always better to determine the memory area for the stack segment yourself, so as not to accidentally fall into overlapping areas with the stack. * ExtBIOS_vars, if exists (1 - 4 kb) To determine the presence of this block, you need to call int $12 or read the same value at word [$00413]. If the value is less than 640, then this block is present and occupies the missing space (640 - word [$00413]) So if you open the A20, then the memory map can be enlarged for real mode on this data area Code: $100000 - $10FFEF ; HMA (~ 64 kb or 65520 bytes) SEG = $FFFF & OFF = [$0010 .. $FFFF] Naturally, for 32-bit addressing, all these blocks do not disappear anywhere, but simply the addresses of these blocks increase by 3 hexadecimal digits: Code: $00000000 - $000003FF ; Real IDT $00000400 - $000005FF ; BIOS_vars $00000600 - $00007BFF ; stack segment (29,5 kb) $00007C00 - $0009FBFF ; empty (608 kb) $0009FC00 - $0009FFFF ; ExtBIOS_vars, if exists (1 - 4 kb) * $000A0000 - $000AFFFF ; Video segment $000B0000 - $000B7FFF ; Mono text segment $000B8000 - $000BFFFF ; Color text segment $000C0000 - $000CFFFF ; Video BIOS $000D0000 - $000EFFFF ; Other ROM or Extended memory $000F0000 - $000FFFFF ; Main BIOS $00100000 - $0010FFEF ; HMA !00100000 - $FFFFFFFF ; Expanded memory (4Gb - 1Mb) But the end of this memory, although designated as $FFFFFFFF, but it is not. It is defined in SMAP. And in fact, when using PAE, addressing even in 32-bit mode can be $FFFFFFFFF. But it is also highly fragmented within the first 4 GB. And this information is also received via SMAP (ax = $E820/int $15). I think you can find documentation for this function. |
|||
![]() |
|
sinsi 22 Aug 2022, 06:13
Code: mov ah,$02 Read mov al,$01 1 sector mov ch,$00 Start track 0 mov cl,$01 Start sector 1 << sectors start with 1 which is the boot sector mov dh,$00 Start head 0 mov dl,$01 Drive 1 << drives start with 0 |
|||
![]() |
|
retro 22 Aug 2022, 09:22
oh, thanks for the explanation!
|
|||
![]() |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.