Why LDS SI returns ERROR in NASM ??

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Why LDS SI returns ERROR in NASM ??

Post by mrkaktus »

Why I can't write ?:

mov ax, 2
mov bx, 2
lds si, powitanie
call WRITE

.
.
.

powitanie db 'Inicjuje system...',0

When I'm compiling it by NASM it returns:
"error, invalid combination of opcode and operands"

Using " lds si, [powitanie] " allows me to compile it by NASM
but I know that it doesn't return the proper adress in DS:SI.

So , what to do? Please help me :S.
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Why LDS SI returns ERROR in NASM ??

Post by dave »

Please post more of you code

firstly, it should be

lds si, [powitanie]

as the cpu expects to take the address of some data, your string in this case, where currently you are giving it an address.

your other problem with "lds si, [powitanie]" is more then likely related to the fact your origin not being set properly. This would cause your data to be an offset from the beginning of your file not from the data segment you are curently using. However, since you only have a very small snippet of code it code be any number of errors.

Dave
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Why LDS SI returns ERROR in NASM ??

Post by mrkaktus »

Whole code of second stage bootloader.

Code: Select all

;
;                        "Alt Ctrl Delet"  
;                           ACD Loader
;                  (Bootloader Stopnia Drugiego)
;                              v1.0
;
;                            Mrkaktus 
;                      12 pazdziernika 2005
;     
;              
; Bootloader drugiego stopnia. Do jego zadan nalezy:
;
; [PROCEDURY 16bit]
; - Sprawdzenie typu procesora
;   (minimum 386)
;
; [PROCEDURY 32bit]
; - Zapisanie dostepnosci rozszerzen procesora
;   (Koprocesor, MMX, 3DNow!, SSE, SEE2, SSE3 itd.)
; - Sprawdzenie trybu pracy procesora
;   (wymagany tryb rzeczywisty)
; - Obliczenie rozmiaru pamieci operacyjnej RAM
;   (minimum 1mb RAM)
; - Wlaczenie linii A20
; - Zaladowanie Kernela do pamieci RAM
; - Utworzenie tablicy GDT
; - Utworzenie tablicy IDT
; - Utworzenie PD i PT systemu
; - Utworzenie GTB i TB
; - Oznaczenie zarezerwowanych stron w GTB/TB
; - Oznaczenie blokow specjalnych w PT
; - Uruchomienie PM
; - Wyczyszczenie potoku skokiem do kodu kernelu
;

;------------------+
; PROCEDURY 16 BIT |
;------------------+

 ; Inicjacja segmentow i reset stosu

     cli                                             ; Wylaczamy obsluge przerwan na 
                                                     ; czas resetowania stosu.
     mov ax, 0x1800                                  ; Bootloader laduje nas pod adres
     mov ds, ax                                      ; 96KB wiec ustawiamy odpowiednio
     mov es, ax                                      ; nasze rejestry.
     mov ax, 0x0800                                  ; \Resetujemy stos systemu.
     mov ss, ax                                      ; /
     mov sp, 0xFFFF                                  ; (Rozmiar stosu 64KB)
     sti                                             ; Przywracamy obsluge przerwan.

 ; Wyczyszczenie ekranu pod wyswietlenie komunikatow

     mov al, ' '                                     ; Czy?? znakiem spacji
     mov ah, 0x1B                                    ; Kolor tla niebieski a znaku bialy.
     mov dx, 0xB800                                  ;\Za?aduj segment ekranu
     mov es, dx                                      ;/
     xor di, di                                      ; Brak przesuniecia (DI=0)
     mov cx, 2000                                    ; Ustal ilo?? powtu?e? czyszczenia (80x25=2000)
     cld                                             ;\Powta?aj kopiowanie danych.
     rep stosw                                       ;/


     mov ax, 1                                       ; W pozycji X=1 Y=1
     mov bx, 2                                       ; wyswietla komunikat
     mov cl, 1fh                                     ; 
     lds si, powitanie                               ; powitania
     call WRITE                                      ;



     HALT_CPU:                   ; Je?eli wyst?pi? powa?ny b??d skacze tutaj i
     jmp HALT_CPU                ; zatrzymuje wywo?anie systemu.

;-------------------------------------------------------------------------------------
; Podstawowa procedura wyswietlajaca napis:                          v1.1 - 13.10.2005
; AX, BX - pozycja X,Y
;     cl - atrybuty tla i textu
; DS:SI  - wskaz na ciag znakow
WRITE:
     push cx
     mov cx, bx                                      ; Kopiuje Y do CX
     shl bx, 7                                       ; Mnozy Y * 128 
     shl cx, 5                                       ; Mnozy Y * 32
     shl ax, 1                                       ; Mnozy X * 2
     add ax, bx                                      ;\Dodaje (Y * 160) do (X*2)
     add ax, cx                                      ;/(przesuniecie na ekranie)
     mov dx, 0xb800                                  ;\  Przygotowuje w ES:DI
     mov es, dx                                      ; |-adres poczatkowy do
     mov di, ax                                      ;/  zapisu na ekran.

     pop cx
     WR_PETLA:
     mov dl, [ds:si]                                 ; Odczytaj znak i sprawdz
     cmp dl, 0                                       ; czy nie koniec ciagu
     jz  WR_KONIEC                                   ; Jak tak to koncz
     movsb                                           ; Kopiuje z DS:SI do ES:DI
     mov byte [es:di], cl
     inc di                                          ; Omin parametry na ekranie
     jmp WR_PETLA                                    ; Kopiuj kolejny znak

     WR_KONIEC:                                      ; Konczymy procedure
     ret


 powitanie db 'Inicjuje system...',0
so I think everything is ok. And about giving it in [powitanie] im not sure. Aren't we getting the data from variable in such way?
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Why LDS SI returns ERROR in NASM ??

Post by dave »

Lets start off with some basics. When you do say:

mov ax, myvariable

you are putting the offset ( in 16 bit mode ) into ax if on the other hand you do say:

mov ax, [myvariable]

you are putting the first byte or word at the address where myvariable is stored into ax. So if the address of myvariable is say 0x0200 ( just as an example ) and the data in this variable is 'hello'

mov word ax, myvariable

would move 0x0200 in ax. On the hand

mov word ax, [myvariable]

would move the data ( first word ) at address 0x0200 to ax so ax would have 'he' in it.

so your code should be

lds si, [powitanie]


Now the problem with doing this is your code does not set an orgin to tell nasm where it will be loaded in memory so when you load do the above assembly your variable "powitanie" is an offset relative to the start of the file not relative to the segment in which the code is load. While this does not appear to be the problem after looking at your code ( I am assuming
0x1800 is the segment where your code is also loaded ) since the offset should work you segment ( however this is not always the case ).


The problem with you not seeing the text on your screen is actually coming from your write text function. Your function is not writing your text to the screen because you never write [ds:si] to [es:di] you write cl but not your actual ascii data.

dave
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Why LDS SI returns ERROR in NASM ??

Post by mrkaktus »

I still cant understand this:

"The problem with you not seeing the text on your screen is actually coming from your write text function. Your function is not writing your text to the screen because you never write [ds:si] to [es:di] you write cl but not your actual ascii data. "

Copying from [ds:si] to [es:di] is maked by the function MOVSB which
increases SI and DI after that, then I am writing the parameters of font to the screen and INC DI to point to the next char.

If I have:

mov si, powitanie (loading only offset of the string yes?)

the WRITE function works fine.

If I use: lds si, [powitanie]

In the WRITE function when it is makeing CMP first time it gets NULL
in DL so it is finishing. This is the reason of clear screen. :? I cant understand why it reads 0 to dl from DS:SI :(
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Why LDS SI returns ERROR in NASM ??

Post by dave »

sorry missed the movsb just kinda blended together with all the other text

try disassembling your code with ndisasm if your using nasm as see where lds si, [powitanie] is actually pointing to within your code. It more then likely is a problem with the address your loading into ds:si. Althouh there really is no need to use lds si, [powitanie] as mov si, powitanie is perfectly fine for what your doing.

dave
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Why LDS SI returns ERROR in NASM ??

Post by mrkaktus »

I know what is wrong now. It is not my code but NASM compiler.
I'm compiling my code to BIN format because it will be directly run by
processor (because im writing OS of course :P). In BIN output format NASM is not providing Segmets, because it is written to compile files to BIN format that will be run in PM mode in some OS (I think Linux). In PM BIN output can't use RM segmets so there is error. I think i must to find better compiler (FASM?) or to think what to do with that in NASM :S.
dave
Member
Member
Posts: 42
Joined: Sat Jul 09, 2005 11:00 pm

Re: Why LDS SI returns ERROR in NASM ??

Post by dave »

Well, it is not NASM that is the problem. When you compile to a flat binary format this means there is no header information in the file for an os which uses an executable file format. If you move to FASM or any other your problem will still appear as it is a code problem not a problem with nasm.

dave
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Why LDS SI returns ERROR in NASM ??

Post by mrkaktus »

Yes you have right. It was my mistake. I think error was here :

Code: Select all

    mov ax, 0x0800                                  ; \Resetujemy stos systemu.
     mov ss, ax                                      ; /
     mov sp, 0xFFFF                                  ; (Rozmiar stosu 64KB)
When I move out that lines everything in my code works fine now. Because I add such lines to test CPU and it was hanging then :

Code: Select all

     ; Test czy nowszy czy starszy od 286 

     pushf                                           ;\_Zapisz rejestr FLAGS do BX
    ; pop bx                                          ;/
     xor ax, ax                                      ;\
     push ax                                         ; |-Zeruje FLAGS przy uzyciu AX
     popf                                            ;/
     pushf                                           ;\_Zapisuje nowy stan FLAGS do AX
     pop ax                                          ;/
    ; push bx                                         ;\_Przywruc orginalny stan 
     popf                                            ;/ rejestru FLAGS z BX
So something is wrong with setting the stack. But I don't know what because I have done this one time in bootloader and in this code I was doing this just second time to have it clear and 'frash' at the beginning.
Size and adress is thesame like in bootloader. Hmmm.
Post Reply