My print string function

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.
ASHLEY4

Re:My print string function

Post 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.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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]
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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).
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
BI lazy

Re:My print string function

Post by BI lazy »

ooch candy, whats that dutch expression "eternal yachtfields" stands for?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post by Candy »

BI lazy wrote: ooch candy, whats that dutch expression "eternal yachtfields" stands for?

"eeuwige jachtvelden" - heaven or something like that.
BI lazy

Re:My print string function

Post 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)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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 :)
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:My print string function

Post 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
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:My print string function

Post 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?

Post Reply