Page 2 of 5

Re:My print string function

Posted: Sun Mar 21, 2004 3:54 am
by ASHLEY4
So we need to see the getcursor code (I miss read the getcursorxy for getcursor and as, he push and pop ebx in that i thort it did not change any thing ::).

ASHLEY4.

Re:My print string function

Posted: Sun Mar 21, 2004 10:45 am
by bubach
ok.. it?s becasue the kernel will be in 100% asm..

i find it too easy to cut?n?paste code when things are going to slow..
i will have to be more patient and buy a real asm book instead of using those bad dos tutorials from around 1990..

here?s the whole text.asm

/ Christoffer

[attachment deleted by admin]

Re:My print string function

Posted: Sun Mar 21, 2004 1:26 pm
by Candy
bubach wrote: anyway, do you think that the things u pointed out will solve it? i will look it throw and be back tomorrow.. :-)
Complex answer: yes and no. Yes they will make your code work and give you a good feeling. No, you didn't fix the actual bug but a separate bug that would only scroll your screen every char you printed, and move the cursor to the last line (which perfectly explains why you got a vertical line of info, you'd have fixed that bug by now).

However, your real bug here lies in calling scroll_up instead of _scroll_up. The first one is the plain function without the preserve-my-variable wrapper, while the second is with the wrapper. It therefore wrecks your esi (and edi, and ecx, and eax) which pointed to your source but now to the eternal yachtfields (literal translation of dutch expression) that lie at 0xb8000 + 4000d = 0xB8FA0. You then try to print this, which does not really give decent output, but then you scroll one line further. And, the story continues :).

I expect the vertical line to be all the same char.

Solution, fix your jb's and call _scroll_up instead of scroll_up (or better yet, switch the two names around).

Greetz, Candy

Re:My print string function

Posted: Mon Mar 22, 2004 2:04 am
by bubach
so u r saying that this bug should give me a loop that scrolls up one line all the time? this was the result one time, but not as it is now..
thanks for all of your replies candy. it?s time to buy a good asm book and (re)write it myself.. ;)

/ Christoffer

Re:My print string function

Posted: Mon Mar 22, 2004 2:19 am
by Candy
bubach wrote: so u r saying that this bug should give me a loop that scrolls up one line all the time? this was the result one time, but not as it is now..
thanks for all of your replies candy. it?s time to buy a good asm book and (re)write it myself.. ;)

/ Christoffer
That was the result of the cooperation between two bugs. One bug would put your pointer to any place (which is in scroll_up), and the other would scroll up every time you placed a char (which caused the first bug to also appear). These combined put a list of bullshit in the leftmost line.

If you fixed the first bug first, it would still scroll up but it would display your string vertically instead of horizontally.

If you fixed the second bug only, you'd be printing normally until the screen is full, then each scroll-call will wreck the source pointer and start printing gibberish. You probably have that now.

If you fix both, it works.


The first bug was probably caused by misreading or forgetting the _ when typing the call. Also, it could be because the names are confusing.

The second bug was probably because you converted it from AT&T syntax code and did not swap the two halves at the cmp, thinking it doesn't matter. For jb and ja they do :). The other method to fix it is also correct, swap the two around. That does generate a non-normal opcode though, immediate as first encodes as a different op (iirc 22 instead of 20, but don't shoot me on that).

Re:My print string function

Posted: Mon Mar 22, 2004 5:50 am
by bubach
ok, i have recently looked up the diffrences between popa and popad etc.
on some places in the code i commented the d away becasue i did?nt know what it meant. ;)
Thanks for your help, i am sure to fix it now..

/ Christoffer

Re:My print string function

Posted: Mon Mar 22, 2004 6:19 am
by BI lazy
ooch candy, whats that dutch expression "eternal yachtfields" stands for?

Re:My print string function

Posted: Mon Mar 22, 2004 6:32 am
by Candy
BI lazy wrote: ooch candy, whats that dutch expression "eternal yachtfields" stands for?

"eeuwige jachtvelden" - heaven or something like that.

Re:My print string function

Posted: Mon Mar 22, 2004 6:53 am
by BI lazy
*feels not the slightest glitch of shame for being offtopic*

I'd have translated it with german "Ewige Jagdgr?nde" - in english "eternal Hunting Realms" *rofl* (some STFW'ing revealed it to be true)

Re:My print string function

Posted: Mon Mar 22, 2004 7:29 am
by Candy
BI lazy wrote: I'd have translated it with german "Ewige Jagdgr?nde" - in english "eternal Hunting Realms" *rofl* (some STFW'ing revealed it to be true)
yachtfields... how bad can your english get ::)

Thanks for the decent translation. Now back to topic :)

Re:My print string function

Posted: Wed Mar 24, 2004 8:07 am
by bubach
hmm.. i have a question; is this really a bug:

Code: Select all

      call   scroll_up
      call   _scroll_up.mv_curs
Becasue it scroll up _before_ it move the cursor.. It?s the only diffrens between that and this (that move the cursor before scrolling):

Code: Select all

call   _scroll_up
how big of a diffrens can it possible make in witch order u do it, scroll before moving the cursor or after?

/ Christoffer

Re:My print string function

Posted: Wed Mar 24, 2004 8:18 am
by Candy
bubach wrote: hmm.. i have a question; is this really a bug:

Code: Select all

      call   scroll_up
      call   _scroll_up.mv_curs
Becasue it scroll up _before_ it move the cursor.. It?s the only diffrens between that and this (that move the cursor before scrolling):

Code: Select all

call   _scroll_up
how big of a diffrens can it possible make in witch order u do it, scroll before moving the cursor or after?

/ Christoffer

Code: Select all

_scroll_up:   pusha                ;d
                call    scroll_up
                popa                 ;d

.mv_curs:   mov     bx,80*49
                call    setcursor
      ret
The point was not the order. Do you see those pusha's and popa's? They save your registers. PS: make them pushad & popad again. That's the way to save your esi.

Re:My print string function

Posted: Wed Mar 24, 2004 8:33 am
by bubach
they are pushad?s again, but the file on this forum is?nt updated very often.. ;)
I have also added pushad and popad in the scroll_up function so it should save the registers even if i 'call' them the "wrong" way..
Now i just have to find that reply where u pointed out witch 'mov' that was switched.. ;)

thanks!

/ Christoffer

Re:My print string function

Posted: Wed Mar 24, 2004 8:45 am
by bubach
I think i found it.. :-)
So i should replace:

Code: Select all

      mov   dx,bx
      mov   ax,bx
GC1:      sub   dx,80
      cmp   dx,ax
      jna   GC1

                add     dx,80

                push    edx

                sub     bx,dx           ;bx = y*80

                mov     ax,bx
                mov     bl,80
                div     bl

                mov     dl,al
                pop     ebx
                mov     dh,bl

                pop     ebx
                pop     eax
                ret
with:

Code: Select all

    xor dx, dx

GC1:
    sub bx, 80
    inc dl
    cmp bx, 80
    ja GC1

    mov dh, bl

                movzx   bx,dl
      mov   ax,bx
      shl   ax,4
      shl   bx,6
      add   bx,ax
                movzx   ax,dh
      add   bx,ax
right?

btw: whats SIB?

/ Christoffer

Re:My print string function

Posted: Wed Mar 24, 2004 11:45 am
by Candy
Nearly.

Code: Select all

      mov   dx,bx
      mov   ax,bx
GC1:      sub   dx,80
      cmp   dx,ax
      jna   GC1

                add     dx,80

                push    edx

                sub     bx,dx           ;bx = y*80

                mov     ax,bx
                mov     bl,80
                div     bl

                mov     dl,al
                pop     ebx
                mov     dh,bl

                pop     ebx
                pop     eax
                ret
with:

Code: Select all

    xor dx, dx

GC1:
    sub bx, 80
    inc dl
    cmp bx, 80
    ja GC1

    mov dh, bl
    pop ebx
    ret
This is not necessary, the code is equivalent. It's just a lot shorter (and slightly faster).

Both are equivalent to:

Code: Select all

  return_value.dh = offset % 80;
  return_value.dl = offset / 80;
  return return_value;
hmmz... am I so stupid or is that just me?

The next is also equivalent, and even faster from 2 lines and up on athlons and faster :). Don't you just love optimizing really small and only rarely called functions?

Code: Select all

    mov ax, bx
    div byte 80
    mov dx, ax
    ret
[quote]
 btw: whats SIB?
[/quote]
Scale, Index, Base. The way to address on 386+'s

Example without-SIB:
mov eax, some_number
mov ebx, 20h
shl eax, 2
add eax, ebx
add eax, 012345678h

Example with SIB:
mov eax, some_number
mov ebx, 020h
lea eax, [ebx+eax*4+012345678h]

See a difference?