flat assembler
Message board for the users of flat assembler.

Index > Main > [solved] STOSB does not work in some uses

Author
Thread Post new topic Reply to topic
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 06 Jun 2015, 04:31
I've come across an anomaly involving the STOSB instruction, and I am certain that I have had similar trouble with the other like string instructions. This is most certainly not the first time this has happened to me. Take the following code for example:

Code:
; This is the environment in which the code is running...
; String instructions should increment DI
cld

; ES == DS
push ds
pop es

; The following is actual code that I am working on...
; This does not work
and ax, 0x0F00
shr ax, 8
xlatb
stosb

; ...while this does
and ax, 0x0F00
shr ax, 8
xlatb
mov byte [di], al
inc di
    


If you were to probe the memory directly after the STOSB executes, where it had supposedly written the byte, you would find that it is simply not there in memory. It writes nothing.

What...? Am I missing something painfully obvious here?
Post 06 Jun 2015, 04:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20516
Location: In your JS exploiting you and your system
revolution 06 Jun 2015, 04:39
Check the DF flag, perhaps it is set?

If not then I suspect your segment registers have been changed. The only difference between 'stosb' and 'mov [di],al | inc/dec di' is the segment register used (and the flags I suppose also).

Otherwise show all of your code.
Post 06 Jun 2015, 04:39
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 06 Jun 2015, 05:02
It was something painfully obvious afterall. I neglected to preserve ES prior to a BIOS call that I would not have expected to destroy it.

BIOS, kids. Not even once. It'll ruin your life.
Post 06 Jun 2015, 05:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20516
Location: In your JS exploiting you and your system
revolution 06 Jun 2015, 05:06
Segment registers: Still destroying people's sanity 35 years later.
Post 06 Jun 2015, 05:06
View user's profile Send private message Visit poster's website Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 06 Jun 2015, 20:58
Trinitek wrote:
It was something painfully obvious afterall. I neglected to preserve ES prior to a BIOS call that I would not have expected to destroy it.
BIOS, kids. Not even once. It'll ruin your life.
And which BIOS function was that?

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 06 Jun 2015, 20:58
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 07 Jun 2015, 00:54
ax = 0xE820, int 0x15; running in VirtualBox. It had changed ES to 0xF000.
Post 07 Jun 2015, 00:54
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 07 Jun 2015, 13:36
Trinitek wrote:
ax = 0xE820, int 0x15; running in VirtualBox. It had changed ES to 0xF000.
No it didn't. You'll have to check your code.
I modified SudoBIOS to print the es value on return. I tried it in the latest VirtualBox v4.3.28 (Windows 7)
and the es was the same as it was going in (you need to set es:di to point to the return buffer).
Of course, the int 0x15 call was made in 32 bit PM. There really is no need to program in real mode any more
if all that you need is transparent BIOS access.
Also, Qemu is much faster for test and development, since you don't have to convert the image file first.


Description: VirtualBox MikeOS32_4.png
Filesize: 39.15 KB
Viewed: 8467 Time(s)

VirtualBox MikeOS32_4.png



_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 07 Jun 2015, 13:36
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 07 Jun 2015, 15:22
Nope. You're right. It was ah=0x08, int 0x13. I had to clear ES before the call anyway, so even if it didn't change it to 0xF000, it still wouldn't be right... I'm not having a very good week, as you can see.

Quote:
Also, Qemu is much faster for test and development, since you don't have to convert the image file first.

What do you mean "convert"? I'm building the floppy image using FASM and starting the VM from a little run.bat file, and that's fast enough for me.
Post 07 Jun 2015, 15:22
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 07 Jun 2015, 15:41
Trinitek wrote:
Nope. You're right. It was ah=0x08, int 0x13. I had to clear ES before the call anyway, so even if it didn't
change it to 0xF000, it still wouldn't be right... I'm not having a very good week, as you can see.
Function 8 returns the address (in ROM segment 0xF000) of the floppy disk drive parameter table in es:di
Trinitek wrote:
Quote:
Also, Qemu is much faster for test and development, since you don't have to convert the image file first.
What do you mean "convert"? I'm building the floppy image using FASM and starting the VM from a little run.bat
file, and that's fast enough for me.
You are not running it as a hard drive image. The floppy disk is long gone and forgotten. It's best to develop on
a USB flash drive image which will boot and run as either emulation on real PC's. The SudoBIOS demo, for example
is a 1.44MB fat12 floppy disk image, but will also boot and run as hard drive emulation. On some PC's you have
no choice.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 07 Jun 2015, 15:41
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 07 Jun 2015, 16:28
I will eventually use it as the boot image for an CD ISO image. Is there any benefit from not emulating a floppy disk in this case?
Post 07 Jun 2015, 16:28
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 07 Jun 2015, 16:33
Trinitek wrote:
I will eventually use it as the boot image for an CD ISO image. Is there any benefit from not emulating a floppy disk in this case?
Long gone and forgotten.
(And hard to carry in your pocket).
Boot media today is USB.

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 07 Jun 2015, 16:33
View user's profile Send private message Visit poster's website Reply with quote
Trinitek



Joined: 06 Nov 2011
Posts: 257
Trinitek 07 Jun 2015, 16:41
Thanks for the pointers, Mike. I really apppreciate it.
Post 07 Jun 2015, 16:41
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.